From a01f20473fbd5934617999ca8f9e616c75e99127 Mon Sep 17 00:00:00 2001 From: LakshmanKishore Date: Fri, 6 Mar 2026 09:39:26 +0530 Subject: [PATCH] feat: implement CSS-variable based syntax highlighting for dark mode --- index.html | 3 +- script.js | 42 ++++++++++++++-------------- styles.css | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 99 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index f2d98ee..11ccb04 100644 --- a/index.html +++ b/index.html @@ -32,7 +32,6 @@ - @@ -268,4 +267,4 @@
Menu
- \ No newline at end of file + diff --git a/script.js b/script.js index 1aa5503..f5a176f 100644 --- a/script.js +++ b/script.js @@ -121,11 +121,6 @@ document.addEventListener("DOMContentLoaded", function () { marked.setOptions({ ...markedOptions, renderer: renderer, - highlight: function (code, language) { - if (language === 'mermaid') return code; - const validLanguage = hljs.getLanguage(language) ? language : "plaintext"; - return hljs.highlight(code, { language: validLanguage }).value; - }, }); const sampleMarkdown = `# Welcome to Markdown Viewer @@ -145,10 +140,9 @@ document.addEventListener("DOMContentLoaded", function () { const sanitizedHtml = DOMPurify.sanitize(html); markdownPreview.innerHTML = sanitizedHtml; - // Apply syntax highlighting to code blocks - markdownPreview.querySelectorAll('pre code').forEach((block) => { - hljs.highlightElement(block); - }); + // Syntax highlighting is handled automatically + // during the parsing phase by the marked renderer. + // Themes are applied instantly via CSS variables. } \`\`\` @@ -302,16 +296,6 @@ This is a fully client-side application. Your content never leaves your browser }); markdownPreview.innerHTML = sanitizedHtml; - markdownPreview.querySelectorAll("pre code").forEach((block) => { - try { - if (!block.classList.contains('mermaid') && !block.classList.contains('hljs')) { - hljs.highlightElement(block); - } - } catch (e) { - console.warn("Syntax highlighting failed for a code block:", e); - } - }); - processEmojis(markdownPreview); // Reinitialize mermaid with current theme before rendering diagrams @@ -813,9 +797,6 @@ This is a fully client-side application. Your content never leaves your browser Markdown Export -