Extensions
editWithout extensions, the parser follows the CommonMark specification. Extensions add the syntaxes that CommonMark does not define, such as tables and footnotes, and change how some elements are rendered.
Enable extensions
Each extension has a Use… method on MarkdownPipelineBuilder. Call the ones you need, then Build:
var pipeline = new MarkdownPipelineBuilder()
.UsePipeTables()
.UseTaskLists()
.UseAutoIdentifiers()
.Build();
var html = MarkdownConverter.ToHtml("# Getting started", pipeline);
Assert.Equal("<h1 id=\"getting-started\">Getting started</h1>\n", html);- Enable only what your content uses. Each extension adds a syntax: text that was plain before may become a table, a link or an emoji.
- Call UseGenericAttributes after the other extensions. It changes the parsers that the other extensions add.
- Pass the options in the first call. An extension is enabled once: most
Use…methods do nothing when their extension is already enabled, and keep its options. UseAlertBlocks and UseAutoLinks replace it instead, UseGenericAttributes replaces its filter, and UseReferralLinks adds the newrelvalues.
Enable the common extensions at once
UseAdvancedExtensions enables alert blocks, abbreviations, auto-identifiers, citations, custom containers, definition lists, extra emphasis, figures, footers, footnotes, grid tables, mathematics, media links, pipe tables, extra list types, task lists, diagrams, auto-links and generic attributes:
var pipeline = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.Build();
var html = MarkdownConverter.ToHtml("| a | b |\n|---|---|\n| 1 | 2 |", pipeline);
Assert.StartsWith("<table>", html);It does not enable emojis, SmartyPants, soft line breaks as hard breaks, CJK emphasis, globalization, Jira links, referral links, Bootstrap classes, YAML front matter, pragma lines or UseNonAsciiNoEscape.
UseAdvancedExtensions enables each extension with its default options, unless it is already enabled. To change the options of one of them, enable it first:
// UseAdvancedExtensions keeps the extensions that are already enabled, with their options
var pipeline = new MarkdownPipelineBuilder()
.UseAutoIdentifiers(AutoIdentifierOptions.GitHub)
.UseAdvancedExtensions()
.Build();
var html = MarkdownConverter.ToHtml("# Été", pipeline);
Assert.Equal("<h1 id=\"été\">Été</h1>\n", html);
// In the other order, UseAutoIdentifiers does nothing: the extension is already enabled with the default options
var ignored = new MarkdownPipelineBuilder()
.UseAdvancedExtensions()
.UseAutoIdentifiers(AutoIdentifierOptions.GitHub)
.Build();
Assert.Equal("<h1 id=\"ete\">Été</h1>\n", MarkdownConverter.ToHtml("# Été", ignored));Enable extensions from a configuration string
Configure enables the extensions named in a string, separated by +. Use it to choose the extensions in a setting of your application:
// For instance, read from the configuration of the application
var extensions = "pipetables+tasklists+autoidentifiers";
var pipeline = new MarkdownPipelineBuilder()
.Configure(extensions)
.Build();
var html = MarkdownConverter.ToHtml("- [x] Done", pipeline);
Assert.Equal("<ul class=\"contains-task-list\">\n<li class=\"task-list-item\"><input disabled=\"disabled\" type=\"checkbox\" checked=\"checked\" /> Done</li>\n</ul>\n", html);The names are case-insensitive; an unknown name throws an ArgumentException.
All the extensions
| Method | Syntax or effect | Page |
|---|---|---|
| UsePipeTables | GitHub-style tables: \| a \| b \| | Tables |
| UseGridTables | Pandoc grid tables, drawn with +, - and \| | Tables |
| UseBootstrap | Bootstrap classes on tables, figures, images and quotes | Tables |
| UseAutoIdentifiers | An id on each heading, and links to headings by their text | Headings and links |
| UseAutoLinks | Links from https://…, www.… and mailto: text | Headings and links |
| UseReferralLinks | rel values, such as nofollow, on links | Headings and links |
| UseJiraLinks | Links from PROJECT-123 references | Headings and links |
| UseMediaLinks | Players for YouTube, Vimeo, audio and video links | Headings and links |
| UseNonAsciiNoEscape | Non-ASCII characters of URLs written as they are | Headings and links |
| UseEmphasisExtras | ~~deleted~~, ~sub~, ^sup^, ++inserted++, ==marked== | Text formatting |
| UseSmartyPants | Typographic quotes, dashes and ellipses | Text formatting |
| UseEmojiAndSmiley | :tada: shortcodes and :) smileys | Text formatting |
| UseAbbreviations | *[HTML]: … definitions rendered as <abbr> | Text formatting |
| UseCjkFriendlyEmphasis | Emphasis rules adapted to Chinese, Japanese and Korean text | Text formatting |
| UseGlobalization | dir="rtl" on right-to-left content | Text formatting |
| UseSoftlineBreakAsHardlineBreak | Every line break rendered as <br /> | Converting to HTML |
| UseAlertBlocks | GitHub alerts: > [!NOTE], > [!WARNING]… | Blocks |
| UseCustomContainers | ::: blocks rendered as <div>, ::text:: as <span> | Blocks |
| UseDefinitionLists | Terms and definitions rendered as <dl> | Blocks |
| UseFigures, UseFooters, UseCitations | ^^^ figures, ^^ footers, ""title"" citations | Blocks |
| UseFootnotes | [^1] footnotes | Blocks |
| UseTaskLists | - [ ] and - [x] items | Blocks |
| UseListExtras | a. and i. ordered lists | Blocks |
| UseMathematics | $inline$ and $$block$$ mathematics | Blocks |
| UseDiagrams | mermaid and nomnoml code blocks | Blocks |
| UseGenericAttributes | {#id .class name=value} attributes | Attributes |
| UseYamlFrontMatter | A leading YAML block, excluded from the output | YAML front matter |
| UsePragmaLines | An id with the line number on each block | Source positions |
| UsePreciseSourceLocation | The exact position of every inline | Source positions |
| DisableHtml | Raw HTML written as text | Security |
| DisableHeadings | No ATX (#) or setext headings | |
| EnableTrackTrivia | Whitespace kept to write the document back | Editing documents |
| ConfigureNewLine | The line ending of the output | Converting to HTML |
The .md files of the test specifications give the exact syntax and output of each extension, with many examples.
Pages
- Tables: pipe tables, grid tables and their options.
- Headings and links: heading identifiers, automatic links,
relvalues, Jira links and embedded media. - Text formatting: strikethrough and other emphasis, typographic punctuation, emojis and abbreviations.
- Blocks: alerts, containers, definition lists, figures, footnotes, task lists, mathematics and diagrams.
- Attributes: add identifiers, classes and attributes to the elements.
- YAML front matter: read the metadata at the top of a document.