Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

chore(ui): remove ignored Marked options (#7644)

Chanhyo Jungac64cf4a6a1b
diff --git a/src/local_deep_research/web/static/js/services/ui.js b/src/local_deep_research/web/static/js/services/ui.js
index b22c33a020..acd7a76378 100644
--- a/src/local_deep_research/web/static/js/services/ui.js
+++ b/src/local_deep_research/web/static/js/services/ui.js
@@ -303,8 +303,8 @@ function showMessage(message, type = 'success', duration = UI_CONFIG.NOTIFICATIO
// Explicit DOMPurify allowlist for renderer-generated Markdown output. Raw
// author-supplied HTML is escaped at Marked's renderer.html hook below; this
-// second boundary constrains HTML produced by Markdown/GFM, syntax highlighting,
-// and KaTeX. Executable/embedded-content tags remain excluded, event-handler
+// second boundary constrains HTML produced by Markdown/GFM and KaTeX.
+// Executable/embedded-content tags remain excluded, event-handler
// attributes are excluded, and URL attributes keep DOMPurify's built-in scheme
// filter so javascript:/data:/vbscript: hrefs are dropped.
const MARKDOWN_ALLOWED_TAGS = [
@@ -339,7 +339,7 @@ const MARKDOWN_ALLOWED_TAGS = [
const MARKDOWN_ALLOWED_ATTR = [
'href', 'title', 'target', 'rel', // links (scheme-filtered)
'src', 'alt', // images (src is policy-checked below)
- 'class', 'id', 'style', 'role', // layout, Prism tokens, KaTeX styling
+ 'class', 'id', 'style', 'role', // layout, code languages, KaTeX styling
'align', 'colspan', 'rowspan', // tables
'type', 'checked', 'disabled', // GFM task-list inputs
'start', // ordered lists
@@ -710,13 +710,13 @@ const SAFE_KATEX_STYLE_VALIDATORS = new Map([
['width', isSafeKatexLength],
]);
-// `class` is needed for KaTeX and code highlighting. Preserve only classes
-// generated by the renderers this pipeline supports, so a future renderer or
-// extension cannot accidentally invoke unrelated globally-loaded utilities.
+// `class` is needed for KaTeX, GFM tasks and fenced-code language labels.
+// Historical highlighting classes remain for compatibility, not Marked 18 output.
+// Keep this set narrow so extensions cannot invoke unrelated global utilities.
const SAFE_MARKDOWN_CLASS_NAMES = new Set([
// GFM task lists.
'contains-task-list', 'task-list-item', 'task-list-item-checkbox',
- // Prism token classes. Language identifiers use the safe prefix below.
+ // Retained Prism token classes. Language identifiers use the safe prefix below.
'token', 'atrule', 'attr-name', 'attr-value', 'bold', 'boolean', 'builtin',
'cdata', 'char', 'class-name', 'comment', 'constant', 'decorator', 'deleted',
'doctype', 'entity', 'function', 'function-variable', 'hashbang', 'important',
@@ -762,7 +762,7 @@ const SAFE_MARKDOWN_CLASS_NAMES = new Set([
function isSafeMarkdownClassName(className) {
return SAFE_MARKDOWN_CLASS_NAMES.has(className)
// Marked places the requested lexer name on fenced code blocks;
- // highlight.js prefixes every generated token class with `hljs-`.
+ // Retain the highlight.js class prefixes for compatibility.
|| /^language-[\w-]+$/i.test(className)
|| /^hljs(?:-[\w-]+)?$/i.test(className);
}
@@ -851,7 +851,7 @@ function hardenSanitizedMarkdown(html) {
}
}
// Class values are another CSS execution surface. Filter individual
- // tokens so a valid KaTeX/Prism class can survive without carrying a
+ // tokens so an allowlisted class can survive without carrying a
// Bootstrap utility class alongside it.
for (const el of root.querySelectorAll('[class]')) {
const safeClasses = [...el.classList].filter(isSafeMarkdownClassName);
@@ -933,9 +933,9 @@ function renderMarkdown(markdown) {
};
// Raw HTML has no trustworthy provenance: if it reaches the
// final sanitizer as active markup, it can impersonate the
- // KaTeX/Prism classes and inline metrics that generated output
+ // KaTeX classes and inline metrics that generated output
// legitimately needs. Escaping at Marked's raw-HTML hook keeps
- // ordinary Markdown, GFM, highlighted code, and KaTeX rendering
+ // ordinary Markdown, GFM, fenced code, and KaTeX rendering
// intact while making author-supplied tags visible as text.
// Renderer extensions such as marked-katex-extension bypass
// this hook, so their generated markup still reaches the tight
@@ -950,19 +950,11 @@ function renderMarkdown(markdown) {
breaks: true,
gfm: true,
headerIds: true,
- smartLists: true,
// smartypants:false — converting `--` to en/em-dashes
// mangles code blocks that contain CLI flags (e.g.
// `--verbose`) or Python `**kwargs`. Match app.js so notes
// rendering preserves verbatim code for copy-paste.
smartypants: false,
- highlight(code, language) {
- // Use Prism for syntax highlighting if available
- if (typeof Prism !== 'undefined' && Prism.languages[language]) {
- return Prism.highlight(code, Prism.languages[language], language);
- }
- return code;
- }
});
// Parse markdown and return HTML
diff --git a/tests/js/services/ui.test.js b/tests/js/services/ui.test.js
index 2de8f22624..eb9c8c20b6 100644
--- a/tests/js/services/ui.test.js
+++ b/tests/js/services/ui.test.js
@@ -368,7 +368,7 @@ describe('renderMarkdown', () => {
});
});
-describe('renderMarkdown with KaTeX math', () => {
+describe('renderMarkdown with real Marked, KaTeX and DOMPurify', () => {
// Configure a real marked + KaTeX + DOMPurify pipeline for this block only.
// The setup mirrors app.js so renderMarkdown takes the marked-rendering
// branch instead of falling through to the plaintext-escape fallback.
@@ -406,6 +406,70 @@ describe('renderMarkdown with KaTeX math', () => {
globalThis.DOMPurify = DOMPurify;
});
+ it.each(['smartLists', 'highlight'])('omits obsolete %s from actual Marked options', (option) => {
+ const setOptions = vi.spyOn(globalThis.marked, 'setOptions');
+ try {
+ const result = ui.renderMarkdown('# Options');
+
+ expect(result).toBe('<div class="ldr-markdown-content"><h1>Options</h1>\n</div>');
+ expect(setOptions).toHaveBeenCalledTimes(1);
+ const [options] = setOptions.mock.calls[0];
+ expect(options).toMatchObject({
+ breaks: true,
+ gfm: true,
+ headerIds: true,
+ smartypants: false,
+ });
+ expect(options).not.toHaveProperty(option);
+ } finally {
+ setOptions.mockRestore();
+ }
+ });
+
+ it('preserves fenced JavaScript verbatim without Prism token spans', () => {
+ const code = 'const args = ["--verbose", \'--output=<file>\'];';
+ const template = document.createElement('template');
+ // eslint-disable-next-line no-unsanitized/property -- test-only: inspect actual renderer output.
+ template.innerHTML = ui.renderMarkdown('```javascript\n' + code + '\n```');
+
+ const renderedCode = template.content.querySelector('.ldr-markdown-content > pre > code.language-javascript');
+ expect(renderedCode).not.toBeNull();
+ expect(renderedCode.textContent).toBe(code + '\n');
+ expect(renderedCode.children).toHaveLength(0);
+ expect(template.content.querySelector('span.token')).toBeNull();
+ });
+
+ it('preserves headings, links, inline code, line breaks and GFM', () => {
+ const template = document.createElement('template');
+ // eslint-disable-next-line no-unsanitized/property -- test-only: inspect actual renderer output.
+ template.innerHTML = ui.renderMarkdown('# Guide\n\n[Docs](https://example.test/docs "Reference")\nUse `--verbose` and ~~old~~.\n\n- item');
+
+ const root = template.content.querySelector('.ldr-markdown-content');
+ expect(root.querySelector('h1').textContent).toBe('Guide');
+ const link = root.querySelector('a');
+ expect(link.textContent).toBe('Docs');
+ expect(link.getAttribute('href')).toBe('https://example.test/docs');
+ expect(link.getAttribute('title')).toBe('Reference');
+ expect(link.getAttribute('target')).toBe('_blank');
+ expect(link.getAttribute('rel')).toBe('noopener noreferrer');
+ expect(root.querySelector('p > br')).not.toBeNull();
+ expect(root.querySelector('p > code').textContent).toBe('--verbose');
+ expect(root.querySelector('del').textContent).toBe('old');
+ expect(root.querySelector('ul > li').textContent).toBe('item');
+ });
+
+ it('renders raw author HTML as visible text alongside Markdown', () => {
+ const rawHtml = '<span class="token keyword">example</span>';
+ const template = document.createElement('template');
+ // eslint-disable-next-line no-unsanitized/property -- test-only: inspect actual renderer output.
+ template.innerHTML = ui.renderMarkdown('# Example\n\n' + rawHtml);
+
+ const root = template.content.querySelector('.ldr-markdown-content');
+ expect(root.querySelector('h1').textContent).toBe('Example');
+ expect(root.querySelector('p').textContent).toBe(rawHtml);
+ expect(root.querySelector('span')).toBeNull();
+ });
+
// We still assert on the KaTeX HTML rendering branch — that is the
// visible math layer and the proof that the extension actually ran, and
// it is what a browser shows.