fix for some blocks

This commit is contained in:
Gamosoft 2025-12-10 09:10:58 +01:00
parent 62625b8897
commit 598901e629
1 changed files with 24 additions and 7 deletions

View File

@ -568,11 +568,28 @@ function noteApp() {
// Escape HTML first // Escape HTML first
let html = this.escapeHtml(text); let html = this.escapeHtml(text);
// Frontmatter (must be at start) // Store code blocks and inline code with placeholders to protect from other patterns
html = html.replace(/^(---\n[\s\S]*?\n---)/m, '<span class="md-frontmatter">$1</span>'); const codePlaceholders = [];
// Code blocks (before other patterns to avoid conflicts) // Frontmatter (must be at start) - protect it
html = html.replace(/(```[\s\S]*?```)/g, '<span class="md-codeblock">$1</span>'); html = html.replace(/^(---\n[\s\S]*?\n---)/m, (match) => {
codePlaceholders.push('<span class="md-frontmatter">' + match + '</span>');
return `\x00CODE${codePlaceholders.length - 1}\x00`;
});
// Code blocks - protect them
html = html.replace(/(```[\s\S]*?```)/g, (match) => {
codePlaceholders.push('<span class="md-codeblock">' + match + '</span>');
return `\x00CODE${codePlaceholders.length - 1}\x00`;
});
// Inline code - protect it
html = html.replace(/`([^`\n]+)`/g, (match) => {
codePlaceholders.push('<span class="md-code">' + match + '</span>');
return `\x00CODE${codePlaceholders.length - 1}\x00`;
});
// Now apply other patterns (they won't match inside protected code)
// Headings // Headings
html = html.replace(/^(#{1,6})\s(.*)$/gm, '<span class="md-heading">$1 $2</span>'); html = html.replace(/^(#{1,6})\s(.*)$/gm, '<span class="md-heading">$1 $2</span>');
@ -585,9 +602,6 @@ function noteApp() {
html = html.replace(/(?<![*\\])\*([^*\n]+)\*(?!\*)/g, '<span class="md-italic">*$1*</span>'); html = html.replace(/(?<![*\\])\*([^*\n]+)\*(?!\*)/g, '<span class="md-italic">*$1*</span>');
html = html.replace(/(?<![_\\])_([^_\n]+)_(?!_)/g, '<span class="md-italic">_$1_</span>'); html = html.replace(/(?<![_\\])_([^_\n]+)_(?!_)/g, '<span class="md-italic">_$1_</span>');
// Inline code
html = html.replace(/`([^`\n]+)`/g, '<span class="md-code">`$1`</span>');
// Wikilinks [[...]] // Wikilinks [[...]]
html = html.replace(/\[\[([^\]]+)\]\]/g, '<span class="md-wikilink">[[$1]]</span>'); html = html.replace(/\[\[([^\]]+)\]\]/g, '<span class="md-wikilink">[[$1]]</span>');
@ -604,6 +618,9 @@ function noteApp() {
// Horizontal rules // Horizontal rules
html = html.replace(/^([-*_]{3,})$/gm, '<span class="md-hr">$1</span>'); html = html.replace(/^([-*_]{3,})$/gm, '<span class="md-hr">$1</span>');
// Restore protected code blocks
html = html.replace(/\x00CODE(\d+)\x00/g, (match, index) => codePlaceholders[parseInt(index)]);
return html; return html;
}, },