Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed headings working inside of code blocks #51

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,10 +439,6 @@ addEventListener('DOMContentLoaded', () => {
.replace(/__(.+?)__/g, '<u>$1</u>')
.replace(/\*(.+?)\*/g, '<em>$1</em>')
.replace(/_(.+?)_/g, '<em>$1</em>')
//headings
.replace(/^# (.*)$/gm, '<h1 class="heading1">$1</h1>')
.replace(/^## (.*)$/gm, '<h2 class="heading2">$1</h2>')
.replace(/^### (.*)$/gm, '<h3 class="heading3">$1</h3>')
// Replace >>> and > with block-quotes. &#62; is HTML code for >
.replace(/^(?: *&#62;&#62;&#62; ([\s\S]*))|(?:^ *&#62;(?!&#62;&#62;) +.+\n)+(?:^ *&#62;(?!&#62;&#62;) .+\n?)+|^(?: *&#62;(?!&#62;&#62;) ([^\n]*))(\n?)/mg, (all, match1, match2, newLine) => {
return `<div class="blockquote"><div class="blockquoteDivider"></div><blockquote>${match1 || match2 || newLine ? match1 || match2 : all.replace(/^ *&#62; /gm, '')}</blockquote></div>`;
Expand Down Expand Up @@ -470,6 +466,10 @@ addEventListener('DOMContentLoaded', () => {
// Inline code
txt = txt.replace(/`([^`]+?)`|``([^`]+?)``/g, (m, x, y, z) => x ? `<code class="inline">${x}</code>` : y ? `<code class="inline">${y}</code>` : z ? `<code class="inline">${z}</code>` : m)
}

txt = txt.replace(/^# (.*)$/gm, '<h1 class="heading1">$1</h1>')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Consider moving heading replacements back to their original position.

The heading replacements were moved to a different part of the function. This could potentially affect the order of replacements and lead to unexpected results. Consider moving them back to their original position to maintain the intended order of operations.

Suggested change
txt = txt.replace(/^# (.*)$/gm, '<h1 class="heading1">$1</h1>')
txt = txt.replace(/^# (.*)$/gm, '<h1 class="heading1">$1</h1>')
.replace(/^## (.*)$/gm, '<h2 class="heading2">$1</h2>')
.replace(/^### (.*)$/gm, '<h3 class="heading3">$1</h3>')
txt = txt.replace(/`([^`]+?)`|``([^`]+?)``/g, (m, x, y, z) => x ? `<code class="inline">${x}</code>` : y ? `<code class="inline">${y}</code>` : z ? `<code class="inline">${z}</code>` : m)

.replace(/^## (.*)$/gm, '<h2 class="heading2">$1</h2>')
.replace(/^### (.*)$/gm, '<h3 class="heading3">$1</h3>')
return txt;
}

Expand Down