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, andWARNING - 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:
HeadingsBaseLevelto offset heading levels inside cards or sectionsOpenLinksInNewTabandAllowRelativeLinksfor link behaviorTableModeto choose between plain, Bootstrap, Tabler, or DataTables tablesGenerateHeadingIdswhen you want slugged anchorsTaskListStyleto 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.Markdownusing 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.csHtmlForgeX.Examples/Markdown/MarkdownExample.csHtmlForgeX.Examples/Markdown/MarkdownIntegrationDemo.csHtmlForgeX.Examples/Markdown/OfficeImoMarkdownExample.cs
Related Guides
- Installation — package commands for HtmlForgeX and optional add-ons
- Advanced Topics — library modes and AOT guidance