Other extensions

This page covers smaller or more specialized extensions that are not part of UseAdvancedExtensions().

Bootstrap

Enable with .UseBootstrap().

Adds Bootstrap CSS classes to generated HTML elements:

Element Class applied
<table> table
<blockquote> blockquote
<figure> figure
<figcaption> figure-caption
<img> img-fluid
var pipeline = new MarkdownPipelineBuilder()
    .UseBootstrap()
    .Build();

Hardline breaks

Enable with .UseSoftlineBreakAsHardlineBreak().

Makes every soft line break (a single newline inside a paragraph) render as a <br> tag instead of a space. Useful when you want each line to appear as written.

var pipeline = new MarkdownPipelineBuilder()
    .UseSoftlineBreakAsHardlineBreak()
    .Build();

Without this extension:

Line one
Line two

Renders as: <p>Line one Line two</p>

With this extension, it renders as: <p>Line one<br />Line two</p>

Enable with .UseJiraLinks(options).

Automatically converts JIRA-style project references (e.g., PROJECT-123) into clickable links.

using Markdig.Extensions.JiraLinks;

var pipeline = new MarkdownPipelineBuilder()
    .UseJiraLinks(new JiraLinkOptions("https://jira.example.com/browse/"))
    .Build();

var html = Markdown.ToHtml("Fixed in PROJ-456.", pipeline);
// => <p>Fixed in <a href="https://jira.example.com/browse/PROJ-456">PROJ-456</a>.</p>

Globalization

Enable with .UseGlobalization().

Adds appropriate dir attributes on HTML elements for right-to-left content. Detects the text direction of each block and annotates it.

var pipeline = new MarkdownPipelineBuilder()
    .UseGlobalization()
    .Build();

Enable with .UseReferralLinks(rels).

Adds rel attributes to all rendered links:

var pipeline = new MarkdownPipelineBuilder()
    .UseReferralLinks("nofollow", "noopener", "noreferrer")
    .Build();

All links will have rel="nofollow noopener noreferrer" added.

Self pipeline

Enable with .UseSelfPipeline().

Detects the pipeline configuration from the Markdown document itself via a special HTML comment tag:

<!--markdig:extensions=pipetables+footnotes-->

| A | B |
|---|---|
| 1 | 2 |
var pipeline = new MarkdownPipelineBuilder()
    .UseSelfPipeline() // Must be the only extension
    .Build();

Pragma lines

Enable with .UsePragmaLines().

Inserts <span id="pragma-line-N"></span> markers into the HTML output for each source line. This is useful for editor synchronization (scrolling an editor to the rendered position).

var pipeline = new MarkdownPipelineBuilder()
    .UsePragmaLines()
    .Build();

Non-ASCII no escape

Enable with .UseNonAsciiNoEscape().

Disables percent-encoding of non-ASCII characters in URLs. This works around a rendering bug in Internet Explorer/Edge with local file links containing non-US-ASCII characters.

var pipeline = new MarkdownPipelineBuilder()
    .UseNonAsciiNoEscape()
    .Build();

Precise source location

Enable with .UsePreciseSourceLocation().

Maps every AST node to its exact position in the original source text via the Span property. Useful for syntax highlighting, editors, and linters.

var pipeline = new MarkdownPipelineBuilder()
    .UsePreciseSourceLocation()
    .Build();

var document = Markdown.Parse(text, pipeline);
foreach (var node in document.Descendants())
{
    Console.WriteLine($"{node.GetType().Name}: {node.Span}");
}

Disable HTML

Use .DisableHtml() (a configuration option, not an extension).

Removes the HTML block parser and disables inline HTML parsing. This prevents raw HTML injection, but it is not a complete security solution on its own:

var pipeline = new MarkdownPipelineBuilder()
    .DisableHtml()
    .Build();