See [[machine-learning-basics]] for more.
') postprocessWikilinks(root, (raw) => resolveWikilink(raw, REFS, ARCHIVED_REFS)) const a = root.querySelector('a.wiki-link') as HTMLAnchorElement expect(a).not.toBeNull() expect(a.getAttribute('data-slug')).toBe('machine-learning-basics') expect(a.textContent).toBe('机器学习基础') expect(a.getAttribute('href')).toBeNull() }) it('replaces an archived hit into ', () => { const root = setup('See [[deprecated-concept]].
') postprocessWikilinks(root, (raw) => resolveWikilink(raw, REFS, ARCHIVED_REFS)) const a = root.querySelector('a.wiki-link.wiki-link-archived') as HTMLAnchorElement expect(a).not.toBeNull() expect(a.getAttribute('data-slug')).toBe('deprecated-concept') expect(a.getAttribute('title')).toBe('Archived page') }) it('replaces a miss into with no clickable surface', () => { const root = setup('See [[unknown-page]] sometime.
') postprocessWikilinks(root, (raw) => resolveWikilink(raw, REFS, ARCHIVED_REFS)) const span = root.querySelector('span.wiki-link-broken') as HTMLSpanElement expect(span).not.toBeNull() expect(root.querySelector('a')).toBeNull() // Display falls back to the literal [[...]] so the malformed source is // visible to the reader. expect(span.textContent).toBe('[[unknown-page]]') }) it('does not interpolate dangerous raw into attributes', () => { // The realistic vector: a text node carries the literal `]] stay safe.' root.appendChild(p) expect(root.querySelector('script')).toBeNull() // sanity — text-node form postprocessWikilinks(root, (raw) => resolveWikilink(raw, REFS, ARCHIVED_REFS)) expect(root.querySelector('script')).toBeNull() expect(root.querySelector('a')).toBeNull() const span = root.querySelector('span.wiki-link-broken') as HTMLSpanElement expect(span).not.toBeNull() // The attribute carrying user data is the title; verify it's the rejection // reason, not the raw payload. expect(span.getAttribute('title')).toMatch(/dangerous/) // Visible label is the literal [[...]] — readers see the malformed source // verbatim instead of having it silently swallowed. expect(span.textContent).toContain('