wip: typed literal syntax for locale messages

This commit is contained in:
Benjamin Singleton 2026-02-23 12:28:36 -06:00
parent d258014471
commit e48b6c8708
6 changed files with 297 additions and 125 deletions

View file

@ -39,26 +39,39 @@ export function parseMarkdown<Slot extends string>(
markdownString: string,
slots: readonly Slot[],
): Result<Markdown<Slot>, string> {
if (markdownString === "|~") {
if (markdownString.trim() === "--") {
return { type: "ok", ok: { lines: [], slots: [] } };
}
const lines = markdownString.split("\n");
const strippedLines: string[] = [];
const dequotedLines: string[] = [];
for (const line of lines) {
const MARKDOWN_LINE_PREFIX = "| ";
if (!line.startsWith(MARKDOWN_LINE_PREFIX)) {
const MARKDOWN_LINE_AFFIX = '"';
if (!line.startsWith(MARKDOWN_LINE_AFFIX)) {
return {
type: "err",
err: `Line ${String(strippedLines.length + 1)} of markdown is not prefixed`,
err: `Line ${String(dequotedLines.length + 1)} of markdown must start with ${MARKDOWN_LINE_AFFIX}`,
};
}
strippedLines.push(line.substring(MARKDOWN_LINE_PREFIX.length));
if (!line.endsWith(MARKDOWN_LINE_AFFIX)) {
return {
type: "err",
err: `Line ${String(dequotedLines.length + 1)} of markdown must end with ${MARKDOWN_LINE_AFFIX}`,
};
}
const deprefixed = line.substring(MARKDOWN_LINE_AFFIX.length);
const dequoted = deprefixed.substring(
0,
deprefixed.length - MARKDOWN_LINE_AFFIX.length,
);
dequotedLines.push(dequoted);
}
const markdownLines: MarkdownLine<Slot>[] = [];
for (const line of strippedLines) {
for (const line of dequotedLines) {
const markdownLineRes = parseMarkdownLine(line, slots);
if (markdownLineRes.type === "err") {
return {