fix(frontmatter): expose metadata table semantics

Refs #8. Add a caption and row headers; keep the actual accessible-table assertion unchanged.

Co-Authored-By: Codex (GPT-6) <noreply@openai.com>
Signed-off-by: James Maes <jmaes@dmdbrands.com>
This commit is contained in:
James MaesandCodex committed 2026-10-10 21:03:18 -05:00
1 parent 3b6ebf83d0
commit a141929820
2 files changed
+5 -5

No files matched your search

@@ -34,7 +34,7 @@ internal static class DocumentFrontmatter
/// <summary>Metadata is display text: split only at the first colon and escape every value before creating table markup.</summary>
public static string RenderMetadata(string metadata)
{
var html = new StringBuilder("<table>");
var html = new StringBuilder("<table><caption>Document metadata</caption>");
foreach(string line in metadata.Split('\n'))
{
string text = line.Trim();
@@ -46,7 +46,7 @@ internal static class DocumentFrontmatter
html.Append("<tr>");
if(colon >= 0)
{
html.Append("<td>").Append(WebUtility.HtmlEncode(PlainValue(text[..colon]))).Append("</td>");
html.Append("<th>").Append(WebUtility.HtmlEncode(PlainValue(text[..colon]))).Append("</th>");
html.Append("<td>").Append(WebUtility.HtmlEncode(PlainValue(text[(colon + 1)..]))).Append("</td>");
}
else
@@ -55,7 +55,7 @@ public sealed class DocumentFrontmatterTests
Assert.Contains("<h1>Body heading</h1>", hidden, StringComparison.Ordinal);
Assert.DoesNotContain("Visible value", hidden, StringComparison.Ordinal);
string metadata = renderer.Render(Markdown, FrontmatterMode.Metadata);
Assert.Contains("<td>title</td><td>Visible value</td>", metadata, StringComparison.Ordinal);
Assert.Contains("<th>title</th><td>Visible value</td>", metadata, StringComparison.Ordinal);
Assert.Contains("https://example.com/a:b", metadata, StringComparison.Ordinal);
Assert.Contains("&lt;script&gt;bad()&lt;/script&gt;", metadata, StringComparison.Ordinal);
Assert.DoesNotContain("<script", metadata, StringComparison.Ordinal);
@@ -92,7 +92,7 @@ public sealed class DocumentFrontmatterTests
[InlineData("O'Reilly", "O'Reilly")]
public void RenderMetadata_FormattingMarkers_ProducesPlainText(string value, string expected)
{
Assert.Equal("<table><tr><td>key</td><td>" + System.Net.WebUtility.HtmlEncode(expected) + "</td></tr></table>", DocumentFrontmatter.RenderMetadata("key: " + value));
Assert.Equal("<table><caption>Document metadata</caption><tr><th>key</th><td>" + System.Net.WebUtility.HtmlEncode(expected) + "</td></tr></table>", DocumentFrontmatter.RenderMetadata("key: " + value));
}
@@ -101,7 +101,7 @@ public sealed class DocumentFrontmatterTests
[Fact]
public void RenderMetadata_UnstructuredRows_EscapesText()
{
Assert.Equal("<table><tr><td colspan=\"2\">A &amp; B</td></tr></table>", DocumentFrontmatter.RenderMetadata(" \nA & B\n\t"));
Assert.Equal("<table><caption>Document metadata</caption><tr><td colspan=\"2\">A &amp; B</td></tr></table>", DocumentFrontmatter.RenderMetadata(" \nA & B\n\t"));
}