Markdown Rendering

HtmlForgeX can render markdown directly into the document model so you still work with typed HtmlForgeX elements instead of hand-authoring HTML.

What You Get

  • Headings, paragraphs, lists, task lists, blockquotes, and horizontal rules
  • Inline formatting such as bold, italic, strike-through, inline code, links, and images
  • Fenced code blocks with PrismJS-friendly output
  • Plain, Bootstrap, Tabler, and DataTables-backed markdown tables
  • GitHub-style callouts like NOTE , TIP , and WARNING
  • Safe defaults that encode HTML and strip unsafe scripts

Quick Start

var page = doc.Body.Page();
var markdown = new BasicElement();

markdown.Markdown("""
# Hello HtmlForgeX

This is **markdown** rendered inside a HtmlForgeX document.
""");

page.Add(markdown);

Useful Options

MarkdownOptions lets you control how markdown maps into HtmlForgeX:

  • HeadingsBaseLevel to offset heading levels inside cards or sections
  • OpenLinksInNewTab and AllowRelativeLinks for link behavior
  • TableMode to choose between plain, Bootstrap, Tabler, or DataTables tables
  • GenerateHeadingIds when you want slugged anchors
  • TaskListStyle to match the visual style of your output
var options = new MarkdownOptions {
    TableMode = MarkdownTableMode.DataTables,
    GenerateHeadingIds = true,
    OpenLinksInNewTab = true
};

page.Card(card => {
    card.Header(header => header.Title("Release Notes"));
    card.Body(body => body.Markdown(markdownText, options));
});

OfficeIMO Integration

HtmlForgeX.Markdown is the optional add-on package for OfficeIMO.Markdown integration. It maps OfficeIMO's markdown model into HtmlForgeX elements, so generated content still uses HtmlForgeX styling, Prism registration, and DataTables support.

dotnet add package HtmlForgeX.Markdown
using HtmlForgeX.Markdown;

var doc = new Document(LibraryMode.Online)
    .Settings(s => s.UseOfficeImo(o => {
        o.HeadingsBaseLevel = 2;
        o.GenerateHeadingIds = true;
        o.TableMode = MarkdownTableMode.Tabler;
    }).End());

Security Model

  • Html content is encoded by default
  • <script> tags are stripped
  • Links and images are restricted to safe schemes
  • Inline code is protected before emphasis parsing runs

Examples In This Repo

  • HtmlForgeX.Examples/Markdown/MarkdownStandaloneExample.cs
  • HtmlForgeX.Examples/Markdown/MarkdownExample.cs
  • HtmlForgeX.Examples/Markdown/MarkdownIntegrationDemo.cs
  • HtmlForgeX.Examples/Markdown/OfficeImoMarkdownExample.cs