From 6e8701943c0bc573ffbe9ff02e8feec912caa118 Mon Sep 17 00:00:00 2001 From: bfs2021 <101915083+bfs2021@users.noreply.github.com> Date: Thu, 22 Oct 2026 11:49:20 +0800 Subject: [PATCH] frontmatter: find a block list past blank and comment lines A comment between a key and its block list made the look-ahead see the comment, so the key stayed null and the first item errored as a list item without a key. Skip blank and comment lines when looking for the list. Fixes #84 Signed-off-by: bfs2021 <101915083+bfs2021@users.noreply.github.com> --- site/lib/frontmatter.mjs | 6 +++++- site/lib/lib.test.mjs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/site/lib/frontmatter.mjs b/site/lib/frontmatter.mjs index 37af725..5d5fee7 100644 --- a/site/lib/frontmatter.mjs +++ b/site/lib/frontmatter.mjs @@ -85,7 +85,11 @@ export function parseFrontmatter(text) { return; } const value = parseScalar(line.slice(idx + 1)); - const next = lines[i + 1]; + let nextIndex = i + 1; + while (nextIndex < lines.length && (!lines[nextIndex].trim() || lines[nextIndex].trim().startsWith("#"))) { + nextIndex += 1; + } + const next = lines[nextIndex]; if (value === null && next !== undefined && /^\s+-\s/.test(next)) { meta[key] = []; listKey = key; diff --git a/site/lib/lib.test.mjs b/site/lib/lib.test.mjs index f6b3cbc..d0b068d 100644 --- a/site/lib/lib.test.mjs +++ b/site/lib/lib.test.mjs @@ -485,6 +485,9 @@ const f1 = fm([ eq("frontmatter undoes quote escapes", f1.meta.attribution_string, 'Music "{title}" by {artist}'); eq("frontmatter keeps a quoted comma inside one list item", JSON.stringify(f1.meta.tags), JSON.stringify(["sci-fi, space", "ui", "it's"])); eq("frontmatter reads a block list", JSON.stringify(f1.meta.formats), JSON.stringify(["PNG", "SVG"])); +const fComment = fm(["tags:", " # content words only", " - low-poly"]); +eq("frontmatter reads a block list after a comment", JSON.stringify(fComment.meta.tags), JSON.stringify(["low-poly"])); +eq("frontmatter has no errors for a list after a comment", fComment.errors.length, 0); eq("frontmatter reads booleans", f1.meta.commercial, true); eq("frontmatter has no errors on good input", f1.errors.length, 0); eq("frontmatter ignores a byte-order mark", parseFrontmatter("---\nid: a\n---\nB")?.meta.id, "a");