@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.
- package/dist/__tests__/mermaid-svg-sanitize.test.d.ts +2 -0
- package/dist/__tests__/mermaid-svg-sanitize.test.d.ts.map +1 -0
- package/dist/__tests__/mermaid-svg-sanitize.test.js +42 -0
- package/dist/__tests__/mermaid-svg-sanitize.test.js.map +1 -0
- package/dist/lib/components/markdown.component.d.ts +29 -0
- package/dist/lib/components/markdown.component.d.ts.map +1 -1
- package/dist/lib/components/markdown.component.dom.test.js +139 -0
- package/dist/lib/components/markdown.component.dom.test.js.map +1 -1
- package/dist/lib/components/markdown.component.js +358 -39
- package/dist/lib/components/markdown.component.js.map +1 -1
- package/dist/lib/services/markdown.service.d.ts +13 -1
- package/dist/lib/services/markdown.service.d.ts.map +1 -1
- package/dist/lib/services/markdown.service.dom.test.js +41 -0
- package/dist/lib/services/markdown.service.dom.test.js.map +1 -1
- package/dist/lib/services/markdown.service.js +69 -4
- package/dist/lib/services/markdown.service.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-svg-sanitize.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/mermaid-svg-sanitize.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from 'vitest';
|
|
2
|
+
import { MarkdownService } from '../lib/services/markdown.service';
|
|
3
|
+
describe('MarkdownService.RenderMermaid (S11 SVG sanitization & htmlLabels:false)', () => {
|
|
4
|
+
afterEach(() => {
|
|
5
|
+
document.body.innerHTML = '';
|
|
6
|
+
vi.restoreAllMocks();
|
|
7
|
+
});
|
|
8
|
+
it('configures mermaid with htmlLabels: false, preserves SVG flowchart text labels, and strips XSS payloads', async () => {
|
|
9
|
+
const service = new MarkdownService();
|
|
10
|
+
const container = document.createElement('div');
|
|
11
|
+
container.innerHTML = '<pre><code class="language-mermaid">flowchart TD\nA[Start] --> B[End]</code></pre>';
|
|
12
|
+
document.body.appendChild(container);
|
|
13
|
+
const initSpy = vi.fn();
|
|
14
|
+
const renderSpy = vi.fn(async () => ({
|
|
15
|
+
svg: '<svg viewBox="0 0 200 100" xmlns="http://www.w3.org/2000/svg">' +
|
|
16
|
+
'<g class="node"><rect width="80" height="30" onload="alert(1)"/>' +
|
|
17
|
+
'<text x="40" y="20">Quarterly Revenue</text></g>' +
|
|
18
|
+
'<foreignObject><div xmlns="http://www.w3.org/1999/xhtml"><script>alert(2)</script>UnsafeHtml</div></foreignObject>' +
|
|
19
|
+
'<script>alert(3)</script>' +
|
|
20
|
+
'</svg>',
|
|
21
|
+
}));
|
|
22
|
+
// Inject stub mermaid engine through internal cached property cleanly
|
|
23
|
+
Reflect.set(service, 'mermaidEngine', {
|
|
24
|
+
initialize: initSpy,
|
|
25
|
+
render: renderSpy,
|
|
26
|
+
});
|
|
27
|
+
const rendered = await service.RenderMermaid(container);
|
|
28
|
+
expect(rendered).toBe(true);
|
|
29
|
+
expect(initSpy).toHaveBeenCalledWith(expect.objectContaining({
|
|
30
|
+
securityLevel: 'strict',
|
|
31
|
+
htmlLabels: false,
|
|
32
|
+
flowchart: { htmlLabels: false },
|
|
33
|
+
}));
|
|
34
|
+
const renderedSvg = container.querySelector('.mermaid-diagram svg');
|
|
35
|
+
expect(renderedSvg).not.toBeNull();
|
|
36
|
+
expect(renderedSvg?.textContent).toContain('Quarterly Revenue');
|
|
37
|
+
expect(container.querySelector('script')).toBeNull();
|
|
38
|
+
expect(container.querySelector('foreignObject')).toBeNull();
|
|
39
|
+
expect(renderedSvg?.querySelector('rect')?.hasAttribute('onload')).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=mermaid-svg-sanitize.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-svg-sanitize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,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAChC,MAAM,CAAC,gBAAgB,CAAC;YACpB,aAAa,EAAE,QAAQ;YACvB,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;SACnC,CAAC,CACL,CAAC;QAEF,MAAM,WAAW,GAAG,SAAS,CAAC,aAAa,CAAC,sBAAsB,CAAC,CAAC;QACpE,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QACnC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QAChE,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QACrD,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC5D,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expect, vi, afterEach } from 'vitest';\nimport { MarkdownService } from '../lib/services/markdown.service';\n\ndescribe('MarkdownService.RenderMermaid (S11 SVG sanitization & htmlLabels:false)', () => {\n afterEach(() => {\n document.body.innerHTML = '';\n vi.restoreAllMocks();\n });\n\n it('configures mermaid with htmlLabels: false, preserves SVG flowchart text labels, and strips XSS payloads', async () => {\n const service = new MarkdownService();\n const container = document.createElement('div');\n container.innerHTML = '<pre><code class=\"language-mermaid\">flowchart TD\\nA[Start] --> B[End]</code></pre>';\n document.body.appendChild(container);\n\n const initSpy = vi.fn();\n const renderSpy = vi.fn(async () => ({\n svg:\n '<svg viewBox=\"0 0 200 100\" xmlns=\"http://www.w3.org/2000/svg\">' +\n '<g class=\"node\"><rect width=\"80\" height=\"30\" onload=\"alert(1)\"/>' +\n '<text x=\"40\" y=\"20\">Quarterly Revenue</text></g>' +\n '<foreignObject><div xmlns=\"http://www.w3.org/1999/xhtml\"><script>alert(2)</script>UnsafeHtml</div></foreignObject>' +\n '<script>alert(3)</script>' +\n '</svg>',\n }));\n\n // Inject stub mermaid engine through internal cached property cleanly\n Reflect.set(service, 'mermaidEngine', {\n initialize: initSpy,\n render: renderSpy,\n });\n\n const rendered = await service.RenderMermaid(container);\n expect(rendered).toBe(true);\n expect(initSpy).toHaveBeenCalledWith(\n expect.objectContaining({\n securityLevel: 'strict',\n htmlLabels: false,\n flowchart: { htmlLabels: false },\n }),\n );\n\n const renderedSvg = container.querySelector('.mermaid-diagram svg');\n expect(renderedSvg).not.toBeNull();\n expect(renderedSvg?.textContent).toContain('Quarterly Revenue');\n expect(container.querySelector('script')).toBeNull();\n expect(container.querySelector('foreignObject')).toBeNull();\n expect(renderedSvg?.querySelector('rect')?.hasAttribute('onload')).toBe(false);\n });\n});\n"]}
|
|
@@ -282,15 +282,44 @@ export declare class MarkdownComponent implements OnChanges, AfterViewInit, OnDe
|
|
|
282
282
|
private diagramViewers;
|
|
283
283
|
private renderSeq;
|
|
284
284
|
private isDestroyed;
|
|
285
|
+
private lastRenderedMarkdown;
|
|
286
|
+
private committedPrefixMarkdown;
|
|
287
|
+
private committedPrefixHtml;
|
|
288
|
+
private committedPrefixNodeCount;
|
|
289
|
+
private tailNodeCount;
|
|
290
|
+
private prefixHeadingList;
|
|
291
|
+
private prefixHeadingTexts;
|
|
292
|
+
private currentHeadingList;
|
|
293
|
+
private streamingFallbackForced;
|
|
294
|
+
private containerElement;
|
|
295
|
+
private pendingRenderMarkdown;
|
|
285
296
|
constructor(elementRef: ElementRef<HTMLElement>, sanitizer: DomSanitizer, markdownService: MarkdownService, cdr: ChangeDetectorRef);
|
|
286
297
|
ngOnChanges(changes: SimpleChanges): void;
|
|
287
298
|
ngAfterViewInit(): void;
|
|
288
299
|
ngOnDestroy(): void;
|
|
289
300
|
private destroyDiagramViewers;
|
|
301
|
+
private getContainer;
|
|
302
|
+
private resetStreamingState;
|
|
303
|
+
private buildConfig;
|
|
304
|
+
private prepareHtml;
|
|
305
|
+
private updateContentFlags;
|
|
306
|
+
/**
|
|
307
|
+
* Linear O(N) non-regex detector for whole-document Markdown cross-references:
|
|
308
|
+
* - Reference-style link definitions: `[id]: url`
|
|
309
|
+
* - Footnote definitions: `[^id]:`
|
|
310
|
+
* - Table-of-contents directives: `[toc]` or `[[toc]]`
|
|
311
|
+
*
|
|
312
|
+
* Uses pure string scanning with zero regular expressions to avoid polynomial backtracking (ReDoS).
|
|
313
|
+
*/
|
|
314
|
+
private hasWholeDocCrossRef;
|
|
315
|
+
private canStreamAppend;
|
|
316
|
+
private hasDuplicateHeadingsAgainstPrefix;
|
|
290
317
|
/**
|
|
291
318
|
* Render the markdown content
|
|
292
319
|
*/
|
|
293
320
|
private render;
|
|
321
|
+
private renderFull;
|
|
322
|
+
private renderIncremental;
|
|
294
323
|
/**
|
|
295
324
|
* Process rendered content after DOM update
|
|
296
325
|
* Handles syntax highlighting, mermaid rendering, interactive MJ diagrams, copy buttons, etc.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/markdown.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,aAAa,EAIb,iBAAiB,EACjB,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAA2C,mBAAmB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;;AAG1H,gGAAgG;AAChG,qBAAa,qBAAqB;IAE9B,iDAAiD;aACjC,GAAG,EAAE,MAAM;IAC3B,yCAAyC;aACzB,GAAG,EAAE,MAAM;;IAH3B,iDAAiD;IACjC,GAAG,EAAE,MAAM;IAC3B,yCAAyC;IACzB,GAAG,EAAE,MAAM;CAE9B;AA0BD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAQa,iBAAkB,YAAW,SAAS,EAAE,aAAa,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"markdown.component.d.ts","sourceRoot":"","sources":["../../../src/lib/components/markdown.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,EACZ,UAAU,EACV,SAAS,EACT,SAAS,EACT,aAAa,EAIb,iBAAiB,EACjB,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAA2C,mBAAmB,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;;AAG1H,gGAAgG;AAChG,qBAAa,qBAAqB;IAE9B,iDAAiD;aACjC,GAAG,EAAE,MAAM;IAC3B,yCAAyC;aACzB,GAAG,EAAE,MAAM;;IAH3B,iDAAiD;IACjC,GAAG,EAAE,MAAM;IAC3B,yCAAyC;IACzB,GAAG,EAAE,MAAM;CAE9B;AA0BD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAQa,iBAAkB,YAAW,SAAS,EAAE,aAAa,EAAE,SAAS;IAuYzE,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,GAAG;IAzYb;;OAEG;IACM,IAAI,EAAE,MAAM,CAAM;IAE3B,oCAAoC;IACpC,IAAa,IAAI,CAAC,KAAK,EAAE,MAAM,EAE9B;IACD,oCAAoC;IACpC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACM,eAAe,EAAE,OAAO,CAA2C;IAE5E,+CAA+C;IAC/C,IAAa,eAA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
|
|
552
552
|
});
|
|
553
|
+
describe('incremental block-tail streaming rendering', () => {
|
|
554
|
+
it('monotonic streaming append reuses cached prefix DOM nodes without tearing down completed elements', () => {
|
|
555
|
+
const f = render({ data: '# Title\n\nParagraph 1' });
|
|
556
|
+
const c = container(f);
|
|
557
|
+
const h1Ref = c.querySelector('h1');
|
|
558
|
+
expect(h1Ref).not.toBeNull();
|
|
559
|
+
expect(h1Ref?.textContent).toContain('Title');
|
|
560
|
+
// Append Paragraph 2: Paragraph 1 graduates into the stable prefix
|
|
561
|
+
f.componentRef.setInput('data', '# Title\n\nParagraph 1\n\nParagraph 2');
|
|
562
|
+
f.detectChanges();
|
|
563
|
+
expect(c.querySelector('h1')).toBe(h1Ref); // Title h1 strictly === identical across chunks
|
|
564
|
+
const p1Ref = c.querySelectorAll('p')[0];
|
|
565
|
+
expect(p1Ref).not.toBeNull();
|
|
566
|
+
expect(p1Ref.textContent).toContain('Paragraph 1');
|
|
567
|
+
expect(c.querySelectorAll('p')[1]?.textContent).toContain('Paragraph 2');
|
|
568
|
+
// Append more text to Paragraph 2 (updating active mutable tail)
|
|
569
|
+
f.componentRef.setInput('data', '# Title\n\nParagraph 1\n\nParagraph 2 is still streaming...');
|
|
570
|
+
f.detectChanges();
|
|
571
|
+
expect(c.querySelector('h1')).toBe(h1Ref); // Title h1 still strictly === identical
|
|
572
|
+
expect(c.querySelectorAll('p')[0]).toBe(p1Ref); // Paragraph 1 still strictly === identical
|
|
573
|
+
expect(c.querySelectorAll('p')[1]?.textContent).toContain('Paragraph 2 is still streaming');
|
|
574
|
+
// Append code block: Paragraph 2 graduates into stable prefix
|
|
575
|
+
f.componentRef.setInput('data', '# Title\n\nParagraph 1\n\nParagraph 2 is still streaming...\n\n```ts\nconst x = 1;\n```');
|
|
576
|
+
f.detectChanges();
|
|
577
|
+
expect(c.querySelector('h1')).toBe(h1Ref); // Still strictly === identical
|
|
578
|
+
expect(c.querySelectorAll('p')[0]).toBe(p1Ref); // Still strictly === identical
|
|
579
|
+
const p2Ref = c.querySelectorAll('p')[1];
|
|
580
|
+
expect(c.querySelector('pre code')?.textContent).toContain('const x = 1;');
|
|
581
|
+
// Append trailing conclusion: Code block graduates into stable prefix
|
|
582
|
+
f.componentRef.setInput('data', '# Title\n\nParagraph 1\n\nParagraph 2 is still streaming...\n\n```ts\nconst x = 1;\n```\n\nConclusion');
|
|
583
|
+
f.detectChanges();
|
|
584
|
+
expect(c.querySelector('h1')).toBe(h1Ref); // Title h1 strictly === identical
|
|
585
|
+
expect(c.querySelectorAll('p')[0]).toBe(p1Ref); // Paragraph 1 strictly === identical
|
|
586
|
+
expect(c.querySelectorAll('p')[1]).toBe(p2Ref); // Paragraph 2 strictly === identical
|
|
587
|
+
const preRef = c.querySelector('pre');
|
|
588
|
+
expect(preRef).not.toBeNull();
|
|
589
|
+
expect(c.querySelectorAll('p')[2]?.textContent).toContain('Conclusion');
|
|
590
|
+
// Stream more tokens into conclusion: Pre/code block stays strictly === identical
|
|
591
|
+
f.componentRef.setInput('data', '# Title\n\nParagraph 1\n\nParagraph 2 is still streaming...\n\n```ts\nconst x = 1;\n```\n\nConclusion is continuing to stream.');
|
|
592
|
+
f.detectChanges();
|
|
593
|
+
expect(c.querySelector('h1')).toBe(h1Ref); // Title h1 strictly === identical
|
|
594
|
+
expect(c.querySelectorAll('p')[0]).toBe(p1Ref); // Paragraph 1 strictly === identical
|
|
595
|
+
expect(c.querySelectorAll('p')[1]).toBe(p2Ref); // Paragraph 2 strictly === identical
|
|
596
|
+
expect(c.querySelector('pre')).toBe(preRef); // Pre/code block strictly === identical
|
|
597
|
+
expect(c.querySelectorAll('p')[2]?.textContent).toContain('Conclusion is continuing to stream');
|
|
598
|
+
});
|
|
599
|
+
it('open fenced code blocks across multiple chunks render accurately without premature splitting on blank lines inside the fence', () => {
|
|
600
|
+
const f = render({ data: '# Section\n\nIntroduction text.' });
|
|
601
|
+
const c = container(f);
|
|
602
|
+
const h1Ref = c.querySelector('h1');
|
|
603
|
+
// Chunk 1: Open fence with initial line
|
|
604
|
+
f.componentRef.setInput('data', '# Section\n\nIntroduction text.\n\n```ts\nconst a = 1;');
|
|
605
|
+
f.detectChanges();
|
|
606
|
+
expect(c.querySelector('h1')).toBe(h1Ref);
|
|
607
|
+
const pIntroRef = c.querySelector('p');
|
|
608
|
+
expect(pIntroRef).not.toBeNull();
|
|
609
|
+
expect(c.querySelectorAll('pre code').length).toBe(1);
|
|
610
|
+
expect(c.querySelector('pre code')?.textContent?.trim()).toBe('const a = 1;');
|
|
611
|
+
// Chunk 2: Blank line inside the open code block followed by another line
|
|
612
|
+
f.componentRef.setInput('data', '# Section\n\nIntroduction text.\n\n```ts\nconst a = 1;\n\nconst b = 2;');
|
|
613
|
+
f.detectChanges();
|
|
614
|
+
expect(c.querySelector('h1')).toBe(h1Ref);
|
|
615
|
+
expect(c.querySelector('p')).toBe(pIntroRef); // Intro paragraph stays strictly === identical
|
|
616
|
+
expect(c.querySelectorAll('pre code').length).toBe(1);
|
|
617
|
+
expect(c.querySelector('pre code')?.textContent?.trim()).toBe('const a = 1;\n\nconst b = 2;');
|
|
618
|
+
// Chunk 3: Closing the fence and appending trailing prose
|
|
619
|
+
f.componentRef.setInput('data', '# Section\n\nIntroduction text.\n\n```ts\nconst a = 1;\n\nconst b = 2;\n```\n\nTrailing paragraph.');
|
|
620
|
+
f.detectChanges();
|
|
621
|
+
expect(c.querySelector('h1')).toBe(h1Ref);
|
|
622
|
+
expect(c.querySelector('p')).toBe(pIntroRef); // Still strictly === identical
|
|
623
|
+
expect(c.querySelectorAll('pre code').length).toBe(1);
|
|
624
|
+
expect(c.querySelector('pre code')?.textContent?.trim()).toBe('const a = 1;\n\nconst b = 2;');
|
|
625
|
+
expect(c.querySelectorAll('p').length).toBe(2);
|
|
626
|
+
expect(c.querySelectorAll('p')[1]?.textContent).toContain('Trailing paragraph.');
|
|
627
|
+
});
|
|
628
|
+
it('reference-style links arriving in a later chunk seamlessly fall back to full render so links resolve correctly', () => {
|
|
629
|
+
const f = render({ data: 'Read the [documentation][docs] for setup.\n\nMore info here.' });
|
|
630
|
+
const c = container(f);
|
|
631
|
+
// Initially, [docs] is undefined, so marked leaves it as literal text
|
|
632
|
+
expect(c.querySelector('a')).toBeNull();
|
|
633
|
+
expect(c.textContent).toContain('[documentation][docs]');
|
|
634
|
+
// Later chunk introduces the reference link definition
|
|
635
|
+
f.componentRef.setInput('data', 'Read the [documentation][docs] for setup.\n\nMore info here.\n\n[docs]: https://example.com/docs');
|
|
636
|
+
f.detectChanges();
|
|
637
|
+
// Full render fallback resolves the link
|
|
638
|
+
const link = c.querySelector('a');
|
|
639
|
+
expect(link).not.toBeNull();
|
|
640
|
+
expect(link?.getAttribute('href')).toBe('https://example.com/docs');
|
|
641
|
+
expect(link?.textContent).toBe('documentation');
|
|
642
|
+
});
|
|
643
|
+
it('non-monotonic text replacement seamlessly falls back to full render', () => {
|
|
644
|
+
const f = render({ data: '# Original Document\n\nFirst paragraph here.' });
|
|
645
|
+
const c = container(f);
|
|
646
|
+
expect(c.querySelector('h1')?.textContent).toContain('Original Document');
|
|
647
|
+
// Completely replaced content (not monotonic prefix extension)
|
|
648
|
+
f.componentRef.setInput('data', '# Replaced Document\n\nCompletely different content.');
|
|
649
|
+
f.detectChanges();
|
|
650
|
+
expect(c.querySelector('h1')?.textContent).toContain('Replaced Document');
|
|
651
|
+
expect(c.querySelector('p')?.textContent).toContain('Completely different content.');
|
|
652
|
+
expect(c.textContent).not.toContain('Original Document');
|
|
653
|
+
});
|
|
654
|
+
it('duplicate headings seamlessly fall back to full render to preserve unique ID slug suffixes', () => {
|
|
655
|
+
const f = render({ data: '# Overview\n\nInitial overview.' });
|
|
656
|
+
const c = container(f);
|
|
657
|
+
expect(c.querySelector('h1')?.id).toBe('overview');
|
|
658
|
+
// Appending a second heading with the exact same name
|
|
659
|
+
f.componentRef.setInput('data', '# Overview\n\nInitial overview.\n\n# Overview\n\nSecond overview.');
|
|
660
|
+
f.detectChanges();
|
|
661
|
+
const headings = c.querySelectorAll('h1');
|
|
662
|
+
expect(headings.length).toBe(2);
|
|
663
|
+
expect(headings[0].id).toBe('overview');
|
|
664
|
+
expect(headings[1].id).toBe('overview-1');
|
|
665
|
+
});
|
|
666
|
+
it('produces 100% identical HTML output to full render across multi-element streamed documents', async () => {
|
|
667
|
+
const chunks = [
|
|
668
|
+
'# Main Title\n\nFirst paragraph introduces the topic.',
|
|
669
|
+
'# Main Title\n\nFirst paragraph introduces the topic.\n\n## Subheading\n\n- item 1\n- item 2',
|
|
670
|
+
'# Main Title\n\nFirst paragraph introduces the topic.\n\n## Subheading\n\n- item 1\n- item 2\n\n> A thoughtful quote.\n>\n> Second line of quote.',
|
|
671
|
+
'# Main Title\n\nFirst paragraph introduces the topic.\n\n## Subheading\n\n- item 1\n- item 2\n\n> A thoughtful quote.\n>\n> Second line of quote.\n\n```javascript\nfunction test() {\n return 42;\n}\n```',
|
|
672
|
+
'# Main Title\n\nFirst paragraph introduces the topic.\n\n## Subheading\n\n- item 1\n- item 2\n\n> A thoughtful quote.\n>\n> Second line of quote.\n\n```javascript\nfunction test() {\n return 42;\n}\n```\n\nFinal conclusion paragraph.',
|
|
673
|
+
];
|
|
674
|
+
// Stream sequentially through chunks
|
|
675
|
+
const streamFixture = render({ data: chunks[0] });
|
|
676
|
+
for (let i = 1; i < chunks.length; i++) {
|
|
677
|
+
streamFixture.componentRef.setInput('data', chunks[i]);
|
|
678
|
+
streamFixture.detectChanges();
|
|
679
|
+
}
|
|
680
|
+
// Flush microtasks for postRenderProcessing
|
|
681
|
+
await Promise.resolve();
|
|
682
|
+
await Promise.resolve();
|
|
683
|
+
// One-shot full render of the final text using a second component instance
|
|
684
|
+
const fullFixture = TestBed.createComponent(MarkdownComponent);
|
|
685
|
+
fullFixture.componentRef.setInput('data', chunks[chunks.length - 1]);
|
|
686
|
+
fullFixture.detectChanges();
|
|
687
|
+
await Promise.resolve();
|
|
688
|
+
await Promise.resolve();
|
|
689
|
+
expect(container(streamFixture).innerHTML.trim()).toBe(container(fullFixture).innerHTML.trim());
|
|
690
|
+
});
|
|
691
|
+
});
|
|
553
692
|
});
|
|
554
693
|
//# sourceMappingURL=markdown.component.dom.test.js.map
|