Markdown

Bind Markdown front matter and the raw body to a record, then render it with the Markdown library you choose.

On this page
csharp
[DataSource("Posts", "./*.md", OrderBy = "Date desc, Title")]
public sealed record BlogPost(
    string Slug, string Title, DateOnly Date, string Summary, string RawMarkdown);
markdown
---
title: Hello
date: 2026-01-05
summary: My first post.
---
Body text in **Markdown**.

Bevel reads the front matter and the raw body. It does not turn Markdown into HTML. How you render it is up to you.

What Bevel fills in

Besides the front matter, Bevel fills these members. Declare only the ones you need.

Member Value
Slug The file name without extension, or slug: in the front matter.
SourcePath The file's path, relative to the wildcard root.
RawMarkdown The body without the front matter.

Matching ignores case. Document fields win, except Slug.

  • The front matter sits between --- lines (trailing spaces or tabs are allowed). The closing line may be the last line, with no newline after it.
  • RawMarkdown and front matter are always LF, whatever the file uses. Slugs are NFC-normalized (not lowercased). Output is the same on every OS.
  • Front matter keys that match no member are ignored.
  • For index.md below the root, the slug is the folder name. See Nested folders.
  • To drop drafts, see Drafts and removing items.

Render the body

Add Markdig to your project and write Components/Markdown.razor:

razor
@using Markdig

@((MarkupString)Markdig.Markdown.ToHtml(Content, Pipeline))

@code {
    static readonly MarkdownPipeline Pipeline = new MarkdownPipelineBuilder()
        .UseAdvancedExtensions()
        .Build();

    [Parameter, EditorRequired] public string Content { get; set; } = "";
}

Use it on a page with <Markdown Content="@Post.RawMarkdown" />.

Bevel does not check slugs by itself. Add [Unique] (see Required values and Unique).