---
/**
* A short description from a data file, rendered inline (PLAN.md ยง16, phase 16).
*
* Reference data in `src/data/` is plain strings, because a check reads the same file. Three
* inline marks are understood, and nothing else: `code`, **bold**, and [a link](/path/). The
* text is never parsed as HTML, so a description cannot inject markup.
*/
interface Props {
text: string;
}
const { text } = Astro.props;
type Token = { kind: 'text' | 'code' | 'strong'; value: string } | { kind: 'link'; value: string; href: string };
const tokens: Token[] = [];
const pattern = /`([^`]+)`|\*\*([^*]+)\*\*|\[([^\]]+)\]\(([^)\s]+)\)/g;
let last = 0;
for (const m of String(text ?? '').matchAll(pattern)) {
if (m.index > last) tokens.push({ kind: 'text', value: text.slice(last, m.index) });
if (m[1] !== undefined) tokens.push({ kind: 'code', value: m[1] });
else if (m[2] !== undefined) tokens.push({ kind: 'strong', value: m[2] });
else tokens.push({ kind: 'link', value: m[3], href: m[4] });
last = m.index + m[0].length;
}
if (last < text.length) tokens.push({ kind: 'text', value: text.slice(last) });
---
{tokens.map((t) =>
t.kind === 'code' ? {t.value}
: t.kind === 'strong' ? {t.value}
: t.kind === 'link' ? {t.value}
: t.value
)}