Skip to content

Show front matter, read its fields, and recognize TOML front matter (#195) - #196

Merged
jeff377 merged 3 commits into
mainfrom
claude/front-matter-2b6044
Dec 4, 2026
Merged

jeff377 merged 3 commits into
mainfrom
claude/front-matter-2b6044

Conversation

@jeff377

@jeff377 jeff377 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Closes #195

What this adds

  • MarkdownOptions.ShowFrontMatter (off by default). With it off, the output is the same as before. With it on, the YAML (---) or TOML (+++) front matter at the top of a text is shown by both MarkdownViewers and by MarkdownHtml:
    • title is drawn like a first-level heading. It is not a heading, so it is left out of the table of contents, find, and outline numbering.
    • date, author/authors and tags/categories go on one faded line, with the tags drawn as labels.
    • Every other field sits behind a More toggle. The toggle is collapsed in both viewers and open in HTML. Its text comes from FrontMatterMoreLabel on each viewer, so an application can translate it.
    • A nested value is shown as code.
    • Every value is plain text. A value becomes a link only when it is an absolute URL whose scheme the link policy allows.
    • Front matter that cannot be read is shown as a code block with its source. It never throws.
  • MarkdownFrontMatter.Read(string): a public reader whose API uses no Markdig type. It returns the format and the fields (Text, List or Nested). MarkdownHtml.ToPage takes the front matter's title when MarkdownHtmlOptions.Title is not set.
  • TOML front matter: a block parser of our own. A +++ block is no longer read as paragraphs, and MarkdownEditor colors it as code.
  • The YAML and TOML readers are our own and cover the subset front matter is written in. No package reference was added.
  • The gallery samples have a Post switch that shows a blog post with front matter.

Downstream (Polhem framework)

  • New CSS variable: --pmd-tag-bg, the background of a front matter tag. When it is not set, it falls back to --pmd-code-bg.
  • New CSS classes: pmd-front-matter, pmd-front-matter-title, pmd-front-matter-byline, pmd-front-matter-tag, pmd-front-matter-fields, pmd-front-matter-more.
  • New parameter / styled property: FrontMatterMoreLabel on both viewers.
  • Behavior change: a text that starts with TOML front matter (+++) used to show that block as paragraphs. Now it is hidden by default, the same way YAML front matter already was.

Checks

  • dotnet build / dotnet test (Release), node --test tests/js/*.test.mjs, ./check-md-links.sh, the AOT smoke publish and run, and the WASM gallery publish all pass locally.
  • Both galleries were checked by hand:
    • Blazor: light and dark themes, with More open. Find skips the front matter.
    • Avalonia desktop: Post sample, with More open.
  • With Semi.Avalonia, the Expander draws its own bottom divider above the front matter's rule. This comes from the theme, not from the package.

@jeff377
jeff377 enabled auto-merge (squash) December 4, 2026 16:17
@jeff377
jeff377 merged commit a84ac28 into main Dec 4, 2026
6 checks passed
@jeff377
jeff377 deleted the claude/front-matter-2b6044 branch December 4, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show front matter, read its fields, and recognize TOML front matter

1 participant