testCodeLinksInPages
A page's {@link} to a definition is a link to its page in the code browser on the static site (shown as code in the app), with its own text if it gives one; one written in code stays as it's written
import { highlighter, pageAt, pageList, renderPage, SOURCES } from "#codebase/tcmts/site"; import assert from "node:assert/strict"; export const testCodeLinksInPages = async () => { const pages = pageList(SOURCES["docs/README.md"]!); const page = pages.find((p) => p.src === "docs/claims.md")!; const md = "Proved by {@linkcode tcmts.cli.test.e2e.prod.testA}, {@link tcmts.lib.square the square}; written: `{@link square}`."; const hl = await highlighter(); const html = renderPage(page, pages, md, hl, () => true, false).html; assert.match( html, /<a href="code\/tcm\/cli\/test\/e2e\/prod\/testA\.html" rel="external" title="tcmts\.cli\.test\.e2e\.prod\.testA"><code>testA<\/code><\/a>/, ); assert.match( html, /<a href="code\/tcm\/lib\/square\.html" rel="external" title="tcmts\.lib\.square">the square<\/a>/, ); assert.match(html, /<code>\{@link square\}<\/code>/, "in code, as written"); assert.match( renderPage(page, pages, md, hl, () => true, true).html, /Proved by <code>testA<\/code>, the square;/, "the app: code, no link", ); assert.match( renderPage(page, pages, md, hl, () => true, true, true).html, /<a href="code\/tcm\/lib\/square\.html" rel="external"/, "the app on the published site, beside its code browser", ); // the app's pages: the index, and each page with or without .html; nothing else is the app's assert.equal(pageAt("/", pages)?.file, "index.html"); assert.equal(pageAt("/claims", pages)?.file, "claims.html"); assert.equal(pageAt("/claims.html", pages)?.file, "claims.html"); assert.equal(pageAt("/code/tcm/index.html", pages), undefined); assert.equal(pageAt("/examples/reminders/", pages), undefined); assert.equal(pageAt("/nowhere", pages), undefined); }