linkStrings
Highlighted code (highlight's) with the strings targets names made links to them, as references are
(linkRefs): a manifest's names and files.
import { esc } from "#codebase/tcmts/cli/pages"; import { codeHref } from "#codebase/tcmts/share"; export function linkStrings(html: string, targets: Map<string, string>): string { const plain = (s: string) => s .replace(/"/g, '"') .replace(/'/g, "'") .replace(/</g, "<") .replace(/>/g, ">") .replace(/&/g, "&"); return html.replace( /<span class="s">((?:"|'|")([^<]*?)(?:"|'|"))<\/span>/g, (all, quoted: string, inner: string) => { const name = targets.get(plain(inner)); return name ? `<a class="ref s" href="${codeHref(name)}" title="${esc(name)}">${quoted}</a>` : all; }, ); }