@memberjunction/ng-markdown 6.3.0-edge.0 → 6.3.0-edge.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.service.dom.test.js","sourceRoot":"","sources":["../../../src/lib/services/markdown.service.dom.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAsBrD,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,OAAwB,CAAC;IAC7B,IAAI,MAAgC,CAAC;IAErC,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;QAChC,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAE,OAAqC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;QACrB,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;YAC5D,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,UAAU,EAA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AE;YACtE,kFAAkF;YAClF,4DAA4D;YAC5D,MAAM,aAAa,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;YAC1D,MAAM,CAAC,QAAQ,CAAC,CAAC;YACjB,MAAM,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAC/C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;YACjE,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC7B,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YACnC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAAC;YACzD,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';\nimport type { Mermaid } from 'mermaid';\nimport katex from 'katex';\nimport { MarkdownService } from './markdown.service';\n\n/**\n * jsdom specs for the web shell around @memberjunction/markdown-core.\n *\n * These focus on the browser-only concerns that stay in the Angular service:\n * the `parse()` entry points and the DOM-based `unwrapMiscodedHtml()` fixup.\n * The framework-agnostic parsing itself is covered in @memberjunction/markdown-core.\n *\n * `unwrapMiscodedHtml` is private, so we reach it through a typed cast — the same\n * pattern the markdown-core engine spec uses to poke the internal marked instance.\n * This keeps the assertions deterministic (exact HTML in, exact behavior out)\n * rather than depending on which fixtures marked happens to miscode.\n */\ntype UnwrapAccessor = { unwrapMiscodedHtml(html: string): string };\n\n/** Same private-member reach-in, for the lazily-loaded mermaid engine (see `loadMermaid`). */\ntype MermaidLoaderAccessor = { loadMermaid(): Promise<Mermaid> };\n\n/** And for the lazily-loaded KaTeX engine (see `loadKatex`). */\ntype KatexLoaderAccessor = { loadKatex(): Promise<unknown> };\n\ndescribe('MarkdownService (DOM)', () => {\n let service: MarkdownService;\n let unwrap: (html: string) => string;\n\n beforeEach(() => {\n service = new MarkdownService();\n unwrap = (html: string) => (service as unknown as UnwrapAccessor).unwrapMiscodedHtml(html);\n });\n\n describe('parse', () => {\n it('returns empty string for empty input', () => {\n expect(service.parse('')).toBe('');\n });\n\n it('renders basic prose to a paragraph', () => {\n expect(service.parse('hello world')).toContain('<p>');\n });\n\n it('accepts per-call config overrides without throwing', () => {\n expect(() => service.parse('# Title', { enableHtml: true })).not.toThrow();\n });\n\n it('parseAsync resolves to the same output as parse', async () => {\n const md = '**bold**';\n expect(await service.parseAsync(md)).toBe(service.parse(md));\n });\n });\n\n describe('unwrapMiscodedHtml', () => {\n it('is a no-op when there are no <pre> blocks', () => {\n const html = '<p>just a paragraph</p>';\n expect(unwrap(html)).toBe(html);\n });\n\n it('returns empty input unchanged', () => {\n expect(unwrap('')).toBe('');\n });\n\n it('skips content containing <svg (DOMParser would mangle SVG namespaces)', () => {\n const html = '<pre><code>&lt;svg&gt;&lt;rect/&gt;&lt;/svg&gt;</code></pre>';\n // Left untouched precisely because it contains \"<svg\".\n expect(unwrap(html)).toBe(html);\n });\n\n it('preserves an intentional code block that carries a language class', () => {\n const html = '<pre><code class=\"language-html\">&lt;div&gt;&lt;span&gt;x&lt;/span&gt;&lt;/div&gt;</code></pre>';\n const out = unwrap(html);\n // Language-classed code is an intentional example → NOT unwrapped.\n expect(out).toContain('language-html');\n expect(out).toContain('<pre>');\n });\n\n it('unwraps structural HTML that marked miscoded into a <pre><code> block', () => {\n // textContent decodes to <div><span>x</span></div> — multi-tag structural HTML.\n const html = '<pre><code>&lt;div&gt;&lt;span&gt;x&lt;/span&gt;&lt;/div&gt;</code></pre>';\n const out = unwrap(html);\n expect(out).toContain('<div>');\n expect(out).toContain('<span>x</span>');\n // The escaped code-block form must be gone.\n expect(out).not.toContain('&lt;div&gt;');\n expect(out).not.toContain('<pre>');\n });\n\n it('does not unwrap a single self-closing tag (needs 2+ tags to qualify)', () => {\n const html = '<pre><code>&lt;br&gt;</code></pre>';\n // tagCount < 2 → looksLikeStructuralHtml returns false → left as-is.\n expect(unwrap(html)).toBe(html);\n });\n\n it('does not unwrap an empty code block', () => {\n const html = '<pre><code></code></pre>';\n expect(unwrap(html)).toBe(html);\n });\n\n it('does not unwrap plain non-HTML code content', () => {\n const html = '<pre><code>const x = 1; // not html</code></pre>';\n expect(unwrap(html)).toBe(html);\n });\n\n it('does not throw on malformed markup', () => {\n expect(() => unwrap('<pre><code>&lt;div&gt;&lt;span&gt;unclosed')).not.toThrow();\n });\n });\n\n describe('config accessors', () => {\n it('resetConfig restores enableHtml to the default (false)', () => {\n service.configureMarked({ enableHtml: true });\n expect(service.getConfig().enableHtml).toBe(true);\n service.resetConfig();\n expect(service.getConfig().enableHtml).toBe(false);\n });\n\n it('isLanguageSupported reflects Prism registration', () => {\n // typescript is imported by the service; a made-up language is not.\n expect(service.isLanguageSupported('typescript')).toBe(true);\n expect(service.isLanguageSupported('definitely-not-a-language')).toBe(false);\n });\n });\n\n describe('renderMermaid', () => {\n /** Stub the private lazy loader — the point of these specs is WHEN it is called, not what it returns. */\n const stubLoader = (impl: () => Promise<Mermaid>): void => {\n (service as unknown as MermaidLoaderAccessor).loadMermaid = impl;\n };\n\n const containerWith = (html: string): HTMLElement => {\n const container = document.createElement('div');\n container.innerHTML = html;\n return container;\n };\n\n it('never loads the diagram engine when the document has no diagram', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched for a diagram-free document');\n });\n\n const result = await service.renderMermaid(containerWith('<p>no diagrams here</p>'));\n\n expect(result).toBe(false);\n expect(loads).toBe(0);\n });\n\n it('shows a visible failure on every block when the lazy chunk cannot be loaded', async () => {\n stubLoader(() => Promise.reject(new Error('chunk fetch failed')));\n const container = containerWith(\n '<pre><code class=\"language-mermaid\">graph TD; A-->B;</code></pre>' +\n '<div class=\"mermaid\">graph TD; C-->D;</div>',\n );\n\n const result = await service.renderMermaid(container);\n\n expect(result).toBe(false);\n const failed = container.querySelectorAll('.mermaid-error');\n expect(failed.length).toBe(2);\n for (const element of Array.from(failed)) {\n expect(element.getAttribute('data-mermaid-error')).toBe('Diagram engine failed to load');\n }\n });\n\n it('does nothing at all when mermaid is disabled by config', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched when mermaid is disabled');\n });\n service.configureMarked({ enableMermaid: false });\n\n const result = await service.renderMermaid(\n containerWith('<pre><code class=\"language-mermaid\">graph TD; A-->B;</code></pre>'),\n );\n\n expect(result).toBe(false);\n expect(loads).toBe(0);\n });\n });\n\n describe('RenderMath', () => {\n /** Parse through the real pipeline (sanitizer included) and mount it, as the component does. */\n const mount = (markdown: string): HTMLElement => {\n const container = document.createElement('div');\n container.innerHTML = service.Parse(markdown);\n return container;\n };\n\n const stubLoader = (impl: () => Promise<unknown>): void => {\n (service as unknown as KatexLoaderAccessor).loadKatex = impl;\n };\n\n it('typesets inline and display math as MathML with the real engine', async () => {\n const container = mount('Energy $E = mc^2$ where\\n\\n$$\\n\\\\frac{a}{b}\\n$$');\n\n expect(await service.RenderMath(container)).toBe(true);\n\n const formulas = container.querySelectorAll('math');\n expect(formulas.length).toBe(2);\n expect(formulas[0].getAttribute('display')).toBeNull();\n expect(formulas[1].getAttribute('display')).toBe('block');\n expect(container.querySelector('mfrac')).not.toBeNull();\n expect(container.querySelector('annotation')?.textContent).toBe('E = mc^2');\n expect(container.querySelector('code.mj-math')).toBeNull();\n });\n\n it('spells styled letters with Unicode math characters, which Chrome renders (it ignores mathvariant)', async () => {\n const container = mount('$\\\\mathbf{E} \\\\in \\\\mathbb{R}^3, \\\\mathcal{L}, \\\\mathfrak{H}, \\\\mathbf{0}, \\\\boldsymbol{\\\\alpha}$');\n\n await service.RenderMath(container);\n\n const identifiers = Array.from(container.querySelectorAll('mi, mn')).map((n) => n.textContent);\n expect(identifiers).toEqual(expect.arrayContaining(['𝐄', 'ℝ', 'ℒ', 'ℌ', '𝟎']));\n expect(container.querySelector('mi[mathvariant=\"bold\"], mi[mathvariant=\"double-struck\"]')).toBeNull();\n // Greek has no Unicode form here: it keeps the attribute for the CSS bold fallback.\n expect(container.querySelector('mi[mathvariant=\"bold-italic\"]')?.textContent).toBe('α');\n // The TeX source in the annotation is untouched.\n expect(container.querySelector('annotation')?.textContent).toContain('\\\\mathbf{E}');\n });\n\n it('leaves TeX it cannot parse visible as source, and still typesets the rest', async () => {\n const container = mount('Broken $\\\\frac{a$ but fine $x^2$');\n\n expect(await service.RenderMath(container)).toBe(true);\n\n const broken = container.querySelector('code.mj-math.mj-math-error');\n expect(broken?.textContent).toBe('\\\\frac{a');\n expect(broken?.getAttribute('title')).toBeTruthy();\n expect(container.querySelectorAll('math').length).toBe(1);\n });\n\n it('leaves a formula that defines macros as source (expansion bombs)', async () => {\n const container = mount('$\\\\def\\\\a{x x x}\\\\a\\\\a$ and $y$');\n\n await service.RenderMath(container);\n\n const kept = container.querySelector('code.mj-math.mj-math-error');\n expect(kept?.textContent).toBe('\\\\def\\\\a{x x x}\\\\a\\\\a');\n expect(kept?.getAttribute('title')).toContain('macros');\n expect(container.querySelectorAll('math').length).toBe(1);\n });\n\n it('caps user sizes', async () => {\n const container = mount('$\\\\rule{100000em}{100000em}$');\n\n await service.RenderMath(container);\n\n const rule = container.querySelector('mspace');\n expect(parseFloat(rule?.getAttribute('width') ?? '0')).toBeLessThanOrEqual(20);\n expect(parseFloat(rule?.getAttribute('height') ?? '0')).toBeLessThanOrEqual(20);\n });\n\n it('skips placeholders a newer render replaced while KaTeX was loading', async () => {\n let release: (engine: unknown) => void = () => undefined;\n stubLoader(() => new Promise((resolve) => (release = resolve)));\n const container = mount('$x^2$');\n\n const pending = service.RenderMath(container);\n container.innerHTML = service.Parse('$y^2$'); // the next streamed chunk\n release(katex);\n\n expect(await pending).toBe(false);\n expect(container.querySelector('math')).toBeNull();\n expect(container.querySelector('code.mj-math')?.textContent).toBe('y^2');\n });\n\n it('keeps \\\\href inert (trust is off)', async () => {\n const container = mount('$\\\\href{javascript:alert(1)}{x}$');\n\n await service.RenderMath(container);\n\n // No link anywhere: the command shows as an unrendered \"\\href\". The URL survives only\n // as text inside <annotation>, which is the TeX source and never a link.\n expect(container.querySelector('a, [href]')).toBeNull();\n expect(container.querySelector('mtext')?.textContent).toBe('\\\\href');\n });\n\n it('never loads the engine when the document has no math', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched for a math-free document');\n });\n\n expect(await service.RenderMath(mount('It costs $5 and $10.'))).toBe(false);\n expect(loads).toBe(0);\n });\n\n it('leaves the source showing when the lazy chunk cannot be loaded', async () => {\n stubLoader(() => Promise.reject(new Error('chunk fetch failed')));\n const container = mount('$x^2$');\n\n expect(await service.RenderMath(container)).toBe(false);\n expect(container.querySelector('code.mj-math')?.textContent).toBe('x^2');\n });\n\n it('does nothing at all when math is disabled by config', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched when math is disabled');\n });\n service.ConfigureMarked({ enableMath: false });\n\n const container = mount('$x^2$');\n\n expect(await service.RenderMath(container)).toBe(false);\n expect(loads).toBe(0);\n expect(container.textContent?.trim()).toBe('$x^2$');\n });\n });\n\n describe('MathML markup', () => {\n const MATHML_NS = 'http://www.w3.org/1998/Math/MathML';\n const mount = (markdown: string): HTMLElement => {\n const container = document.createElement('div');\n container.innerHTML = service.Parse(markdown);\n return container;\n };\n\n it('keeps a JATS formula as real MathML elements, prefixes removed', () => {\n const c = mount('Loss <mml:math display=\"inline\"><mml:mn>7</mml:mn><mml:mo>×</mml:mo><mml:msup><mml:mn>10</mml:mn><mml:mn>13</mml:mn></mml:msup></mml:math> per pulse.');\n const msup = c.querySelector('msup');\n expect(msup?.namespaceURI).toBe(MATHML_NS);\n expect(msup?.textContent).toBe('1013');\n expect(c.textContent).toContain('per pulse.');\n });\n\n it('keeps a table\\'s column alignment and spacing (DOMPurify misspells one, lacks the other)', () => {\n const c = mount('<math display=\"block\"><mtable columnalign=\"right left\" columnspacing=\"0em 2em\"><mtr><mtd><mi>a</mi></mtd><mtd><mo>=</mo><mi>b</mi></mtd></mtr></mtable></math>');\n const table = c.querySelector('mtable');\n expect(table?.getAttribute('columnalign')).toBe('right left');\n expect(table?.getAttribute('columnspacing')).toBe('0em 2em');\n });\n\n it('shows the formula once when MathML carries its TeX in an annotation (MathJax, Pandoc, Word)', () => {\n const c = mount('<math><semantics><mrow><msup><mi>x</mi><mn>2</mn></msup></mrow><annotation encoding=\"application/x-tex\">x^2</annotation></semantics></math>');\n expect(c.querySelector('msup')).not.toBeNull();\n expect(c.textContent?.trim()).toBe('x2');\n });\n\n it('spells styled letters with Unicode math characters, as for typeset TeX', async () => {\n const c = mount('<math><mi mathvariant=\"bold\">E</mi><mo>∈</mo><msup><mi mathvariant=\"double-struck\">R</mi><mn>3</mn></msup></math>');\n await service.RenderMath(c);\n expect(Array.from(c.querySelectorAll('mi')).map((n) => n.textContent)).toEqual(['𝐄', 'ℝ']);\n });\n\n // Known DOMPurify bypass shapes through MathML, plus the plain attribute and handler routes.\n it.each([\n ['javascript: href on a MathML element', '<math href=\"javascript:alert(1)\"><mi xlink:href=\"javascript:alert(1)\">x</mi></math>'],\n ['maction with a script link', '<math><maction actiontype=\"statusline\" xlink:href=\"javascript:alert(1)\"><mi>x</mi></maction></math>'],\n ['HTML inside annotation-xml', '<math><annotation-xml encoding=\"text/html\"><img src=\"x\" onerror=\"alert(1)\"></annotation-xml></math>'],\n ['mglyph/style namespace confusion', '<math><mtext><table><mglyph><style><img src=\"x\" onerror=\"alert(1)\">'],\n ['form/math nesting confusion', '<form><math><mtext></form><form><mglyph><style></math><img src=\"x\" onerror=\"alert(1)\">'],\n ['handlers on MathML elements', '<math onclick=\"alert(1)\"><mi onmouseover=\"alert(1)\">x</mi></math>'],\n ])('strips %s', (_name, payload) => {\n const c = mount(payload);\n const attributes = Array.from(c.querySelectorAll('*')).flatMap((el) => Array.from(el.attributes));\n expect(attributes.filter((a) => a.name.startsWith('on'))).toEqual([]);\n expect(attributes.filter((a) => /javascript:/i.test(a.value))).toEqual([]);\n expect(c.querySelector('script')).toBeNull();\n });\n });\n\n describe('parse sanitizes unless scripts are explicitly enabled', () => {\n it('strips handlers and script from passthrough HTML', () => {\n const out = service.parse('<div><img src=\"x\" onerror=\"alert(1)\"><script>alert(2)</script></div>', { enableHtml: true });\n expect(out).not.toContain('onerror');\n expect(out).not.toContain('<script');\n expect(out).toContain('<img');\n });\n\n it('leaves script in place when enableJavaScript is true (the opt-out)', () => {\n const out = service.parse('<div>x</div><script>alert(1)</script>', { enableHtml: true, enableJavaScript: true });\n expect(out).toContain('<script>');\n });\n\n it('sanitizeHtml is exposed for consumers that bind parse() output themselves', () => {\n expect(service.sanitizeHtml('<a href=\"javascript:alert(1)\" onclick=\"x()\">x</a>')).toBe('<a>x</a>');\n });\n });\n\n describe('unwrapMiscodedHtml is inert and keeps leading style', () => {\n afterEach(() => vi.restoreAllMocks());\n const miscoded = '<pre><code>&lt;style&gt;.card{color:red}&lt;/style&gt;&lt;div class=\"card\"&gt;&lt;img src=\"x\" onerror=\"alert(1)\"&gt;&lt;p&gt;hi&lt;/p&gt;&lt;/div&gt;</code></pre>';\n\n it('never creates elements on the live document while unwrapping', () => {\n // Building the replacement on the live document would run image error handlers at\n // parse time, before parse() sanitizes the returned string.\n const createElement = vi.spyOn(document, 'createElement');\n unwrap(miscoded);\n expect(createElement).not.toHaveBeenCalled();\n });\n\n it('unwraps the structural HTML and keeps a leading <style>', () => {\n const out = unwrap(miscoded);\n expect(out).not.toContain('<pre>');\n expect(out).toContain('<style>.card{color:red}</style>');\n expect(out).toContain('<div class=\"card\">');\n });\n\n it('returns markup for parse() to sanitize rather than executing it', () => {\n expect(unwrap(miscoded)).toContain('onerror=\"alert(1)\"');\n });\n });\n});\n"]}
1
+ {"version":3,"file":"markdown.service.dom.test.js","sourceRoot":"","sources":["../../../src/lib/services/markdown.service.dom.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEzE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAsBrD,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAI,OAAwB,CAAC;IAC7B,IAAI,MAAgC,CAAC;IAErC,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;QAChC,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAAE,OAAqC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC7F,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;QACrB,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;YAC9C,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;YAC5D,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAA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BAAoB,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';\nimport type { Mermaid } from 'mermaid';\nimport katex from 'katex';\nimport { MarkdownService } from './markdown.service';\n\n/**\n * jsdom specs for the web shell around @memberjunction/markdown-core.\n *\n * These focus on the browser-only concerns that stay in the Angular service:\n * the `parse()` entry points and the DOM-based `unwrapMiscodedHtml()` fixup.\n * The framework-agnostic parsing itself is covered in @memberjunction/markdown-core.\n *\n * `unwrapMiscodedHtml` is private, so we reach it through a typed cast — the same\n * pattern the markdown-core engine spec uses to poke the internal marked instance.\n * This keeps the assertions deterministic (exact HTML in, exact behavior out)\n * rather than depending on which fixtures marked happens to miscode.\n */\ntype UnwrapAccessor = { unwrapMiscodedHtml(html: string): string };\n\n/** Same private-member reach-in, for the lazily-loaded mermaid engine (see `loadMermaid`). */\ntype MermaidLoaderAccessor = { loadMermaid(): Promise<Mermaid> };\n\n/** And for the lazily-loaded KaTeX engine (see `loadKatex`). */\ntype KatexLoaderAccessor = { loadKatex(): Promise<unknown> };\n\ndescribe('MarkdownService (DOM)', () => {\n let service: MarkdownService;\n let unwrap: (html: string) => string;\n\n beforeEach(() => {\n service = new MarkdownService();\n unwrap = (html: string) => (service as unknown as UnwrapAccessor).unwrapMiscodedHtml(html);\n });\n\n describe('parse', () => {\n it('returns empty string for empty input', () => {\n expect(service.parse('')).toBe('');\n });\n\n it('renders basic prose to a paragraph', () => {\n expect(service.parse('hello world')).toContain('<p>');\n });\n\n it('accepts per-call config overrides without throwing', () => {\n expect(() => service.parse('# Title', { enableHtml: true })).not.toThrow();\n });\n\n it('parseAsync resolves to the same output as parse', async () => {\n const md = '**bold**';\n expect(await service.parseAsync(md)).toBe(service.parse(md));\n });\n });\n\n describe('unwrapMiscodedHtml', () => {\n it('is a no-op when there are no <pre> blocks', () => {\n const html = '<p>just a paragraph</p>';\n expect(unwrap(html)).toBe(html);\n });\n\n it('returns empty input unchanged', () => {\n expect(unwrap('')).toBe('');\n });\n\n it('skips content containing <svg (DOMParser would mangle SVG namespaces)', () => {\n const html = '<pre><code>&lt;svg&gt;&lt;rect/&gt;&lt;/svg&gt;</code></pre>';\n // Left untouched precisely because it contains \"<svg\".\n expect(unwrap(html)).toBe(html);\n });\n\n it('preserves an intentional code block that carries a language class', () => {\n const html = '<pre><code class=\"language-html\">&lt;div&gt;&lt;span&gt;x&lt;/span&gt;&lt;/div&gt;</code></pre>';\n const out = unwrap(html);\n // Language-classed code is an intentional example → NOT unwrapped.\n expect(out).toContain('language-html');\n expect(out).toContain('<pre>');\n });\n\n it('unwraps structural HTML that marked miscoded into a <pre><code> block', () => {\n // textContent decodes to <div><span>x</span></div> — multi-tag structural HTML.\n const html = '<pre><code>&lt;div&gt;&lt;span&gt;x&lt;/span&gt;&lt;/div&gt;</code></pre>';\n const out = unwrap(html);\n expect(out).toContain('<div>');\n expect(out).toContain('<span>x</span>');\n // The escaped code-block form must be gone.\n expect(out).not.toContain('&lt;div&gt;');\n expect(out).not.toContain('<pre>');\n });\n\n it('does not unwrap a single self-closing tag (needs 2+ tags to qualify)', () => {\n const html = '<pre><code>&lt;br&gt;</code></pre>';\n // tagCount < 2 → looksLikeStructuralHtml returns false → left as-is.\n expect(unwrap(html)).toBe(html);\n });\n\n it('does not unwrap an empty code block', () => {\n const html = '<pre><code></code></pre>';\n expect(unwrap(html)).toBe(html);\n });\n\n it('does not unwrap plain non-HTML code content', () => {\n const html = '<pre><code>const x = 1; // not html</code></pre>';\n expect(unwrap(html)).toBe(html);\n });\n\n it('does not throw on malformed markup', () => {\n expect(() => unwrap('<pre><code>&lt;div&gt;&lt;span&gt;unclosed')).not.toThrow();\n });\n });\n\n describe('config accessors', () => {\n it('resetConfig restores enableHtml to the default (false)', () => {\n service.configureMarked({ enableHtml: true });\n expect(service.getConfig().enableHtml).toBe(true);\n service.resetConfig();\n expect(service.getConfig().enableHtml).toBe(false);\n });\n\n it('caches Marked configuration and skips redundant engine reconfiguration when config has not changed', () => {\n const engine = service['engine'];\n const spy = vi.spyOn(engine, 'configureMarked');\n\n // Call with default config when already configured\n service.configureMarked({});\n expect(spy).not.toHaveBeenCalled();\n\n // Call with new config option\n service.configureMarked({ enableHtml: true });\n expect(spy).toHaveBeenCalledTimes(1);\n\n // Call again with the exact same config option\n service.configureMarked({ enableHtml: true });\n expect(spy).toHaveBeenCalledTimes(1);\n\n // Reset to defaults\n service.resetConfig();\n expect(spy).toHaveBeenCalledTimes(2);\n\n // Second reset to defaults\n service.resetConfig();\n expect(spy).toHaveBeenCalledTimes(2);\n });\n\n it('isLanguageSupported reflects Prism registration', () => {\n // typescript is imported by the service; a made-up language is not.\n expect(service.isLanguageSupported('typescript')).toBe(true);\n expect(service.isLanguageSupported('definitely-not-a-language')).toBe(false);\n });\n });\n\n describe('renderMermaid', () => {\n /** Stub the private lazy loader — the point of these specs is WHEN it is called, not what it returns. */\n const stubLoader = (impl: () => Promise<Mermaid>): void => {\n (service as unknown as MermaidLoaderAccessor).loadMermaid = impl;\n };\n\n const containerWith = (html: string): HTMLElement => {\n const container = document.createElement('div');\n container.innerHTML = html;\n return container;\n };\n\n it('never loads the diagram engine when the document has no diagram', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched for a diagram-free document');\n });\n\n const result = await service.renderMermaid(containerWith('<p>no diagrams here</p>'));\n\n expect(result).toBe(false);\n expect(loads).toBe(0);\n });\n\n it('shows a visible failure on every block when the lazy chunk cannot be loaded', async () => {\n stubLoader(() => Promise.reject(new Error('chunk fetch failed')));\n const container = containerWith(\n '<pre><code class=\"language-mermaid\">graph TD; A-->B;</code></pre>' +\n '<div class=\"mermaid\">graph TD; C-->D;</div>',\n );\n\n const result = await service.renderMermaid(container);\n\n expect(result).toBe(false);\n const failed = container.querySelectorAll('.mermaid-error');\n expect(failed.length).toBe(2);\n for (const element of Array.from(failed)) {\n expect(element.getAttribute('data-mermaid-error')).toBe('Diagram engine failed to load');\n }\n });\n\n it('does nothing at all when mermaid is disabled by config', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched when mermaid is disabled');\n });\n service.configureMarked({ enableMermaid: false });\n\n const result = await service.renderMermaid(\n containerWith('<pre><code class=\"language-mermaid\">graph TD; A-->B;</code></pre>'),\n );\n\n expect(result).toBe(false);\n expect(loads).toBe(0);\n });\n\n it('S11: configures securityLevel=\"strict\" and sanitizes SVG output with DOMPurify before DOM insertion', async () => {\n let capturedConfig: Record<string, string | boolean | undefined> | undefined;\n const fakeMermaid: Partial<Mermaid> = {\n initialize: (cfg) => {\n capturedConfig = cfg as Record<string, string | boolean | undefined>;\n },\n render: async () => ({\n svg: '<svg onload=\"alert(1)\"><script>alert(2)</script><a href=\"javascript:alert(3)\"><text>OK</text></a></svg>',\n diagramType: 'flowchart',\n }),\n };\n stubLoader(async () => fakeMermaid as Mermaid);\n const container = containerWith('<pre><code class=\"language-mermaid\">graph TD; A-->B;</code></pre>');\n\n const result = await service.renderMermaid(container);\n\n expect(result).toBe(true);\n expect(capturedConfig?.['securityLevel']).toBe('strict');\n const renderedHtml = container.innerHTML;\n expect(renderedHtml).not.toContain('<script');\n expect(renderedHtml).not.toContain('onload');\n expect(renderedHtml).not.toContain('javascript:');\n expect(renderedHtml).toContain('OK');\n });\n });\n\n describe('RenderMath', () => {\n /** Parse through the real pipeline (sanitizer included) and mount it, as the component does. */\n const mount = (markdown: string): HTMLElement => {\n const container = document.createElement('div');\n container.innerHTML = service.Parse(markdown);\n return container;\n };\n\n const stubLoader = (impl: () => Promise<unknown>): void => {\n (service as unknown as KatexLoaderAccessor).loadKatex = impl;\n };\n\n it('typesets inline and display math as MathML with the real engine', async () => {\n const container = mount('Energy $E = mc^2$ where\\n\\n$$\\n\\\\frac{a}{b}\\n$$');\n\n expect(await service.RenderMath(container)).toBe(true);\n\n const formulas = container.querySelectorAll('math');\n expect(formulas.length).toBe(2);\n expect(formulas[0].getAttribute('display')).toBeNull();\n expect(formulas[1].getAttribute('display')).toBe('block');\n expect(container.querySelector('mfrac')).not.toBeNull();\n expect(container.querySelector('annotation')?.textContent).toBe('E = mc^2');\n expect(container.querySelector('code.mj-math')).toBeNull();\n });\n\n it('spells styled letters with Unicode math characters, which Chrome renders (it ignores mathvariant)', async () => {\n const container = mount('$\\\\mathbf{E} \\\\in \\\\mathbb{R}^3, \\\\mathcal{L}, \\\\mathfrak{H}, \\\\mathbf{0}, \\\\boldsymbol{\\\\alpha}$');\n\n await service.RenderMath(container);\n\n const identifiers = Array.from(container.querySelectorAll('mi, mn')).map((n) => n.textContent);\n expect(identifiers).toEqual(expect.arrayContaining(['𝐄', 'ℝ', 'ℒ', 'ℌ', '𝟎']));\n expect(container.querySelector('mi[mathvariant=\"bold\"], mi[mathvariant=\"double-struck\"]')).toBeNull();\n // Greek has no Unicode form here: it keeps the attribute for the CSS bold fallback.\n expect(container.querySelector('mi[mathvariant=\"bold-italic\"]')?.textContent).toBe('α');\n // The TeX source in the annotation is untouched.\n expect(container.querySelector('annotation')?.textContent).toContain('\\\\mathbf{E}');\n });\n\n it('leaves TeX it cannot parse visible as source, and still typesets the rest', async () => {\n const container = mount('Broken $\\\\frac{a$ but fine $x^2$');\n\n expect(await service.RenderMath(container)).toBe(true);\n\n const broken = container.querySelector('code.mj-math.mj-math-error');\n expect(broken?.textContent).toBe('\\\\frac{a');\n expect(broken?.getAttribute('title')).toBeTruthy();\n expect(container.querySelectorAll('math').length).toBe(1);\n });\n\n it('leaves a formula that defines macros as source (expansion bombs)', async () => {\n const container = mount('$\\\\def\\\\a{x x x}\\\\a\\\\a$ and $y$');\n\n await service.RenderMath(container);\n\n const kept = container.querySelector('code.mj-math.mj-math-error');\n expect(kept?.textContent).toBe('\\\\def\\\\a{x x x}\\\\a\\\\a');\n expect(kept?.getAttribute('title')).toContain('macros');\n expect(container.querySelectorAll('math').length).toBe(1);\n });\n\n it('caps user sizes', async () => {\n const container = mount('$\\\\rule{100000em}{100000em}$');\n\n await service.RenderMath(container);\n\n const rule = container.querySelector('mspace');\n expect(parseFloat(rule?.getAttribute('width') ?? '0')).toBeLessThanOrEqual(20);\n expect(parseFloat(rule?.getAttribute('height') ?? '0')).toBeLessThanOrEqual(20);\n });\n\n it('skips placeholders a newer render replaced while KaTeX was loading', async () => {\n let release: (engine: unknown) => void = () => undefined;\n stubLoader(() => new Promise((resolve) => (release = resolve)));\n const container = mount('$x^2$');\n\n const pending = service.RenderMath(container);\n container.innerHTML = service.Parse('$y^2$'); // the next streamed chunk\n release(katex);\n\n expect(await pending).toBe(false);\n expect(container.querySelector('math')).toBeNull();\n expect(container.querySelector('code.mj-math')?.textContent).toBe('y^2');\n });\n\n it('keeps \\\\href inert (trust is off)', async () => {\n const container = mount('$\\\\href{javascript:alert(1)}{x}$');\n\n await service.RenderMath(container);\n\n // No link anywhere: the command shows as an unrendered \"\\href\". The URL survives only\n // as text inside <annotation>, which is the TeX source and never a link.\n expect(container.querySelector('a, [href]')).toBeNull();\n expect(container.querySelector('mtext')?.textContent).toBe('\\\\href');\n });\n\n it('never loads the engine when the document has no math', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched for a math-free document');\n });\n\n expect(await service.RenderMath(mount('It costs $5 and $10.'))).toBe(false);\n expect(loads).toBe(0);\n });\n\n it('leaves the source showing when the lazy chunk cannot be loaded', async () => {\n stubLoader(() => Promise.reject(new Error('chunk fetch failed')));\n const container = mount('$x^2$');\n\n expect(await service.RenderMath(container)).toBe(false);\n expect(container.querySelector('code.mj-math')?.textContent).toBe('x^2');\n });\n\n it('does nothing at all when math is disabled by config', async () => {\n let loads = 0;\n stubLoader(async () => {\n loads++;\n throw new Error('the engine must not be fetched when math is disabled');\n });\n service.ConfigureMarked({ enableMath: false });\n\n const container = mount('$x^2$');\n\n expect(await service.RenderMath(container)).toBe(false);\n expect(loads).toBe(0);\n expect(container.textContent?.trim()).toBe('$x^2$');\n });\n });\n\n describe('MathML markup', () => {\n const MATHML_NS = 'http://www.w3.org/1998/Math/MathML';\n const mount = (markdown: string): HTMLElement => {\n const container = document.createElement('div');\n container.innerHTML = service.Parse(markdown);\n return container;\n };\n\n it('keeps a JATS formula as real MathML elements, prefixes removed', () => {\n const c = mount('Loss <mml:math display=\"inline\"><mml:mn>7</mml:mn><mml:mo>×</mml:mo><mml:msup><mml:mn>10</mml:mn><mml:mn>13</mml:mn></mml:msup></mml:math> per pulse.');\n const msup = c.querySelector('msup');\n expect(msup?.namespaceURI).toBe(MATHML_NS);\n expect(msup?.textContent).toBe('1013');\n expect(c.textContent).toContain('per pulse.');\n });\n\n it('keeps a table\\'s column alignment and spacing (DOMPurify misspells one, lacks the other)', () => {\n const c = mount('<math display=\"block\"><mtable columnalign=\"right left\" columnspacing=\"0em 2em\"><mtr><mtd><mi>a</mi></mtd><mtd><mo>=</mo><mi>b</mi></mtd></mtr></mtable></math>');\n const table = c.querySelector('mtable');\n expect(table?.getAttribute('columnalign')).toBe('right left');\n expect(table?.getAttribute('columnspacing')).toBe('0em 2em');\n });\n\n it('shows the formula once when MathML carries its TeX in an annotation (MathJax, Pandoc, Word)', () => {\n const c = mount('<math><semantics><mrow><msup><mi>x</mi><mn>2</mn></msup></mrow><annotation encoding=\"application/x-tex\">x^2</annotation></semantics></math>');\n expect(c.querySelector('msup')).not.toBeNull();\n expect(c.textContent?.trim()).toBe('x2');\n });\n\n it('spells styled letters with Unicode math characters, as for typeset TeX', async () => {\n const c = mount('<math><mi mathvariant=\"bold\">E</mi><mo>∈</mo><msup><mi mathvariant=\"double-struck\">R</mi><mn>3</mn></msup></math>');\n await service.RenderMath(c);\n expect(Array.from(c.querySelectorAll('mi')).map((n) => n.textContent)).toEqual(['𝐄', 'ℝ']);\n });\n\n // Known DOMPurify bypass shapes through MathML, plus the plain attribute and handler routes.\n it.each([\n ['javascript: href on a MathML element', '<math href=\"javascript:alert(1)\"><mi xlink:href=\"javascript:alert(1)\">x</mi></math>'],\n ['maction with a script link', '<math><maction actiontype=\"statusline\" xlink:href=\"javascript:alert(1)\"><mi>x</mi></maction></math>'],\n ['HTML inside annotation-xml', '<math><annotation-xml encoding=\"text/html\"><img src=\"x\" onerror=\"alert(1)\"></annotation-xml></math>'],\n ['mglyph/style namespace confusion', '<math><mtext><table><mglyph><style><img src=\"x\" onerror=\"alert(1)\">'],\n ['form/math nesting confusion', '<form><math><mtext></form><form><mglyph><style></math><img src=\"x\" onerror=\"alert(1)\">'],\n ['handlers on MathML elements', '<math onclick=\"alert(1)\"><mi onmouseover=\"alert(1)\">x</mi></math>'],\n ])('strips %s', (_name, payload) => {\n const c = mount(payload);\n const attributes = Array.from(c.querySelectorAll('*')).flatMap((el) => Array.from(el.attributes));\n expect(attributes.filter((a) => a.name.startsWith('on'))).toEqual([]);\n expect(attributes.filter((a) => /javascript:/i.test(a.value))).toEqual([]);\n expect(c.querySelector('script')).toBeNull();\n });\n });\n\n describe('parse sanitizes unless scripts are explicitly enabled', () => {\n it('strips handlers and script from passthrough HTML', () => {\n const out = service.parse('<div><img src=\"x\" onerror=\"alert(1)\"><script>alert(2)</script></div>', { enableHtml: true });\n expect(out).not.toContain('onerror');\n expect(out).not.toContain('<script');\n expect(out).toContain('<img');\n });\n\n it('leaves script in place when enableJavaScript is true (the opt-out)', () => {\n const out = service.parse('<div>x</div><script>alert(1)</script>', { enableHtml: true, enableJavaScript: true });\n expect(out).toContain('<script>');\n });\n\n it('sanitizeHtml is exposed for consumers that bind parse() output themselves', () => {\n expect(service.sanitizeHtml('<a href=\"javascript:alert(1)\" onclick=\"x()\">x</a>')).toBe('<a>x</a>');\n });\n });\n\n describe('unwrapMiscodedHtml is inert and keeps leading style', () => {\n afterEach(() => vi.restoreAllMocks());\n const miscoded = '<pre><code>&lt;style&gt;.card{color:red}&lt;/style&gt;&lt;div class=\"card\"&gt;&lt;img src=\"x\" onerror=\"alert(1)\"&gt;&lt;p&gt;hi&lt;/p&gt;&lt;/div&gt;</code></pre>';\n\n it('never creates elements on the live document while unwrapping', () => {\n // Building the replacement on the live document would run image error handlers at\n // parse time, before parse() sanitizes the returned string.\n const createElement = vi.spyOn(document, 'createElement');\n unwrap(miscoded);\n expect(createElement).not.toHaveBeenCalled();\n });\n\n it('unwraps the structural HTML and keeps a leading <style>', () => {\n const out = unwrap(miscoded);\n expect(out).not.toContain('<pre>');\n expect(out).toContain('<style>.card{color:red}</style>');\n expect(out).toContain('<div class=\"card\">');\n });\n\n it('returns markup for parse() to sanitize rather than executing it', () => {\n expect(unwrap(miscoded)).toContain('onerror=\"alert(1)\"');\n });\n });\n});\n"]}
@@ -170,6 +170,40 @@ function useUnicodeMathLetters(root) {
170
170
  */
171
171
  const TEX_MACRO_DEFINITION = /\\(?:[gex]?def|let|futurelet|newcommand|renewcommand|providecommand)(?![a-zA-Z])/;
172
172
  export class MarkdownService {
173
+ areConfigsEqual(a, b) {
174
+ if (a.enableHighlight !== b.enableHighlight ||
175
+ a.enableMermaid !== b.enableMermaid ||
176
+ a.enableMath !== b.enableMath ||
177
+ a.enableCodeCopy !== b.enableCodeCopy ||
178
+ a.enableCollapsibleHeadings !== b.enableCollapsibleHeadings ||
179
+ a.collapsibleHeadingLevel !== b.collapsibleHeadingLevel ||
180
+ a.collapsibleDefaultExpanded !== b.collapsibleDefaultExpanded ||
181
+ a.enableAlerts !== b.enableAlerts ||
182
+ a.enableSmartypants !== b.enableSmartypants ||
183
+ a.enableSvgRenderer !== b.enableSvgRenderer ||
184
+ a.enableHtml !== b.enableHtml ||
185
+ a.enableJavaScript !== b.enableJavaScript ||
186
+ a.enableHeadingIds !== b.enableHeadingIds ||
187
+ a.headingIdPrefix !== b.headingIdPrefix ||
188
+ a.enableLineNumbers !== b.enableLineNumbers ||
189
+ a.mermaidTheme !== b.mermaidTheme ||
190
+ a.sanitize !== b.sanitize) {
191
+ return false;
192
+ }
193
+ const aLevels = a.autoExpandLevels;
194
+ const bLevels = b.autoExpandLevels;
195
+ if (aLevels === bLevels)
196
+ return true;
197
+ if (!aLevels || !bLevels)
198
+ return false;
199
+ if (aLevels.length !== bLevels.length)
200
+ return false;
201
+ for (let i = 0; i < aLevels.length; i++) {
202
+ if (aLevels[i] !== bLevels[i])
203
+ return false;
204
+ }
205
+ return true;
206
+ }
173
207
  constructor() {
174
208
  this.engine = new MarkdownEngine();
175
209
  this.mermaidInitialized = false;
@@ -199,19 +233,39 @@ export class MarkdownService {
199
233
  // Return code as-is if language not found or highlighting fails
200
234
  return code;
201
235
  };
236
+ this.engineConfigured = false;
202
237
  this.ConfigureMarked(this.currentConfig);
203
238
  }
204
239
  /**
205
240
  * Configure the underlying engine with the provided options.
241
+ * Redundant configuration setup is cached and skipped when options have not changed.
206
242
  */
207
243
  ConfigureMarked(config) {
208
- this.currentConfig = { ...DEFAULT_MARKDOWN_CONFIG, ...config };
244
+ const newConfig = { ...DEFAULT_MARKDOWN_CONFIG, ...config };
245
+ if (this.engineConfigured && this.areConfigsEqual(this.currentConfig, newConfig)) {
246
+ return;
247
+ }
248
+ this.currentConfig = newConfig;
209
249
  this.engine.configureMarked(this.currentConfig, { highlightFn: this.prismHighlight });
250
+ this.engineConfigured = true;
210
251
  }
211
252
  /** @deprecated Use {@link ConfigureMarked}. */
212
253
  configureMarked(config) {
213
254
  return this.ConfigureMarked(config);
214
255
  }
256
+ /**
257
+ * Parse markdown to a token list (AST) using the underlying engine.
258
+ * @param markdown The markdown string to tokenize
259
+ * @param config Optional config overrides
260
+ * @returns The marked token list
261
+ */
262
+ ParseToTokens(markdown, config) {
263
+ return this.engine.ParseToTokens(markdown, config);
264
+ }
265
+ /** @deprecated Use {@link ParseToTokens}. */
266
+ parseToTokens(markdown, config) {
267
+ return this.ParseToTokens(markdown, config);
268
+ }
215
269
  /**
216
270
  * Parse markdown to HTML.
217
271
  * @param markdown The markdown string to parse
@@ -326,8 +380,10 @@ export class MarkdownService {
326
380
  mermaid.initialize({
327
381
  startOnLoad: false,
328
382
  theme: effectiveTheme,
329
- securityLevel: 'loose',
383
+ securityLevel: 'strict',
330
384
  fontFamily: 'inherit',
385
+ htmlLabels: false,
386
+ flowchart: { htmlLabels: false },
331
387
  suppressErrorRendering: true // Suppress visual error diagrams - errors go to console only
332
388
  });
333
389
  this.mermaidInitialized = true;
@@ -369,10 +425,19 @@ export class MarkdownService {
369
425
  const id = `mermaid-${Date.now()}-${i}`;
370
426
  // Render the diagram
371
427
  const { svg } = await mermaid.render(id, code);
372
- // Replace the code block with the rendered SVG
428
+ // Sanitize rendered SVG with DOMPurify even under securityLevel: 'strict' (defense-in-depth)
429
+ const purifierInstance = getPurifier();
430
+ if (!purifierInstance) {
431
+ this.markMermaidBlocksFailed([block], 'Diagram sanitization unavailable');
432
+ continue;
433
+ }
434
+ const sanitizedSvg = purifierInstance.sanitize(svg, {
435
+ USE_PROFILES: { svg: true, svgFilters: true },
436
+ });
437
+ // Replace the code block with the sanitized SVG
373
438
  const wrapper = document.createElement('div');
374
439
  wrapper.className = 'mermaid-diagram';
375
- wrapper.innerHTML = svg;
440
+ wrapper.innerHTML = sanitizedSvg;
376
441
  // Replace the pre element (parent of code) or the mermaid element itself
377
442
  const elementToReplace = block.tagName === 'CODE' ? block.parentElement : block;
378
443
  elementToReplace?.parentNode?.replaceChild(wrapper, elementToReplace);
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.service.js","sourceRoot":"","sources":["../../../src/lib/services/markdown.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,MAAM,SAAS,CAAC;AAM5B,OAAO,EACL,cAAc,EAEd,uBAAuB,EAIxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,SAAS,MAAM,WAAW,CAA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AS,CAAC;YAC7B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACK,uBAAuB,CAAC,OAAe;QAC7C,+BAA+B;QAC/B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAE3C,gCAAgC;QAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAEzC,kEAAkE;QAClE,sEAAsE;QACtE,MAAM,oBAAoB,GAAG,mLAAmL,CAAC;QAEjN,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAEtD,kEAAkE;QAClE,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACvD,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAE/B,kEAAkE;QAClE,6EAA6E;QAC7E,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,KAAK,CAAC;QAEvE,OAAO,IAAI,CAAC;IACd,CAAC;gHA/mBU,eAAe;uEAAf,eAAe,WAAf,eAAe,mBAFd,MAAM;;iFAEP,eAAe;cAH3B,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { Injectable } from '@angular/core';\nimport Prism from 'prismjs';\n// TYPE-ONLY — erased at compile time, so it costs nothing at runtime. The mermaid engine\n// itself is fetched on demand; see `loadMermaid()`.\nimport type { Mermaid } from 'mermaid';\n// TYPE-ONLY as well: KaTeX is fetched on demand the same way; see `loadKatex()`.\nimport type katex from 'katex';\nimport {\n MarkdownEngine,\n MarkdownConfig,\n DEFAULT_MARKDOWN_CONFIG,\n ResolvedMarkdownConfig,\n HeadingInfo,\n HighlightFunction\n} from '@memberjunction/markdown-core';\nimport DOMPurify from 'dompurify';\nimport { escapeHtml } from '@memberjunction/markdown-core';\n\n// Import common Prism language components\n// Additional languages can be imported by the consuming application\nimport 'prismjs/components/prism-typescript';\nimport 'prismjs/components/prism-javascript';\nimport 'prismjs/components/prism-css';\nimport 'prismjs/components/prism-scss';\nimport 'prismjs/components/prism-json';\nimport 'prismjs/components/prism-bash';\nimport 'prismjs/components/prism-sql';\nimport 'prismjs/components/prism-python';\nimport 'prismjs/components/prism-csharp';\nimport 'prismjs/components/prism-java';\nimport 'prismjs/components/prism-markup';\nimport 'prismjs/components/prism-yaml';\nimport 'prismjs/components/prism-markdown';\nimport 'prismjs/components/prism-graphql';\n\n/**\n * Service for parsing and rendering markdown content on the web.\n *\n * The parsing/configuration work (marked setup, custom extensions, HTML and\n * token output) is owned by the framework-agnostic `@memberjunction/markdown-core`\n * {@link MarkdownEngine}. This Angular service is the web shell around it: it\n * injects a Prism-based highlighter into the engine and keeps the browser-only\n * concerns here — Mermaid rendering, copy buttons, and the DOM-based fixup of\n * HTML that marked miscoded as a code block.\n */\n/**\n * The DOMPurify instance used for rendered HTML, created once per window and configured\n * once. A private instance rather than the shared default so the hooks below cannot leak\n * into other packages' DOMPurify usage, and so the configuration is parsed once instead\n * of on every render.\n *\n * Profile: HTML + SVG + SVG filters + MathML, which keeps structural markup, inline styles, data\n * attributes, inline vector graphics and formulas written as MathML, and removes the script vectors.\n * MathML is DOMPurify's own profile, with its namespace checks (the mXSS class of bypasses through\n * `<math>` is what those checks exist for). Deviations from\n * DOMPurify's defaults, each deliberate:\n * - FORCE_BODY: a document that starts with `<style>` keeps it (otherwise the parser hoists\n * a leading style element into <head> and it is dropped); agent-authored mockups start\n * that way.\n * - SANITIZE_DOM off: DOMPurify would strip any id or name that collides with a document\n * or form property (`title`, `name`, `location`, ...), which are exactly the slugs\n * heading ids produce. This app does not read globals off `window` by element id, so\n * DOM clobbering has no effect here, and heading anchors matter.\n * - `target` on links is kept, with `rel=\"noopener noreferrer\"` enforced when it is set.\n * - `columnalign` and `columnspacing` are added: DOMPurify's MathML list spells the first\n * `columnsalign` and lacks the second, so MathML tables lost their layout in Firefox and Safari\n * (Chrome ignores both; the component stylesheet aligns columns there). Both are presentational. (`form` on `<mo>` stays out: on HTML it associates an element with a form, and\n * MathML infers an operator's form without it.)\n * - `annotation` / `annotation-xml` content is dropped with the element. DOMPurify removes both but\n * would keep their text, and MathJax, Pandoc and Word MathML carry the TeX source there, so a\n * formula would read \"x2x^2\".\n * - `<use>` is allowed only with a same-document reference (`#id`); external references\n * are removed. SMIL `<animate>`/`<set>` stay disallowed: they can rewrite `href`.\n */\nlet purifier: ReturnType<typeof DOMPurify> | null = null;\n\nfunction getPurifier(): ReturnType<typeof DOMPurify> | null {\n if (purifier) return purifier;\n if (typeof window === 'undefined') return null;\n const instance = DOMPurify(window);\n if (!instance.isSupported) return null;\n instance.setConfig({\n USE_PROFILES: { html: true, svg: true, svgFilters: true, mathMl: true },\n ADD_TAGS: ['use'],\n ADD_ATTR: ['target', 'columnalign', 'columnspacing'],\n ADD_FORBID_CONTENTS: ['annotation', 'annotation-xml'],\n FORCE_BODY: true,\n SANITIZE_DOM: false,\n });\n instance.addHook('uponSanitizeAttribute', (node, data) => {\n const name = data.attrName.toLowerCase();\n if (node.nodeName.toLowerCase() === 'use' && (name === 'href' || name === 'xlink:href')) {\n // Same-document sprite references only. Anything else can load an external document.\n data.keepAttr = data.attrValue.trim().startsWith('#');\n }\n });\n instance.addHook('afterSanitizeAttributes', (node) => {\n const tag = node.nodeName.toLowerCase();\n if (tag === 'a' && node.hasAttribute('target')) {\n node.setAttribute('rel', 'noopener noreferrer');\n }\n if (tag === 'use') {\n // The attribute hook above has already dropped any non-fragment reference; a <use>\n // with nothing left to reference is removed rather than left as an empty element.\n const ref = node.getAttribute('href') ?? node.getAttribute('xlink:href');\n if (!ref || !ref.trim().startsWith('#')) {\n node.parentNode?.removeChild(node);\n }\n }\n });\n purifier = instance;\n return purifier;\n}\n\n/**\n * Unicode's Mathematical Alphanumeric Symbols by MathML `mathvariant`: the code points of capital\n * A, small a and digit 0 (0 where Unicode has no digits in that style).\n */\nconst MATH_LETTER_BASES: Readonly<Record<string, readonly [number, number, number]>> = {\n bold: [0x1d400, 0x1d41a, 0x1d7ce],\n italic: [0x1d434, 0x1d44e, 0],\n 'bold-italic': [0x1d468, 0x1d482, 0],\n script: [0x1d49c, 0x1d4b6, 0],\n 'bold-script': [0x1d4d0, 0x1d4ea, 0],\n fraktur: [0x1d504, 0x1d51e, 0],\n 'double-struck': [0x1d538, 0x1d552, 0x1d7d8],\n 'bold-fraktur': [0x1d56c, 0x1d586, 0],\n 'sans-serif': [0x1d5a0, 0x1d5ba, 0x1d7e2],\n 'bold-sans-serif': [0x1d5d4, 0x1d5ee, 0x1d7ec],\n 'sans-serif-italic': [0x1d608, 0x1d622, 0],\n 'sans-serif-bold-italic': [0x1d63c, 0x1d656, 0],\n monospace: [0x1d670, 0x1d68a, 0x1d7f6],\n};\n\n/** Letters Unicode encoded (in Letterlike Symbols) before that block existed; it has holes where they would go. */\nconst MATH_LETTER_HOLES: Readonly<Record<string, string>> = {\n 'italic h': 'ℎ',\n 'script B': 'ℬ', 'script E': 'ℰ', 'script F': 'ℱ', 'script H': 'ℋ', 'script I': 'ℐ', 'script L': 'ℒ',\n 'script M': 'ℳ', 'script R': 'ℛ', 'script e': 'ℯ', 'script g': 'ℊ', 'script o': 'ℴ',\n 'fraktur C': 'ℭ', 'fraktur H': 'ℌ', 'fraktur I': 'ℑ', 'fraktur R': 'ℜ', 'fraktur Z': 'ℨ',\n 'double-struck C': 'ℂ', 'double-struck H': 'ℍ', 'double-struck N': 'ℕ', 'double-struck P': 'ℙ',\n 'double-struck Q': 'ℚ', 'double-struck R': 'ℝ', 'double-struck Z': 'ℤ',\n};\n\nfunction toMathLetter(char: string, variant: string): string | null {\n const hole = MATH_LETTER_HOLES[`${variant} ${char}`];\n if (hole) return hole;\n const bases = MATH_LETTER_BASES[variant];\n if (!bases) return null;\n const code = char.charCodeAt(0);\n if (code >= 65 && code <= 90) return String.fromCodePoint(bases[0] + code - 65);\n if (code >= 97 && code <= 122) return String.fromCodePoint(bases[1] + code - 97);\n if (code >= 48 && code <= 57 && bases[2]) return String.fromCodePoint(bases[2] + code - 48);\n return null;\n}\n\n/**\n * Chrome lays out MathML Core, which honors `mathvariant` only as \"normal\". KaTeX writes\n * \\mathbf{E} as `<mi mathvariant=\"bold\">E</mi>` and \\mathbb{R} as `mathvariant=\"double-struck\"`,\n * so Chrome would show plain letters, losing the difference between a vector and a scalar. MathML\n * Core's own answer is to spell such letters with their Unicode math characters (𝐄, ℝ), which every\n * browser renders. Identifiers and numbers only; anything without a Unicode form (Greek, text runs)\n * keeps its attribute and gets the CSS fallback in the component stylesheet.\n */\nfunction useUnicodeMathLetters(root: Element): void {\n root.querySelectorAll('mi[mathvariant], mn[mathvariant]').forEach((node) => {\n const variant = node.getAttribute('mathvariant') ?? '';\n const text = node.textContent ?? '';\n const letters = Array.from(text, (char) => toMathLetter(char, variant));\n if (text && letters.every((letter) => letter !== null)) {\n node.textContent = letters.join('');\n node.removeAttribute('mathvariant');\n }\n });\n}\n\n/**\n * TeX that defines macros. KaTeX's `maxExpand` counts expansions, not output, so three kilobytes of\n * `\\def` can expand to half a million MathML nodes and freeze the tab, again on every streamed\n * chunk. A rendered answer has no use for its own macros, so such formulas stay source.\n */\nconst TEX_MACRO_DEFINITION = /\\\\(?:[gex]?def|let|futurelet|newcommand|renewcommand|providecommand)(?![a-zA-Z])/;\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MarkdownService {\n private engine = new MarkdownEngine();\n private mermaidInitialized = false;\n private lastMermaidTheme: string | null = null;\n private currentConfig: ResolvedMarkdownConfig = { ...DEFAULT_MARKDOWN_CONFIG };\n /** The mermaid engine, once its lazy chunk has landed. Null until a diagram is actually rendered. */\n private mermaidEngine: Mermaid | null = null;\n /** In-flight load, so N diagrams in one document share ONE chunk fetch. */\n private mermaidLoad: Promise<Mermaid> | null = null;\n /** The KaTeX engine, once its lazy chunk has landed. Null until a formula is actually typeset. */\n private katexEngine: typeof katex | null = null;\n /** In-flight load, so N formulas in one document share ONE chunk fetch. */\n private katexLoad: Promise<typeof katex> | null = null;\n\n /**\n * Prism-backed highlight function injected into the core engine. The engine\n * itself has no Prism dependency — it calls this for the HTML output path.\n */\n private prismHighlight: HighlightFunction = (code: string, lang: string): string => {\n if (lang && Prism.languages[lang]) {\n try {\n return Prism.highlight(code, Prism.languages[lang], lang);\n } catch (e) {\n console.warn(`Prism highlighting failed for language: ${lang}`, e);\n }\n }\n // Return code as-is if language not found or highlighting fails\n return code;\n };\n\n constructor() {\n this.ConfigureMarked(this.currentConfig);\n }\n\n /**\n * Configure the underlying engine with the provided options.\n */\n public ConfigureMarked(config: MarkdownConfig): void {\n this.currentConfig = { ...DEFAULT_MARKDOWN_CONFIG, ...config };\n this.engine.configureMarked(this.currentConfig, { highlightFn: this.prismHighlight });\n }\n\n /** @deprecated Use {@link ConfigureMarked}. */\n public configureMarked(config: MarkdownConfig): void {\n return this.ConfigureMarked(config);\n }\n\n /**\n * Parse markdown to HTML.\n * @param markdown The markdown string to parse\n * @param config Optional config overrides for this parse operation\n * @returns The rendered HTML string\n */\n public Parse(markdown: string, config?: Partial<MarkdownConfig>): string {\n if (!markdown) return '';\n\n // Apply config overrides if provided (re-injects the Prism highlighter)\n if (config) {\n this.ConfigureMarked({ ...this.currentConfig, ...config });\n }\n\n let html = this.engine.parseToHtml(markdown);\n\n // When HTML passthrough is enabled, fix incorrectly code-wrapped HTML.\n // marked sometimes wraps inline HTML in <pre><code> blocks. This is a\n // DOM-based fixup so it stays in the web service, not the core engine.\n if (this.currentConfig.enableHtml) {\n html = this.unwrapMiscodedHtml(html);\n }\n\n // The service is the one place every consumer passes through (the component, the chat\n // widget, anything binding parse() output to innerHTML), so the sanitizer runs here.\n // enableJavaScript is the explicit opt-out.\n if (!this.currentConfig.enableJavaScript) {\n html = this.SanitizeHtml(html);\n }\n\n return html;\n }\n\n /** @deprecated Use {@link Parse}. */\n public parse(markdown: string, config?: Partial<MarkdownConfig>): string {\n return this.Parse(markdown, config);\n }\n\n /**\n * Sanitize rendered HTML for binding to innerHTML while preserving layout HTML, inline\n * styles and inline SVG. See the DOMPurify configuration at the top of this file for\n * what is kept and removed. Where no DOM is available to sanitize with, the markup is\n * escaped and rendered as text rather than trusted.\n */\n public SanitizeHtml(html: string): string {\n const instance = getPurifier();\n if (!instance) {\n return escapeHtml(html);\n }\n return instance.sanitize(html);\n }\n\n /** @deprecated Use {@link SanitizeHtml}. */\n public sanitizeHtml(html: string): string {\n return this.SanitizeHtml(html);\n }\n\n /**\n * Parse markdown asynchronously (useful for large documents)\n */\n public async ParseAsync(markdown: string, config?: Partial<MarkdownConfig>): Promise<string> {\n return this.Parse(markdown, config);\n }\n\n /** @deprecated Use {@link ParseAsync}. */\n public async parseAsync(markdown: string, config?: Partial<MarkdownConfig>): Promise<string> {\n return this.ParseAsync(markdown, config);\n }\n\n /**\n * Resolve the effective mermaid theme.\n * 'auto' maps to 'dark' or 'default' based on the document's data-theme attribute.\n */\n private resolveEffectiveMermaidTheme(): 'default' | 'dark' | 'forest' | 'neutral' | 'base' {\n const configTheme = this.currentConfig.mermaidTheme;\n if (configTheme !== 'auto') {\n return configTheme;\n }\n const isDark = typeof document !== 'undefined'\n && document.documentElement.getAttribute('data-theme') === 'dark';\n return isDark ? 'dark' : 'default';\n }\n\n /**\n * Fetch the mermaid engine, on first use only.\n *\n * MEASURED BUNDLE DEFERRAL — this is deliberately a dynamic `import()`, NOT a top-level\n * one, and must not be \"tidied\" back into a static import. `mermaid` and the parsing /\n * graph engines it pulls with it (`@mermaid-js/parser`, `langium`, `chevrotain`,\n * `cytoscape`, `katex`, `d3`) were ~0.95 MB raw of every host's initial download even\n * when no document ever contained a diagram. That is a rounding error for an in-app\n * host and the whole cost for a CDN-loaded embedding of the realtime session overlay\n * (MJ #3882). Documents with no diagram now never fetch the chunk at all.\n *\n * The in-flight promise is cached so N diagrams in one document share one fetch; a\n * FAILED load clears it, so a later render can retry. Retries are bounded by\n * user-driven render calls — there is no loop here.\n */\n private async loadMermaid(): Promise<Mermaid> {\n if (this.mermaidEngine) {\n return this.mermaidEngine;\n }\n\n this.mermaidLoad ??= import('mermaid').then((module) => module.default);\n\n try {\n this.mermaidEngine = await this.mermaidLoad;\n return this.mermaidEngine;\n } catch (error) {\n this.mermaidLoad = null;\n throw error;\n }\n }\n\n /**\n * Initialize Mermaid with the current theme configuration.\n * Re-initializes when the effective theme changes.\n * @param mermaid The lazily-loaded mermaid engine (see {@link loadMermaid})\n */\n private initializeMermaid(mermaid: Mermaid): void {\n const effectiveTheme = this.resolveEffectiveMermaidTheme();\n\n if (this.mermaidInitialized && this.lastMermaidTheme === effectiveTheme) {\n return;\n }\n\n mermaid.initialize({\n startOnLoad: false,\n theme: effectiveTheme,\n securityLevel: 'loose',\n fontFamily: 'inherit',\n suppressErrorRendering: true // Suppress visual error diagrams - errors go to console only\n });\n\n this.mermaidInitialized = true;\n this.lastMermaidTheme = effectiveTheme;\n }\n\n /**\n * Render Mermaid diagrams in a container element\n * Call this after the HTML has been inserted into the DOM\n * @param container The DOM element containing mermaid code blocks\n */\n public async RenderMermaid(container: HTMLElement): Promise<boolean> {\n if (!this.currentConfig.enableMermaid) return false;\n\n // Find all mermaid code blocks BEFORE touching the engine — this is the branch the\n // deferral hangs off: no diagrams in this document means no chunk fetch at all.\n const mermaidBlocks = container.querySelectorAll('pre > code.language-mermaid, .mermaid');\n\n if (mermaidBlocks.length === 0) return false;\n\n let mermaid: Mermaid;\n try {\n mermaid = await this.loadMermaid();\n } catch (error) {\n // The chunk could not be fetched (offline, blocked host, bad deploy). Say so on\n // every block we were going to render — an empty panel would look like the diagram\n // simply wasn't there.\n console.error('Failed to load the Mermaid diagram engine:', error);\n this.markMermaidBlocksFailed(mermaidBlocks, 'Diagram engine failed to load');\n return false;\n }\n\n this.initializeMermaid(mermaid);\n\n for (let i = 0; i < mermaidBlocks.length; i++) {\n const block = mermaidBlocks[i];\n const code = block.textContent || '';\n\n if (!code.trim()) continue;\n\n try {\n // Create a unique ID for this diagram\n const id = `mermaid-${Date.now()}-${i}`;\n\n // Render the diagram\n const { svg } = await mermaid.render(id, code);\n\n // Replace the code block with the rendered SVG\n const wrapper = document.createElement('div');\n wrapper.className = 'mermaid-diagram';\n wrapper.innerHTML = svg;\n\n // Replace the pre element (parent of code) or the mermaid element itself\n const elementToReplace = block.tagName === 'CODE' ? block.parentElement : block;\n elementToReplace?.parentNode?.replaceChild(wrapper, elementToReplace);\n } catch (error) {\n console.warn('Mermaid rendering failed:', error);\n // Show it failed on this block — the source stays visible underneath.\n this.markMermaidBlocksFailed([block], 'Diagram rendering failed');\n }\n }\n\n return true;\n }\n\n /** @deprecated Use {@link RenderMermaid}. */\n public async renderMermaid(container: HTMLElement): Promise<boolean> {\n return this.RenderMermaid(container);\n }\n\n /**\n * Fetch the KaTeX engine, on first use only. A dynamic `import()` under the \"genuine bundle-size\n * deferral\" allowance (typescript-style rules, category 3), like {@link loadMermaid}: KaTeX is\n * 277 KB minified (76 KB gzipped), and documents with no math never download it. A failed load\n * clears the cached promise so a later render can retry.\n */\n private async loadKatex(): Promise<typeof katex> {\n if (this.katexEngine) {\n return this.katexEngine;\n }\n\n this.katexLoad ??= import('katex').then((module) => module.default);\n\n try {\n this.katexEngine = await this.katexLoad;\n return this.katexEngine;\n } catch (error) {\n this.katexLoad = null;\n throw error;\n }\n }\n\n /**\n * Spell MathML's styled letters (`mathvariant=\"bold\"`, `\"double-struck\"`, ...) with their Unicode\n * math characters, which Chrome renders. `RenderMath` already does this; call it on its own when\n * math is off, because MathML that arrived as markup still renders then.\n *\n * @param container The DOM element containing the MathML\n */\n public UseUnicodeMathLetters(container: HTMLElement): void {\n useUnicodeMathLetters(container);\n }\n\n /**\n * Typeset TeX math in a container: every `code.mj-math` placeholder that markdown-core's\n * math extension emitted. Call this after the HTML has been inserted into the DOM. MathML that\n * arrived as markup is already rendered by the browser; it only gets the letter fix below.\n *\n * The output is MathML, which current browsers lay out natively, so hosts need no KaTeX\n * stylesheet or fonts. KaTeX builds the nodes itself from the TeX text (no HTML string is\n * parsed) and runs with `trust` off, so `\\href`, `\\url` and `\\includegraphics` stay inert.\n * A formula KaTeX cannot parse, one that defines macros, or an engine that fails to load leaves\n * the TeX source showing as code. User sizes are capped at 20em.\n *\n * Whether math is on is the caller's decision (`<mj-markdown>` checks its `EnableMath` input):\n * this service is a root singleton whose config the last-rendered component set, so it is no\n * guide to the container in hand. Without math enabled at parse time there are no placeholders.\n *\n * @param container The DOM element containing the math placeholders\n * @returns true if at least one TeX formula was typeset\n */\n public async RenderMath(container: HTMLElement): Promise<boolean> {\n // MathML that arrived as markup (a formula from a JATS article) needs the same Chrome fix as\n // KaTeX's output, and no engine.\n useUnicodeMathLetters(container);\n\n // Find the placeholders BEFORE touching the engine: no math, no chunk fetch.\n const placeholders = container.querySelectorAll<HTMLElement>('code.mj-math');\n if (placeholders.length === 0) return false;\n\n let engine: typeof katex;\n try {\n engine = await this.loadKatex();\n } catch (error) {\n console.error('Failed to load the KaTeX math engine:', error);\n return false;\n }\n\n let typeset = false;\n placeholders.forEach((placeholder) => {\n // A newer render (the next streamed chunk) replaced it while KaTeX was loading.\n if (!container.contains(placeholder)) return;\n const tex = placeholder.textContent ?? '';\n const target = document.createElement('span');\n try {\n if (TEX_MACRO_DEFINITION.test(tex)) {\n throw new Error('Formulas that define macros are not typeset');\n }\n engine.render(tex, target, {\n displayMode: placeholder.classList.contains('mj-math-display'),\n output: 'mathml',\n throwOnError: true,\n strict: 'ignore',\n maxSize: 20\n });\n useUnicodeMathLetters(target);\n placeholder.replaceWith(...Array.from(target.childNodes));\n typeset = true;\n } catch (error) {\n placeholder.classList.add('mj-math-error');\n placeholder.title = error instanceof Error ? error.message : 'This formula could not be typeset';\n }\n });\n\n return typeset;\n }\n\n /**\n * Mark mermaid blocks as un-renderable, so the failure is VISIBLE rather than a block of\n * raw diagram source the reader can't explain. The `.mermaid-error` class carries the\n * error styling and a default caption; `data-mermaid-error` overrides that caption with\n * the specific reason (see `.mermaid-error[data-mermaid-error]::before` in the component\n * stylesheet).\n *\n * @param blocks The mermaid code blocks (or `.mermaid` elements) that could not be rendered\n * @param message Short reason shown above the un-rendered source\n */\n private markMermaidBlocksFailed(blocks: ArrayLike<Element>, message: string): void {\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n const target = block.tagName === 'CODE' ? block.parentElement : block;\n target?.classList.add('mermaid-error');\n target?.setAttribute('data-mermaid-error', message);\n }\n }\n\n /**\n * Highlight code blocks with Prism\n * Call this after the HTML has been inserted into the DOM\n * @param container The DOM element containing code blocks\n */\n public HighlightCode(container: HTMLElement): void {\n if (!this.currentConfig.enableHighlight) return;\n\n // Prism.highlightAllUnder handles finding and highlighting code blocks\n Prism.highlightAllUnder(container);\n }\n\n /** @deprecated Use {@link HighlightCode}. */\n public highlightCode(container: HTMLElement): void {\n return this.HighlightCode(container);\n }\n\n /**\n * Add copy buttons to code blocks\n * @param container The DOM element containing code blocks\n */\n public AddCodeCopyButtons(container: HTMLElement): void {\n if (!this.currentConfig.enableCodeCopy) return;\n\n const codeBlocks = container.querySelectorAll('pre > code');\n\n codeBlocks.forEach((codeBlock) => {\n const pre = codeBlock.parentElement;\n if (!pre || pre.querySelector('.code-copy-btn')) return; // Already has button\n\n // Create copy button\n const button = document.createElement('button');\n button.className = 'code-copy-btn';\n button.innerHTML = '<i class=\"fas fa-copy\"></i>';\n button.title = 'Copy code';\n button.type = 'button';\n\n button.addEventListener('click', async () => {\n const code = codeBlock.textContent || '';\n\n try {\n await navigator.clipboard.writeText(code);\n button.innerHTML = '<i class=\"fas fa-check\"></i>';\n button.classList.add('copied');\n\n setTimeout(() => {\n button.innerHTML = '<i class=\"fas fa-copy\"></i>';\n button.classList.remove('copied');\n }, 2000);\n } catch (err) {\n console.error('Failed to copy code:', err);\n button.innerHTML = '<i class=\"fas fa-times\"></i>';\n\n setTimeout(() => {\n button.innerHTML = '<i class=\"fas fa-copy\"></i>';\n }, 2000);\n }\n });\n\n // Add toolbar wrapper\n const toolbar = document.createElement('div');\n toolbar.className = 'code-toolbar';\n toolbar.appendChild(button);\n\n // Make pre position relative for absolute positioning of toolbar\n pre.style.position = 'relative';\n pre.appendChild(toolbar);\n });\n }\n\n /** @deprecated Use {@link AddCodeCopyButtons}. */\n public addCodeCopyButtons(container: HTMLElement): void {\n return this.AddCodeCopyButtons(container);\n }\n\n /**\n * Initialize collapsible heading functionality\n * This method is a no-op - the component handles event binding\n * @param container The DOM element containing collapsible sections\n */\n public InitializeCollapsibleHeadings(_container: HTMLElement): void {\n // Event binding is handled by the component's setupCollapsibleListeners\n // This method exists for API compatibility but does nothing\n }\n\n /** @deprecated Use {@link InitializeCollapsibleHeadings}. */\n public initializeCollapsibleHeadings(_container: HTMLElement): void {\n return this.InitializeCollapsibleHeadings(_container);\n }\n\n /**\n * Get the list of headings from the last parsed document\n * Useful for building table of contents\n */\n public GetHeadingList(): HeadingInfo[] {\n return this.engine.getHeadingList();\n }\n\n /** @deprecated Use {@link GetHeadingList}. */\n public getHeadingList(): HeadingInfo[] {\n return this.GetHeadingList();\n }\n\n /**\n * Get the current configuration\n */\n public GetConfig(): ResolvedMarkdownConfig {\n return this.engine.getConfig();\n }\n\n /** @deprecated Use {@link GetConfig}. */\n public getConfig(): ResolvedMarkdownConfig {\n return this.GetConfig();\n }\n\n /**\n * Reset configuration to defaults\n */\n public ResetConfig(): void {\n this.ConfigureMarked(DEFAULT_MARKDOWN_CONFIG);\n }\n\n /** @deprecated Use {@link ResetConfig}. */\n public resetConfig(): void {\n return this.ResetConfig();\n }\n\n /**\n * Check if a language is supported by Prism\n */\n public IsLanguageSupported(lang: string): boolean {\n return !!Prism.languages[lang];\n }\n\n /** @deprecated Use {@link IsLanguageSupported}. */\n public isLanguageSupported(lang: string): boolean {\n return this.IsLanguageSupported(lang);\n }\n\n /**\n * Get list of supported Prism languages\n */\n public GetSupportedLanguages(): string[] {\n return Object.keys(Prism.languages).filter(\n lang => typeof Prism.languages[lang] === 'object'\n );\n }\n\n /** @deprecated Use {@link GetSupportedLanguages}. */\n public getSupportedLanguages(): string[] {\n return this.GetSupportedLanguages();\n }\n\n /**\n * Fix HTML that was incorrectly wrapped in <pre><code> blocks by marked.\n * This happens when marked interprets inline HTML (especially indented HTML)\n * as code blocks. We detect this by checking if the code block content\n * looks like valid HTML structure rather than actual code.\n *\n * Only processes code blocks WITHOUT a language class (e.g., language-javascript)\n * to avoid unwrapping intentional code examples.\n */\n private unwrapMiscodedHtml(html: string): string {\n // Quick check - if no pre tags, nothing to do\n if (!html.includes('<pre>')) {\n return html;\n }\n\n // Skip if SVG is present - DOMParser mangles SVG elements like <rect>\n // when parsing as 'text/html' due to namespace issues\n if (html.includes('<svg')) {\n return html;\n }\n\n try {\n const parser = new DOMParser();\n const doc = parser.parseFromString(`<div>${html}</div>`, 'text/html');\n const container = doc.body.firstChild as HTMLElement;\n\n if (!container) return html;\n\n // Find all pre > code elements WITHOUT a language class\n // Code blocks with language classes (language-javascript, etc.) are intentional\n const preElements = container.querySelectorAll('pre');\n let modified = false;\n\n for (const pre of Array.from(preElements)) {\n const code = pre.querySelector('code');\n if (!code) continue;\n\n // Skip if code has a language class - it's intentional code\n const hasLanguageClass = code.className && /language-\\w+/.test(code.className);\n if (hasLanguageClass) continue;\n\n // Get the text content (this is HTML-decoded by the browser)\n const content = code.textContent?.trim() || '';\n\n // Check if this looks like HTML that was incorrectly wrapped\n if (this.looksLikeStructuralHtml(content)) {\n // Verify it parses as valid HTML with actual elements\n const testDoc = parser.parseFromString(content, 'text/html');\n const hasStructure = testDoc.body.children.length > 0 ||\n (testDoc.body.innerHTML.trim().length > 0 &&\n testDoc.body.innerHTML.includes('<'));\n\n if (hasStructure) {\n // Replace the <pre> with the actual HTML content. The nodes are built inside a\n // <template> of the inert DOMParser document, never on the live `document`:\n // setting innerHTML on a live element fires image error handlers at parse time,\n // before the sanitizer in parse() has seen the markup. A <template> also parses\n // in body context, so a mockup that starts with <style> keeps it (a full-document\n // parse would hoist it into <head> and drop it).\n const template = doc.createElement('template');\n template.innerHTML = content;\n pre.replaceWith(template.content);\n modified = true;\n }\n }\n }\n\n if (modified) {\n return container.innerHTML;\n }\n } catch (error) {\n console.warn('Error in unwrapMiscodedHtml:', error);\n }\n\n return html;\n }\n\n /**\n * Check if content looks like structural HTML that was incorrectly\n * wrapped in a code block. We look for common HTML element patterns\n * that indicate this is meant to be rendered HTML, not code.\n */\n private looksLikeStructuralHtml(content: string): boolean {\n // Must start with < to be HTML\n if (!content.startsWith('<')) return false;\n\n // Must end with > (closing tag)\n if (!content.endsWith('>')) return false;\n\n // Check for common structural HTML tags that indicate layout HTML\n // These are tags that would typically appear in a UI mockup/prototype\n const structuralTagPattern = /<(div|span|table|tr|td|th|thead|tbody|p|ul|ol|li|section|article|header|footer|nav|main|aside|form|input|button|label|select|option|textarea|h[1-6]|img|a|strong|em|b|i|br|hr)\\b/i;\n\n if (!structuralTagPattern.test(content)) return false;\n\n // Additional check: should have multiple tags or nested structure\n // Single self-closing tags like <br> or <img> shouldn't trigger unwrapping\n const tagCount = (content.match(/<\\w+/g) || []).length;\n if (tagCount < 2) return false;\n\n // Check it's not just showing HTML as an example (common in docs)\n // If content has lots of &lt; or &gt; it's probably escaped HTML being shown\n if (content.includes('&lt;') || content.includes('&gt;')) return false;\n\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"markdown.service.js","sourceRoot":"","sources":["../../../src/lib/services/markdown.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,MAAM,SAAS,CAAC;AAM5B,OAAO,EACL,cAA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,CAAC;YACH,CAAC;YAED,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,SAAS,CAAC,SAAS,CAAC;YAC7B,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACK,uBAAuB,CAAC,OAAe;QAC7C,+BAA+B;QAC/B,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAE3C,gCAAgC;QAChC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAEzC,kEAAkE;QAClE,sEAAsE;QACtE,MAAM,oBAAoB,GAAG,mLAAmL,CAAC;QAEjN,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAEtD,kEAAkE;QAClE,2EAA2E;QAC3E,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACvD,IAAI,QAAQ,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAE/B,kEAAkE;QAClE,6EAA6E;QAC7E,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,KAAK,CAAC;QAEvE,OAAO,IAAI,CAAC;IACd,CAAC;gHAnrBU,eAAe;uEAAf,eAAe,WAAf,eAAe,mBAFd,MAAM;;iFAEP,eAAe;cAH3B,UAAU;eAAC;gBACV,UAAU,EAAE,MAAM;aACnB","sourcesContent":["import { Injectable } from '@angular/core';\nimport Prism from 'prismjs';\n// TYPE-ONLY — erased at compile time, so it costs nothing at runtime. The mermaid engine\n// itself is fetched on demand; see `loadMermaid()`.\nimport type { Mermaid } from 'mermaid';\n// TYPE-ONLY as well: KaTeX is fetched on demand the same way; see `loadKatex()`.\nimport type katex from 'katex';\nimport {\n MarkdownEngine,\n MarkdownConfig,\n DEFAULT_MARKDOWN_CONFIG,\n ResolvedMarkdownConfig,\n HeadingInfo,\n HighlightFunction\n} from '@memberjunction/markdown-core';\nimport DOMPurify from 'dompurify';\nimport { escapeHtml } from '@memberjunction/markdown-core';\n\n// Import common Prism language components\n// Additional languages can be imported by the consuming application\nimport 'prismjs/components/prism-typescript';\nimport 'prismjs/components/prism-javascript';\nimport 'prismjs/components/prism-css';\nimport 'prismjs/components/prism-scss';\nimport 'prismjs/components/prism-json';\nimport 'prismjs/components/prism-bash';\nimport 'prismjs/components/prism-sql';\nimport 'prismjs/components/prism-python';\nimport 'prismjs/components/prism-csharp';\nimport 'prismjs/components/prism-java';\nimport 'prismjs/components/prism-markup';\nimport 'prismjs/components/prism-yaml';\nimport 'prismjs/components/prism-markdown';\nimport 'prismjs/components/prism-graphql';\n\n/**\n * Service for parsing and rendering markdown content on the web.\n *\n * The parsing/configuration work (marked setup, custom extensions, HTML and\n * token output) is owned by the framework-agnostic `@memberjunction/markdown-core`\n * {@link MarkdownEngine}. This Angular service is the web shell around it: it\n * injects a Prism-based highlighter into the engine and keeps the browser-only\n * concerns here — Mermaid rendering, copy buttons, and the DOM-based fixup of\n * HTML that marked miscoded as a code block.\n */\n/**\n * The DOMPurify instance used for rendered HTML, created once per window and configured\n * once. A private instance rather than the shared default so the hooks below cannot leak\n * into other packages' DOMPurify usage, and so the configuration is parsed once instead\n * of on every render.\n *\n * Profile: HTML + SVG + SVG filters + MathML, which keeps structural markup, inline styles, data\n * attributes, inline vector graphics and formulas written as MathML, and removes the script vectors.\n * MathML is DOMPurify's own profile, with its namespace checks (the mXSS class of bypasses through\n * `<math>` is what those checks exist for). Deviations from\n * DOMPurify's defaults, each deliberate:\n * - FORCE_BODY: a document that starts with `<style>` keeps it (otherwise the parser hoists\n * a leading style element into <head> and it is dropped); agent-authored mockups start\n * that way.\n * - SANITIZE_DOM off: DOMPurify would strip any id or name that collides with a document\n * or form property (`title`, `name`, `location`, ...), which are exactly the slugs\n * heading ids produce. This app does not read globals off `window` by element id, so\n * DOM clobbering has no effect here, and heading anchors matter.\n * - `target` on links is kept, with `rel=\"noopener noreferrer\"` enforced when it is set.\n * - `columnalign` and `columnspacing` are added: DOMPurify's MathML list spells the first\n * `columnsalign` and lacks the second, so MathML tables lost their layout in Firefox and Safari\n * (Chrome ignores both; the component stylesheet aligns columns there). Both are presentational. (`form` on `<mo>` stays out: on HTML it associates an element with a form, and\n * MathML infers an operator's form without it.)\n * - `annotation` / `annotation-xml` content is dropped with the element. DOMPurify removes both but\n * would keep their text, and MathJax, Pandoc and Word MathML carry the TeX source there, so a\n * formula would read \"x2x^2\".\n * - `<use>` is allowed only with a same-document reference (`#id`); external references\n * are removed. SMIL `<animate>`/`<set>` stay disallowed: they can rewrite `href`.\n */\nlet purifier: ReturnType<typeof DOMPurify> | null = null;\n\nfunction getPurifier(): ReturnType<typeof DOMPurify> | null {\n if (purifier) return purifier;\n if (typeof window === 'undefined') return null;\n const instance = DOMPurify(window);\n if (!instance.isSupported) return null;\n instance.setConfig({\n USE_PROFILES: { html: true, svg: true, svgFilters: true, mathMl: true },\n ADD_TAGS: ['use'],\n ADD_ATTR: ['target', 'columnalign', 'columnspacing'],\n ADD_FORBID_CONTENTS: ['annotation', 'annotation-xml'],\n FORCE_BODY: true,\n SANITIZE_DOM: false,\n });\n instance.addHook('uponSanitizeAttribute', (node, data) => {\n const name = data.attrName.toLowerCase();\n if (node.nodeName.toLowerCase() === 'use' && (name === 'href' || name === 'xlink:href')) {\n // Same-document sprite references only. Anything else can load an external document.\n data.keepAttr = data.attrValue.trim().startsWith('#');\n }\n });\n instance.addHook('afterSanitizeAttributes', (node) => {\n const tag = node.nodeName.toLowerCase();\n if (tag === 'a' && node.hasAttribute('target')) {\n node.setAttribute('rel', 'noopener noreferrer');\n }\n if (tag === 'use') {\n // The attribute hook above has already dropped any non-fragment reference; a <use>\n // with nothing left to reference is removed rather than left as an empty element.\n const ref = node.getAttribute('href') ?? node.getAttribute('xlink:href');\n if (!ref || !ref.trim().startsWith('#')) {\n node.parentNode?.removeChild(node);\n }\n }\n });\n purifier = instance;\n return purifier;\n}\n\n/**\n * Unicode's Mathematical Alphanumeric Symbols by MathML `mathvariant`: the code points of capital\n * A, small a and digit 0 (0 where Unicode has no digits in that style).\n */\nconst MATH_LETTER_BASES: Readonly<Record<string, readonly [number, number, number]>> = {\n bold: [0x1d400, 0x1d41a, 0x1d7ce],\n italic: [0x1d434, 0x1d44e, 0],\n 'bold-italic': [0x1d468, 0x1d482, 0],\n script: [0x1d49c, 0x1d4b6, 0],\n 'bold-script': [0x1d4d0, 0x1d4ea, 0],\n fraktur: [0x1d504, 0x1d51e, 0],\n 'double-struck': [0x1d538, 0x1d552, 0x1d7d8],\n 'bold-fraktur': [0x1d56c, 0x1d586, 0],\n 'sans-serif': [0x1d5a0, 0x1d5ba, 0x1d7e2],\n 'bold-sans-serif': [0x1d5d4, 0x1d5ee, 0x1d7ec],\n 'sans-serif-italic': [0x1d608, 0x1d622, 0],\n 'sans-serif-bold-italic': [0x1d63c, 0x1d656, 0],\n monospace: [0x1d670, 0x1d68a, 0x1d7f6],\n};\n\n/** Letters Unicode encoded (in Letterlike Symbols) before that block existed; it has holes where they would go. */\nconst MATH_LETTER_HOLES: Readonly<Record<string, string>> = {\n 'italic h': 'ℎ',\n 'script B': 'ℬ', 'script E': 'ℰ', 'script F': 'ℱ', 'script H': 'ℋ', 'script I': 'ℐ', 'script L': 'ℒ',\n 'script M': 'ℳ', 'script R': 'ℛ', 'script e': 'ℯ', 'script g': 'ℊ', 'script o': 'ℴ',\n 'fraktur C': 'ℭ', 'fraktur H': 'ℌ', 'fraktur I': 'ℑ', 'fraktur R': 'ℜ', 'fraktur Z': 'ℨ',\n 'double-struck C': 'ℂ', 'double-struck H': 'ℍ', 'double-struck N': 'ℕ', 'double-struck P': 'ℙ',\n 'double-struck Q': 'ℚ', 'double-struck R': 'ℝ', 'double-struck Z': 'ℤ',\n};\n\nfunction toMathLetter(char: string, variant: string): string | null {\n const hole = MATH_LETTER_HOLES[`${variant} ${char}`];\n if (hole) return hole;\n const bases = MATH_LETTER_BASES[variant];\n if (!bases) return null;\n const code = char.charCodeAt(0);\n if (code >= 65 && code <= 90) return String.fromCodePoint(bases[0] + code - 65);\n if (code >= 97 && code <= 122) return String.fromCodePoint(bases[1] + code - 97);\n if (code >= 48 && code <= 57 && bases[2]) return String.fromCodePoint(bases[2] + code - 48);\n return null;\n}\n\n/**\n * Chrome lays out MathML Core, which honors `mathvariant` only as \"normal\". KaTeX writes\n * \\mathbf{E} as `<mi mathvariant=\"bold\">E</mi>` and \\mathbb{R} as `mathvariant=\"double-struck\"`,\n * so Chrome would show plain letters, losing the difference between a vector and a scalar. MathML\n * Core's own answer is to spell such letters with their Unicode math characters (𝐄, ℝ), which every\n * browser renders. Identifiers and numbers only; anything without a Unicode form (Greek, text runs)\n * keeps its attribute and gets the CSS fallback in the component stylesheet.\n */\nfunction useUnicodeMathLetters(root: Element): void {\n root.querySelectorAll('mi[mathvariant], mn[mathvariant]').forEach((node) => {\n const variant = node.getAttribute('mathvariant') ?? '';\n const text = node.textContent ?? '';\n const letters = Array.from(text, (char) => toMathLetter(char, variant));\n if (text && letters.every((letter) => letter !== null)) {\n node.textContent = letters.join('');\n node.removeAttribute('mathvariant');\n }\n });\n}\n\n/**\n * TeX that defines macros. KaTeX's `maxExpand` counts expansions, not output, so three kilobytes of\n * `\\def` can expand to half a million MathML nodes and freeze the tab, again on every streamed\n * chunk. A rendered answer has no use for its own macros, so such formulas stay source.\n */\nconst TEX_MACRO_DEFINITION = /\\\\(?:[gex]?def|let|futurelet|newcommand|renewcommand|providecommand)(?![a-zA-Z])/;\n\n@Injectable({\n providedIn: 'root'\n})\nexport class MarkdownService {\n private engine = new MarkdownEngine();\n private mermaidInitialized = false;\n private lastMermaidTheme: string | null = null;\n private currentConfig: ResolvedMarkdownConfig = { ...DEFAULT_MARKDOWN_CONFIG };\n /** The mermaid engine, once its lazy chunk has landed. Null until a diagram is actually rendered. */\n private mermaidEngine: Mermaid | null = null;\n /** In-flight load, so N diagrams in one document share ONE chunk fetch. */\n private mermaidLoad: Promise<Mermaid> | null = null;\n /** The KaTeX engine, once its lazy chunk has landed. Null until a formula is actually typeset. */\n private katexEngine: typeof katex | null = null;\n /** In-flight load, so N formulas in one document share ONE chunk fetch. */\n private katexLoad: Promise<typeof katex> | null = null;\n\n /**\n * Prism-backed highlight function injected into the core engine. The engine\n * itself has no Prism dependency — it calls this for the HTML output path.\n */\n private prismHighlight: HighlightFunction = (code: string, lang: string): string => {\n if (lang && Prism.languages[lang]) {\n try {\n return Prism.highlight(code, Prism.languages[lang], lang);\n } catch (e) {\n console.warn(`Prism highlighting failed for language: ${lang}`, e);\n }\n }\n // Return code as-is if language not found or highlighting fails\n return code;\n };\n\n private engineConfigured = false;\n\n private areConfigsEqual(a: ResolvedMarkdownConfig, b: ResolvedMarkdownConfig): boolean {\n if (\n a.enableHighlight !== b.enableHighlight ||\n a.enableMermaid !== b.enableMermaid ||\n a.enableMath !== b.enableMath ||\n a.enableCodeCopy !== b.enableCodeCopy ||\n a.enableCollapsibleHeadings !== b.enableCollapsibleHeadings ||\n a.collapsibleHeadingLevel !== b.collapsibleHeadingLevel ||\n a.collapsibleDefaultExpanded !== b.collapsibleDefaultExpanded ||\n a.enableAlerts !== b.enableAlerts ||\n a.enableSmartypants !== b.enableSmartypants ||\n a.enableSvgRenderer !== b.enableSvgRenderer ||\n a.enableHtml !== b.enableHtml ||\n a.enableJavaScript !== b.enableJavaScript ||\n a.enableHeadingIds !== b.enableHeadingIds ||\n a.headingIdPrefix !== b.headingIdPrefix ||\n a.enableLineNumbers !== b.enableLineNumbers ||\n a.mermaidTheme !== b.mermaidTheme ||\n a.sanitize !== b.sanitize\n ) {\n return false;\n }\n const aLevels = a.autoExpandLevels;\n const bLevels = b.autoExpandLevels;\n if (aLevels === bLevels) return true;\n if (!aLevels || !bLevels) return false;\n if (aLevels.length !== bLevels.length) return false;\n for (let i = 0; i < aLevels.length; i++) {\n if (aLevels[i] !== bLevels[i]) return false;\n }\n return true;\n }\n\n constructor() {\n this.ConfigureMarked(this.currentConfig);\n }\n\n /**\n * Configure the underlying engine with the provided options.\n * Redundant configuration setup is cached and skipped when options have not changed.\n */\n public ConfigureMarked(config: MarkdownConfig): void {\n const newConfig: ResolvedMarkdownConfig = { ...DEFAULT_MARKDOWN_CONFIG, ...config };\n if (this.engineConfigured && this.areConfigsEqual(this.currentConfig, newConfig)) {\n return;\n }\n this.currentConfig = newConfig;\n this.engine.configureMarked(this.currentConfig, { highlightFn: this.prismHighlight });\n this.engineConfigured = true;\n }\n\n /** @deprecated Use {@link ConfigureMarked}. */\n public configureMarked(config: MarkdownConfig): void {\n return this.ConfigureMarked(config);\n }\n\n /**\n * Parse markdown to a token list (AST) using the underlying engine.\n * @param markdown The markdown string to tokenize\n * @param config Optional config overrides\n * @returns The marked token list\n */\n public ParseToTokens(markdown: string, config?: Partial<MarkdownConfig>): ReturnType<MarkdownEngine['ParseToTokens']> {\n return this.engine.ParseToTokens(markdown, config);\n }\n\n /** @deprecated Use {@link ParseToTokens}. */\n public parseToTokens(markdown: string, config?: Partial<MarkdownConfig>): ReturnType<MarkdownEngine['ParseToTokens']> {\n return this.ParseToTokens(markdown, config);\n }\n\n /**\n * Parse markdown to HTML.\n * @param markdown The markdown string to parse\n * @param config Optional config overrides for this parse operation\n * @returns The rendered HTML string\n */\n public Parse(markdown: string, config?: Partial<MarkdownConfig>): string {\n if (!markdown) return '';\n\n // Apply config overrides if provided (re-injects the Prism highlighter)\n if (config) {\n this.ConfigureMarked({ ...this.currentConfig, ...config });\n }\n\n let html = this.engine.parseToHtml(markdown);\n\n // When HTML passthrough is enabled, fix incorrectly code-wrapped HTML.\n // marked sometimes wraps inline HTML in <pre><code> blocks. This is a\n // DOM-based fixup so it stays in the web service, not the core engine.\n if (this.currentConfig.enableHtml) {\n html = this.unwrapMiscodedHtml(html);\n }\n\n // The service is the one place every consumer passes through (the component, the chat\n // widget, anything binding parse() output to innerHTML), so the sanitizer runs here.\n // enableJavaScript is the explicit opt-out.\n if (!this.currentConfig.enableJavaScript) {\n html = this.SanitizeHtml(html);\n }\n\n return html;\n }\n\n /** @deprecated Use {@link Parse}. */\n public parse(markdown: string, config?: Partial<MarkdownConfig>): string {\n return this.Parse(markdown, config);\n }\n\n /**\n * Sanitize rendered HTML for binding to innerHTML while preserving layout HTML, inline\n * styles and inline SVG. See the DOMPurify configuration at the top of this file for\n * what is kept and removed. Where no DOM is available to sanitize with, the markup is\n * escaped and rendered as text rather than trusted.\n */\n public SanitizeHtml(html: string): string {\n const instance = getPurifier();\n if (!instance) {\n return escapeHtml(html);\n }\n return instance.sanitize(html);\n }\n\n /** @deprecated Use {@link SanitizeHtml}. */\n public sanitizeHtml(html: string): string {\n return this.SanitizeHtml(html);\n }\n\n /**\n * Parse markdown asynchronously (useful for large documents)\n */\n public async ParseAsync(markdown: string, config?: Partial<MarkdownConfig>): Promise<string> {\n return this.Parse(markdown, config);\n }\n\n /** @deprecated Use {@link ParseAsync}. */\n public async parseAsync(markdown: string, config?: Partial<MarkdownConfig>): Promise<string> {\n return this.ParseAsync(markdown, config);\n }\n\n /**\n * Resolve the effective mermaid theme.\n * 'auto' maps to 'dark' or 'default' based on the document's data-theme attribute.\n */\n private resolveEffectiveMermaidTheme(): 'default' | 'dark' | 'forest' | 'neutral' | 'base' {\n const configTheme = this.currentConfig.mermaidTheme;\n if (configTheme !== 'auto') {\n return configTheme;\n }\n const isDark = typeof document !== 'undefined'\n && document.documentElement.getAttribute('data-theme') === 'dark';\n return isDark ? 'dark' : 'default';\n }\n\n /**\n * Fetch the mermaid engine, on first use only.\n *\n * MEASURED BUNDLE DEFERRAL — this is deliberately a dynamic `import()`, NOT a top-level\n * one, and must not be \"tidied\" back into a static import. `mermaid` and the parsing /\n * graph engines it pulls with it (`@mermaid-js/parser`, `langium`, `chevrotain`,\n * `cytoscape`, `katex`, `d3`) were ~0.95 MB raw of every host's initial download even\n * when no document ever contained a diagram. That is a rounding error for an in-app\n * host and the whole cost for a CDN-loaded embedding of the realtime session overlay\n * (MJ #3882). Documents with no diagram now never fetch the chunk at all.\n *\n * The in-flight promise is cached so N diagrams in one document share one fetch; a\n * FAILED load clears it, so a later render can retry. Retries are bounded by\n * user-driven render calls — there is no loop here.\n */\n private async loadMermaid(): Promise<Mermaid> {\n if (this.mermaidEngine) {\n return this.mermaidEngine;\n }\n\n this.mermaidLoad ??= import('mermaid').then((module) => module.default);\n\n try {\n this.mermaidEngine = await this.mermaidLoad;\n return this.mermaidEngine;\n } catch (error) {\n this.mermaidLoad = null;\n throw error;\n }\n }\n\n /**\n * Initialize Mermaid with the current theme configuration.\n * Re-initializes when the effective theme changes.\n * @param mermaid The lazily-loaded mermaid engine (see {@link loadMermaid})\n */\n private initializeMermaid(mermaid: Mermaid): void {\n const effectiveTheme = this.resolveEffectiveMermaidTheme();\n\n if (this.mermaidInitialized && this.lastMermaidTheme === effectiveTheme) {\n return;\n }\n\n mermaid.initialize({\n startOnLoad: false,\n theme: effectiveTheme,\n securityLevel: 'strict',\n fontFamily: 'inherit',\n htmlLabels: false,\n flowchart: { htmlLabels: false },\n suppressErrorRendering: true // Suppress visual error diagrams - errors go to console only\n });\n\n this.mermaidInitialized = true;\n this.lastMermaidTheme = effectiveTheme;\n }\n\n /**\n * Render Mermaid diagrams in a container element\n * Call this after the HTML has been inserted into the DOM\n * @param container The DOM element containing mermaid code blocks\n */\n public async RenderMermaid(container: HTMLElement): Promise<boolean> {\n if (!this.currentConfig.enableMermaid) return false;\n\n // Find all mermaid code blocks BEFORE touching the engine — this is the branch the\n // deferral hangs off: no diagrams in this document means no chunk fetch at all.\n const mermaidBlocks = container.querySelectorAll('pre > code.language-mermaid, .mermaid');\n\n if (mermaidBlocks.length === 0) return false;\n\n let mermaid: Mermaid;\n try {\n mermaid = await this.loadMermaid();\n } catch (error) {\n // The chunk could not be fetched (offline, blocked host, bad deploy). Say so on\n // every block we were going to render — an empty panel would look like the diagram\n // simply wasn't there.\n console.error('Failed to load the Mermaid diagram engine:', error);\n this.markMermaidBlocksFailed(mermaidBlocks, 'Diagram engine failed to load');\n return false;\n }\n\n this.initializeMermaid(mermaid);\n\n for (let i = 0; i < mermaidBlocks.length; i++) {\n const block = mermaidBlocks[i];\n const code = block.textContent || '';\n\n if (!code.trim()) continue;\n\n try {\n // Create a unique ID for this diagram\n const id = `mermaid-${Date.now()}-${i}`;\n\n // Render the diagram\n const { svg } = await mermaid.render(id, code);\n\n // Sanitize rendered SVG with DOMPurify even under securityLevel: 'strict' (defense-in-depth)\n const purifierInstance = getPurifier();\n if (!purifierInstance) {\n this.markMermaidBlocksFailed([block], 'Diagram sanitization unavailable');\n continue;\n }\n const sanitizedSvg = purifierInstance.sanitize(svg, {\n USE_PROFILES: { svg: true, svgFilters: true },\n });\n\n // Replace the code block with the sanitized SVG\n const wrapper = document.createElement('div');\n wrapper.className = 'mermaid-diagram';\n wrapper.innerHTML = sanitizedSvg;\n\n // Replace the pre element (parent of code) or the mermaid element itself\n const elementToReplace = block.tagName === 'CODE' ? block.parentElement : block;\n elementToReplace?.parentNode?.replaceChild(wrapper, elementToReplace);\n } catch (error) {\n console.warn('Mermaid rendering failed:', error);\n // Show it failed on this block — the source stays visible underneath.\n this.markMermaidBlocksFailed([block], 'Diagram rendering failed');\n }\n }\n\n return true;\n }\n\n /** @deprecated Use {@link RenderMermaid}. */\n public async renderMermaid(container: HTMLElement): Promise<boolean> {\n return this.RenderMermaid(container);\n }\n\n /**\n * Fetch the KaTeX engine, on first use only. A dynamic `import()` under the \"genuine bundle-size\n * deferral\" allowance (typescript-style rules, category 3), like {@link loadMermaid}: KaTeX is\n * 277 KB minified (76 KB gzipped), and documents with no math never download it. A failed load\n * clears the cached promise so a later render can retry.\n */\n private async loadKatex(): Promise<typeof katex> {\n if (this.katexEngine) {\n return this.katexEngine;\n }\n\n this.katexLoad ??= import('katex').then((module) => module.default);\n\n try {\n this.katexEngine = await this.katexLoad;\n return this.katexEngine;\n } catch (error) {\n this.katexLoad = null;\n throw error;\n }\n }\n\n /**\n * Spell MathML's styled letters (`mathvariant=\"bold\"`, `\"double-struck\"`, ...) with their Unicode\n * math characters, which Chrome renders. `RenderMath` already does this; call it on its own when\n * math is off, because MathML that arrived as markup still renders then.\n *\n * @param container The DOM element containing the MathML\n */\n public UseUnicodeMathLetters(container: HTMLElement): void {\n useUnicodeMathLetters(container);\n }\n\n /**\n * Typeset TeX math in a container: every `code.mj-math` placeholder that markdown-core's\n * math extension emitted. Call this after the HTML has been inserted into the DOM. MathML that\n * arrived as markup is already rendered by the browser; it only gets the letter fix below.\n *\n * The output is MathML, which current browsers lay out natively, so hosts need no KaTeX\n * stylesheet or fonts. KaTeX builds the nodes itself from the TeX text (no HTML string is\n * parsed) and runs with `trust` off, so `\\href`, `\\url` and `\\includegraphics` stay inert.\n * A formula KaTeX cannot parse, one that defines macros, or an engine that fails to load leaves\n * the TeX source showing as code. User sizes are capped at 20em.\n *\n * Whether math is on is the caller's decision (`<mj-markdown>` checks its `EnableMath` input):\n * this service is a root singleton whose config the last-rendered component set, so it is no\n * guide to the container in hand. Without math enabled at parse time there are no placeholders.\n *\n * @param container The DOM element containing the math placeholders\n * @returns true if at least one TeX formula was typeset\n */\n public async RenderMath(container: HTMLElement): Promise<boolean> {\n // MathML that arrived as markup (a formula from a JATS article) needs the same Chrome fix as\n // KaTeX's output, and no engine.\n useUnicodeMathLetters(container);\n\n // Find the placeholders BEFORE touching the engine: no math, no chunk fetch.\n const placeholders = container.querySelectorAll<HTMLElement>('code.mj-math');\n if (placeholders.length === 0) return false;\n\n let engine: typeof katex;\n try {\n engine = await this.loadKatex();\n } catch (error) {\n console.error('Failed to load the KaTeX math engine:', error);\n return false;\n }\n\n let typeset = false;\n placeholders.forEach((placeholder) => {\n // A newer render (the next streamed chunk) replaced it while KaTeX was loading.\n if (!container.contains(placeholder)) return;\n const tex = placeholder.textContent ?? '';\n const target = document.createElement('span');\n try {\n if (TEX_MACRO_DEFINITION.test(tex)) {\n throw new Error('Formulas that define macros are not typeset');\n }\n engine.render(tex, target, {\n displayMode: placeholder.classList.contains('mj-math-display'),\n output: 'mathml',\n throwOnError: true,\n strict: 'ignore',\n maxSize: 20\n });\n useUnicodeMathLetters(target);\n placeholder.replaceWith(...Array.from(target.childNodes));\n typeset = true;\n } catch (error) {\n placeholder.classList.add('mj-math-error');\n placeholder.title = error instanceof Error ? error.message : 'This formula could not be typeset';\n }\n });\n\n return typeset;\n }\n\n /**\n * Mark mermaid blocks as un-renderable, so the failure is VISIBLE rather than a block of\n * raw diagram source the reader can't explain. The `.mermaid-error` class carries the\n * error styling and a default caption; `data-mermaid-error` overrides that caption with\n * the specific reason (see `.mermaid-error[data-mermaid-error]::before` in the component\n * stylesheet).\n *\n * @param blocks The mermaid code blocks (or `.mermaid` elements) that could not be rendered\n * @param message Short reason shown above the un-rendered source\n */\n private markMermaidBlocksFailed(blocks: ArrayLike<Element>, message: string): void {\n for (let i = 0; i < blocks.length; i++) {\n const block = blocks[i];\n const target = block.tagName === 'CODE' ? block.parentElement : block;\n target?.classList.add('mermaid-error');\n target?.setAttribute('data-mermaid-error', message);\n }\n }\n\n /**\n * Highlight code blocks with Prism\n * Call this after the HTML has been inserted into the DOM\n * @param container The DOM element containing code blocks\n */\n public HighlightCode(container: HTMLElement): void {\n if (!this.currentConfig.enableHighlight) return;\n\n // Prism.highlightAllUnder handles finding and highlighting code blocks\n Prism.highlightAllUnder(container);\n }\n\n /** @deprecated Use {@link HighlightCode}. */\n public highlightCode(container: HTMLElement): void {\n return this.HighlightCode(container);\n }\n\n /**\n * Add copy buttons to code blocks\n * @param container The DOM element containing code blocks\n */\n public AddCodeCopyButtons(container: HTMLElement): void {\n if (!this.currentConfig.enableCodeCopy) return;\n\n const codeBlocks = container.querySelectorAll('pre > code');\n\n codeBlocks.forEach((codeBlock) => {\n const pre = codeBlock.parentElement;\n if (!pre || pre.querySelector('.code-copy-btn')) return; // Already has button\n\n // Create copy button\n const button = document.createElement('button');\n button.className = 'code-copy-btn';\n button.innerHTML = '<i class=\"fas fa-copy\"></i>';\n button.title = 'Copy code';\n button.type = 'button';\n\n button.addEventListener('click', async () => {\n const code = codeBlock.textContent || '';\n\n try {\n await navigator.clipboard.writeText(code);\n button.innerHTML = '<i class=\"fas fa-check\"></i>';\n button.classList.add('copied');\n\n setTimeout(() => {\n button.innerHTML = '<i class=\"fas fa-copy\"></i>';\n button.classList.remove('copied');\n }, 2000);\n } catch (err) {\n console.error('Failed to copy code:', err);\n button.innerHTML = '<i class=\"fas fa-times\"></i>';\n\n setTimeout(() => {\n button.innerHTML = '<i class=\"fas fa-copy\"></i>';\n }, 2000);\n }\n });\n\n // Add toolbar wrapper\n const toolbar = document.createElement('div');\n toolbar.className = 'code-toolbar';\n toolbar.appendChild(button);\n\n // Make pre position relative for absolute positioning of toolbar\n pre.style.position = 'relative';\n pre.appendChild(toolbar);\n });\n }\n\n /** @deprecated Use {@link AddCodeCopyButtons}. */\n public addCodeCopyButtons(container: HTMLElement): void {\n return this.AddCodeCopyButtons(container);\n }\n\n /**\n * Initialize collapsible heading functionality\n * This method is a no-op - the component handles event binding\n * @param container The DOM element containing collapsible sections\n */\n public InitializeCollapsibleHeadings(_container: HTMLElement): void {\n // Event binding is handled by the component's setupCollapsibleListeners\n // This method exists for API compatibility but does nothing\n }\n\n /** @deprecated Use {@link InitializeCollapsibleHeadings}. */\n public initializeCollapsibleHeadings(_container: HTMLElement): void {\n return this.InitializeCollapsibleHeadings(_container);\n }\n\n /**\n * Get the list of headings from the last parsed document\n * Useful for building table of contents\n */\n public GetHeadingList(): HeadingInfo[] {\n return this.engine.getHeadingList();\n }\n\n /** @deprecated Use {@link GetHeadingList}. */\n public getHeadingList(): HeadingInfo[] {\n return this.GetHeadingList();\n }\n\n /**\n * Get the current configuration\n */\n public GetConfig(): ResolvedMarkdownConfig {\n return this.engine.getConfig();\n }\n\n /** @deprecated Use {@link GetConfig}. */\n public getConfig(): ResolvedMarkdownConfig {\n return this.GetConfig();\n }\n\n /**\n * Reset configuration to defaults\n */\n public ResetConfig(): void {\n this.ConfigureMarked(DEFAULT_MARKDOWN_CONFIG);\n }\n\n /** @deprecated Use {@link ResetConfig}. */\n public resetConfig(): void {\n return this.ResetConfig();\n }\n\n /**\n * Check if a language is supported by Prism\n */\n public IsLanguageSupported(lang: string): boolean {\n return !!Prism.languages[lang];\n }\n\n /** @deprecated Use {@link IsLanguageSupported}. */\n public isLanguageSupported(lang: string): boolean {\n return this.IsLanguageSupported(lang);\n }\n\n /**\n * Get list of supported Prism languages\n */\n public GetSupportedLanguages(): string[] {\n return Object.keys(Prism.languages).filter(\n lang => typeof Prism.languages[lang] === 'object'\n );\n }\n\n /** @deprecated Use {@link GetSupportedLanguages}. */\n public getSupportedLanguages(): string[] {\n return this.GetSupportedLanguages();\n }\n\n /**\n * Fix HTML that was incorrectly wrapped in <pre><code> blocks by marked.\n * This happens when marked interprets inline HTML (especially indented HTML)\n * as code blocks. We detect this by checking if the code block content\n * looks like valid HTML structure rather than actual code.\n *\n * Only processes code blocks WITHOUT a language class (e.g., language-javascript)\n * to avoid unwrapping intentional code examples.\n */\n private unwrapMiscodedHtml(html: string): string {\n // Quick check - if no pre tags, nothing to do\n if (!html.includes('<pre>')) {\n return html;\n }\n\n // Skip if SVG is present - DOMParser mangles SVG elements like <rect>\n // when parsing as 'text/html' due to namespace issues\n if (html.includes('<svg')) {\n return html;\n }\n\n try {\n const parser = new DOMParser();\n const doc = parser.parseFromString(`<div>${html}</div>`, 'text/html');\n const container = doc.body.firstChild as HTMLElement;\n\n if (!container) return html;\n\n // Find all pre > code elements WITHOUT a language class\n // Code blocks with language classes (language-javascript, etc.) are intentional\n const preElements = container.querySelectorAll('pre');\n let modified = false;\n\n for (const pre of Array.from(preElements)) {\n const code = pre.querySelector('code');\n if (!code) continue;\n\n // Skip if code has a language class - it's intentional code\n const hasLanguageClass = code.className && /language-\\w+/.test(code.className);\n if (hasLanguageClass) continue;\n\n // Get the text content (this is HTML-decoded by the browser)\n const content = code.textContent?.trim() || '';\n\n // Check if this looks like HTML that was incorrectly wrapped\n if (this.looksLikeStructuralHtml(content)) {\n // Verify it parses as valid HTML with actual elements\n const testDoc = parser.parseFromString(content, 'text/html');\n const hasStructure = testDoc.body.children.length > 0 ||\n (testDoc.body.innerHTML.trim().length > 0 &&\n testDoc.body.innerHTML.includes('<'));\n\n if (hasStructure) {\n // Replace the <pre> with the actual HTML content. The nodes are built inside a\n // <template> of the inert DOMParser document, never on the live `document`:\n // setting innerHTML on a live element fires image error handlers at parse time,\n // before the sanitizer in parse() has seen the markup. A <template> also parses\n // in body context, so a mockup that starts with <style> keeps it (a full-document\n // parse would hoist it into <head> and drop it).\n const template = doc.createElement('template');\n template.innerHTML = content;\n pre.replaceWith(template.content);\n modified = true;\n }\n }\n }\n\n if (modified) {\n return container.innerHTML;\n }\n } catch (error) {\n console.warn('Error in unwrapMiscodedHtml:', error);\n }\n\n return html;\n }\n\n /**\n * Check if content looks like structural HTML that was incorrectly\n * wrapped in a code block. We look for common HTML element patterns\n * that indicate this is meant to be rendered HTML, not code.\n */\n private looksLikeStructuralHtml(content: string): boolean {\n // Must start with < to be HTML\n if (!content.startsWith('<')) return false;\n\n // Must end with > (closing tag)\n if (!content.endsWith('>')) return false;\n\n // Check for common structural HTML tags that indicate layout HTML\n // These are tags that would typically appear in a UI mockup/prototype\n const structuralTagPattern = /<(div|span|table|tr|td|th|thead|tbody|p|ul|ol|li|section|article|header|footer|nav|main|aside|form|input|button|label|select|option|textarea|h[1-6]|img|a|strong|em|b|i|br|hr)\\b/i;\n\n if (!structuralTagPattern.test(content)) return false;\n\n // Additional check: should have multiple tags or nested structure\n // Single self-closing tags like <br> or <img> shouldn't trigger unwrapping\n const tagCount = (content.match(/<\\w+/g) || []).length;\n if (tagCount < 2) return false;\n\n // Check it's not just showing HTML as an example (common in docs)\n // If content has lots of &lt; or &gt; it's probably escaped HTML being shown\n if (content.includes('&lt;') || content.includes('&gt;')) return false;\n\n return true;\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-markdown",
3
- "version": "6.3.0-edge.0",
3
+ "version": "6.3.0-edge.1",
4
4
  "description": "MemberJunction: Lightweight Angular markdown component with Prism.js highlighting, Mermaid diagrams, and extensible features",
5
5
  "main": "./dist/public-api.js",
6
6
  "typings": "./dist/public-api.d.ts",
@@ -20,7 +20,7 @@
20
20
  "devDependencies": {
21
21
  "@angular/compiler": "21.2.22",
22
22
  "@angular/compiler-cli": "21.2.22",
23
- "@memberjunction/ng-test-utils": "6.3.0-edge.0",
23
+ "@memberjunction/ng-test-utils": "6.3.0-edge.1",
24
24
  "jsdom": "^26.1.0",
25
25
  "vitest": "^4.0.18"
26
26
  },
@@ -30,8 +30,8 @@
30
30
  "@angular/platform-browser": "^21.2.22"
31
31
  },
32
32
  "dependencies": {
33
- "@memberjunction/ai-diagrams": "6.3.0-edge.0",
34
- "@memberjunction/markdown-core": "6.3.0-edge.0",
33
+ "@memberjunction/ai-diagrams": "6.3.0-edge.1",
34
+ "@memberjunction/markdown-core": "6.3.0-edge.1",
35
35
  "dompurify": "^3.3.0",
36
36
  "katex": "^0.16.28",
37
37
  "mermaid": "^11.12.2",