import React from "react";
// ---------------------------------------------------------------------------
// A deliberately small Markdown renderer, for the per-song README.md.
//
// Not a general one, and it should not grow into one. It covers exactly what
// the READMEs in this tree use -- headings, pipe tables, bullets, fenced code,
// and inline `code`/**bold**/*em* -- because those files are the only
// documentation of how each song was built, and a table shown as monospace
// text throws away the thing that makes them worth reading.
//
// Output is React nodes, never dangerouslySetInnerHTML. The input is a file on
// a local disk rather than anything hostile, but building a habit of returning
// escaped nodes costs nothing here and means a README copied in from elsewhere
// can never inject markup.
// ---------------------------------------------------------------------------
const INLINE = /(`[^`]+`|\*\*[^*]+\*\*|\*[^*]+\*|\[[^\]]+\]\([^)]+\))/g;
function inline(text: string, keyBase: string): React.ReactNode[] {
return text.split(INLINE).filter(Boolean).map((tok, i) => {
const key = `${keyBase}-${i}`;
if (tok.startsWith("`") && tok.endsWith("`") && tok.length > 1) {
return (
{tok.slice(1, -1)}
);
}
if (tok.startsWith("**") && tok.endsWith("**")) {
return (
{tok.slice(2, -2)}
);
}
if (tok.startsWith("*") && tok.endsWith("*") && tok.length > 2) {
return {tok.slice(1, -1)};
}
const link = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(tok);
if (link) {
// Relative links point at sibling files on disk, which this app does not
// serve -- render them as plain text rather than as a dead link.
const [, label, href] = link;
return /^https?:\/\//.test(href) ? (
{label}
) : (
{label}
);
}
return
{body.join("\n")}
,
);
continue;
}
const h = /^(#{1,4})\s+(.*)$/.exec(line);
if (h) {
const level = h[1].length;
const size = level === 1 ? "text-[15px]" : level === 2 ? "text-[13px]" : "text-[12px]";
out.push(
| {inline(c, `th${i}-${k}`)} | ))}
|---|
| {inline(c, `td${i}-${ri}-${k}`)} | ))}
{inline(para.join(" "), `p${i}`)}
, ); } return