### Delimiter Run Examples Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md Provides examples of different types of delimiter runs: left-flanking, right-flanking, both, and neither. ```markdown ***abc _abc **"abc" _"abc" ``` ```markdown abc*** abc_ "abc"** "abc"_ ``` ```markdown abc***def "abc"_"def" ``` ```markdown abc *** def a _ b ``` -------------------------------- ### Fenced Code Block with Tilde Info String and Options Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Shows an example of a fenced code block using tildes with an info string that includes options like start line. ```markdown ~~~~ ruby startline=3 $%@#$ def foo(x) return 3 end ~~~~~~~ ``` -------------------------------- ### AsciiDoc Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md An example of structured text using AsciiDoc syntax, demonstrating list items, paragraphs, and indented blocks. ```asciidoc 1. List item one. + List item one continued with a second paragraph followed by an Indented block. + ................. $ ls *.sh $ mv *.sh ~/tmp ................. + List item continued with a third paragraph. 2. List item two continued with an open block. + -- This paragraph is part of the preceding list item. a. This list is nested and does not require explicit item continuation. + This paragraph is part of the preceding list item. b. List item b. This paragraph belongs to item two of the outer list. -- ``` -------------------------------- ### Markdown Equivalent Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md The equivalent of the AsciiDoc example, written in Markdown syntax, illustrating list nesting and paragraph structure for readability. ```markdown 1. List item one. List item one continued with a second paragraph followed by an Indented block. $ ls *.sh $ mv *.sh ~/tmp List item continued with a third paragraph. 2. List item two continued with an open block. This paragraph is part of the preceding list item. 1. This list is nested and does not require explicit item continuation. This paragraph is part of the preceding list item. 2. List item b. This paragraph belongs to item two of the outer list. ``` -------------------------------- ### Render Inline Math Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/mathematics.md Markdown example demonstrating inline math using single dollar signs. This is rendered as HTML span with class 'math'. ```markdown The quadratic formula is $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$. ``` -------------------------------- ### Render Block Math Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/mathematics.md Markdown example demonstrating block math using double dollar signs. This is rendered as HTML div with class 'math'. ```markdown $$ \int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} $$ ``` -------------------------------- ### List Item Starting with Blank Line Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates a list item that begins with a blank line, followed by content. This shows how Markdig correctly parses nested structures like code blocks and block quotes within such list items. ```markdown - foo - ``` bar ``` - baz ``` ```html ``` -------------------------------- ### Implement Custom Block Parser (NoteBlockParser) Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/block-parsers.md Implement the `BlockParser` class to define how your custom block is recognized and parsed. This example parses custom note blocks starting with '!!!'. ```csharp using Markdig.Helpers; using Markdig.Parsers; public class NoteBlockParser : BlockParser { public NoteBlockParser() { // This parser triggers on '!' characters OpeningCharacters = ['!']; } public override BlockState TryOpen(BlockProcessor processor) { // Don't match if indented as code (4+ spaces) if (processor.IsCodeIndent) return BlockState.None; var line = processor.Line; var startPosition = line.Start; // Check for "!!!" prefix if (line.CurrentChar != '!' || line.PeekChar(1) != '!' || line.PeekChar(2) != '!') return BlockState.None; // Advance past "!!!" line.Start += 3; line.TrimStart(); // Skip whitespace // Read the note type (e.g., "note", "warning") var noteType = line.ToString().Trim(); string? title = null; // Check for quoted title: !!! note "My Title" var quoteIndex = noteType.IndexOf('"'); if (quoteIndex >= 0) { title = noteType[(quoteIndex + 1)..].TrimEnd('"').Trim(); noteType = noteType[..quoteIndex].Trim(); } // Create the block and push it var block = new NoteBlock(this) { NoteType = noteType, Title = title, Span = new SourceSpan(startPosition, line.End), Line = processor.LineIndex, Column = processor.Column }; processor.NewBlocks.Push(block); return BlockState.Break; // Single-line block } } ``` -------------------------------- ### Simple Grid Table Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/GridTableSpecs.md Demonstrates the basic syntax for a grid table with headers and multiple rows. ```markdown +---------+---------+ | Header | Header | | Column1 | Column2 | +=========+=========+ | 1. ab | > This is a quote | 2. cde | > For the second column | 3. f | +---------+---------+ | Second row spanning | on two columns +---------+---------+ | Back | | | to | | | one | | | column | | +---------+---------+ ``` -------------------------------- ### Valid Jira Link Example 5 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/JiraLinks.md Demonstrates a valid Jira link with a single-character project key. ```markdown This is a Z-1 issue .

This is a Z-1 issue

``` -------------------------------- ### Tab Handling Example 2 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Shows tab behavior with leading spaces and tabs. ```markdown →foo→baz→→bim ``` ```html
foo→baz→→bim
``` -------------------------------- ### Markdown Delimiter Run Examples: Left-Flanking Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Provides examples of delimiter runs that are left-flanking but not right-flanking, illustrating conditions for opening emphasis. ```markdown ***abc _abc **"abc" _"abc" ``` -------------------------------- ### Tab Handling Example 1 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates tab behavior in a simple line without leading indentation. ```markdown →foo→baz→→bim ``` ```html
foo→baz→→bim
``` -------------------------------- ### Basic HTML Block Type 6 Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Illustrates a simple HTML block using type 6 start condition (), showing how content inside is preserved and how a Markdown paragraph follows the block. ```markdown
hi
okay. . table> hi

okay.

``` -------------------------------- ### Valid Jira Link Example 4 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/JiraLinks.md Presents a valid Jira link with a short project key. ```markdown This is a KIRA-1 issue .

This is a KIRA-1 issue

``` -------------------------------- ### Basic HTML Block Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates a simple HTML block. The output shows the HTML block rendered directly. ```markdown . ``` -------------------------------- ### Valid Jira Link Example 2 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/JiraLinks.md Shows a valid Jira link where the project key includes digits. ```markdown This is a ABC4-123 issue .

This is a ABC4-123 issue

``` -------------------------------- ### Blank Lines Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Demonstrates how blank lines are handled between block-level elements and at the beginning/end of a document. ```markdown aaa # aaa . ``` -------------------------------- ### Blank Lines Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates how blank lines are handled between block-level elements and their role in list formatting. ```markdown aaa # aaa . ``` ```html

aaa

aaa

``` -------------------------------- ### Tab Handling Example 3 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Illustrates tab behavior with indented lines containing tabs. ```markdown a→a ὐ→a ``` ```html
a→a
ὐ→a
``` -------------------------------- ### CustomContainerExtension Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/creating-extensions.md Adds support for `:::` fenced containers and inline `::text::` syntax. ```csharp public sealed class CustomContainerExtension : IMarkdownExtension { public void Setup(MarkdownPipelineBuilder pipeline) { // Add the block parser at position 0 (high priority) if (!pipeline.BlockParsers.Contains()) { pipeline.BlockParsers.Insert(0, new CustomContainerParser()); } // Also add inline container support (::text::) var emphasisParser = pipeline.InlineParsers.FindExact(); if (emphasisParser != null && !emphasisParser.HasEmphasisChar(':')) { emphasisParser.EmphasisDescriptors.Add( new EmphasisDescriptor(':', 2, 2, false)); } } public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { if (renderer is HtmlRenderer htmlRenderer) { htmlRenderer.ObjectRenderers.AddIfNotAlready(); htmlRenderer.ObjectRenderers.AddIfNotAlready(); } } } ``` -------------------------------- ### CitationExtension Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/creating-extensions.md Adds support for `"..."` citations by configuring the EmphasisInlineParser and its renderer. ```csharp using Markdig; using Markdig.Parsers.Inlines; using Markdig.Renderers; using Markdig.Renderers.Html.Inlines; public sealed class CitationExtension : IMarkdownExtension { public void Setup(MarkdownPipelineBuilder pipeline) { // Find the existing emphasis parser var emphasisParser = pipeline.InlineParsers.FindExact(); if (emphasisParser != null && !emphasisParser.HasEmphasisChar('"')) { // Add " as a 2-character emphasis delimiter: ""text"" emphasisParser.EmphasisDescriptors.Add( new EmphasisDescriptor('"', 2, 2, false)); } } public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { if (renderer is not HtmlRenderer) return; // Hook into the emphasis renderer to emit for ""..."" var emphasisRenderer = renderer.ObjectRenderers.FindExact(); if (emphasisRenderer == null) return; var previousTag = emphasisRenderer.GetTag; emphasisRenderer.GetTag = inline => (inline.DelimiterCount == 2 && inline.DelimiterChar == '"' ? "cite" : null) ?? previousTag(inline); } } ``` -------------------------------- ### GFM Pipe Table Parsing Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/PipeTableGfmSpecs.md Demonstrates the conversion of a GFM pipe table in Markdown format to its corresponding HTML table representation. This example shows how Markdig interprets the table structure and content. ```markdown a | b -- | - 0 | 1 | 2 3 | ``` ```html
a b
0 1
3
``` -------------------------------- ### Build and Serve Markdig Documentation Site Source: https://github.com/xoofx/markdig/blob/main/site/AGENTS.md Install the Lunet global tool and use it to build the production site or serve a development version with live reloading. ```sh # Prerequisites: install lunet as a .NET global tool dotnet tool install -g lunet # From this directory (site/) lunet build # production build → .lunet/build/www/ lunet serve # dev server with live reload at http://localhost:4000 ``` -------------------------------- ### HTML Block with Inline End Tag Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md An example where the HTML block's end tag is on the same line as the start tag. ```markdown *foo* .

foo

``` -------------------------------- ### Configure, Build, and Use MarkdownPipeline Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/pipeline.md Demonstrates the typical workflow for configuring a MarkdownPipeline using a builder, building an immutable pipeline, and then using it to render Markdown text to HTML. Ensure the builder is used for configuration and the built pipeline is shared for thread-safe usage. ```csharp var builder = new MarkdownPipelineBuilder() .UseAdvancedExtensions(); var pipeline = builder.Build(); var html = Markdown.ToHtml(markdownText, pipeline); ``` -------------------------------- ### GFM Pipe Table with Full Delimiters Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/PipeTableGfmSpecs.md A GFM pipe table example where each line starts and ends with a column delimiter. ```markdown |a|b| |-|-| |0|1| ``` ```html
a b
0 1
``` -------------------------------- ### HTML Processing Instruction Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md Demonstrates an HTML processing instruction (type 3) followed by regular text. ```markdown '; ?> okay . '; ?>

okay

``` -------------------------------- ### Valid Row Separator Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/GridTableSpecs.md Illustrates a correct row separator syntax and its corresponding HTML output. ```markdown +---------+---------+ | This is | a table | . ``` ```html
This is a table
``` -------------------------------- ### Markdown Subscript Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/emphasis-extras.md Shows how to use a single tilde (~) to format text as subscript in Markdown. ```markdown H~2~O is water. ``` -------------------------------- ### Phase 1: Registering Parsers in MarkdownPipelineBuilder Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/pipeline.md Example of setting up an extension during the build phase. This snippet shows how to add a new block parser or modify an existing inline parser. ```csharp public void Setup(MarkdownPipelineBuilder pipeline) { // Add a new block parser pipeline.BlockParsers.AddIfNotAlready(); // Or modify an existing parser var emphasisParser = pipeline.InlineParsers.FindExact(); if (emphasisParser != null) { emphasisParser.EmphasisDescriptors.Add( new EmphasisDescriptor('%', 3, 3, false)); } } ``` -------------------------------- ### Unintended List Capture Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Illustrates a case where a list starting with '1.' might still be captured unintentionally, despite the rule. ```CommonMark The number of windows in my house is 1. The number of doors is 6. ``` ```HTML

The number of windows in my house is

  1. The number of doors is 6.
``` -------------------------------- ### Simple Nested List Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Basic example of a nested unordered list. ```markdown - a - b ``` -------------------------------- ### Usage Example for NoteBlock Extension Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/renderers.md Shows how to build a Markdown pipeline with the custom NoteExtension and convert Markdown containing a NoteBlock to HTML. ```csharp var pipeline = new MarkdownPipelineBuilder() .UseNotes() .Build(); var html = Markdown.ToHtml("!!! warning \"Be careful\"\n", pipeline); ``` -------------------------------- ### Preventing Spurious List Capture Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Example showing how CommonMark prevents unintended list capture by only allowing lists starting with '1' to interrupt paragraphs. ```CommonMark The number of windows in my house is 14. The number of doors is 6. ``` ```HTML

The number of windows in my house is 14. The number of doors is 6.

``` -------------------------------- ### Build and Serve Markdig Website with Lunet Source: https://github.com/xoofx/markdig/blob/main/AGENTS.md Commands to install the Lunet global tool and build or serve the project website. The production build outputs to .lunet/build/www/, and the development server runs at http://localhost:4000 with live reload. ```sh # Prerequisites: install lunet as a .NET global tool dotnet tool install -g lunet # Build the site (from the project root) cd site lunet build # production build → .lunet/build/www/ lunet serve # dev server with live reload at http://localhost:4000 ``` -------------------------------- ### Markdown Strikethrough Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/emphasis-extras.md Demonstrates how to use double tildes (~~) to format text as strikethrough in Markdown. ```markdown This is ~~deleted~~ text. ``` -------------------------------- ### Valid Jira Link Example 3 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/JiraLinks.md Illustrates a valid Jira link with a longer project key containing digits. ```markdown This is a ABC45-123 issue .

This is a ABC45-123 issue

``` -------------------------------- ### Markdown Heading Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/auto-identifiers.md Demonstrates how a Markdown heading is rendered with an auto-generated ID attribute. ```markdown ## Getting Started ``` -------------------------------- ### Invalid Jira Link Example 2 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/JiraLinks.md An invalid Jira link where the project key is preceded by a digit. ```markdown This is not 4JIRA-123 issue .

This is not 4JIRA-123 issue

``` -------------------------------- ### Phase 2: Registering Object Renderers in HtmlRenderer Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/pipeline.md Example of setting up an extension during the rendering phase. This snippet demonstrates adding an HTML object renderer to the HtmlRenderer. ```csharp public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { if (renderer is HtmlRenderer htmlRenderer) { htmlRenderer.ObjectRenderers.AddIfNotAlready(); } } ``` -------------------------------- ### TaskListExtension Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/creating-extensions.md Adds parsing for `[ ]` and `[x]` checkboxes by inserting a custom TaskListInlineParser. ```csharp public sealed class TaskListExtension : IMarkdownExtension { public void Setup(MarkdownPipelineBuilder pipeline) { // Insert the task list parser before the link parser if (!pipeline.InlineParsers.Contains()) { pipeline.InlineParsers.InsertBefore( new TaskListInlineParser()); } } public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) { if (renderer is HtmlRenderer htmlRenderer) { htmlRenderer.ObjectRenderers.AddIfNotAlready(); } } } ``` -------------------------------- ### HTML Comment Block Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md An example of an HTML comment block (type 2) followed by regular text. ```markdown okay .

okay

``` -------------------------------- ### List Item Parsing Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Demonstrates how a sequence of lines with a list marker and indentation is parsed into a list item with its contents. ```markdown ```````````````````````````````` example A paragraph with two lines. indented code > A block quote. .

A paragraph with two lines.

indented code

A block quote.

```````````````````````````````` ``` ```markdown ```````````````````````````````` example 1. A paragraph with two lines. indented code > A block quote. .
  1. A paragraph with two lines.

    indented code
    

    A block quote.

```````````````````````````````` ``` -------------------------------- ### Simple ATX Headings Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Demonstrates ATX headings from level 1 to 6. ```markdown # foo ## foo ### foo #### foo ##### foo ###### foo ``` -------------------------------- ### HTML Block with Non-Standard Tag Start Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Shows an HTML block starting with a string that resembles a tag but is not standard. ```html
  • foo

      bar
    
  • ``` -------------------------------- ### Valid Jira Link Example 1 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/JiraLinks.md Demonstrates a valid Jira link with a project key composed of uppercase letters and a hyphen followed by digits. ```markdown This is a ABCD-123 issue .

    This is a ABCD-123 issue

    ``` -------------------------------- ### Math Inline at Start of Line Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/MathSpecs.md An opening `$$` at the beginning of a line is interpreted as the start of a math block, not inline math. ```markdown $$ math $$ starting at a line . ``` ```html

    \(math\) starting at a line

    ``` -------------------------------- ### Usage of Blink Extension Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/creating-extensions.md Demonstrates how to enable the Blink extension and convert Markdown text containing the blink syntax to HTML. ```csharp var pipeline = new MarkdownPipelineBuilder() .UseBlink() .Build(); var html = Markdown.ToHtml("This is %%%blinking%%% text.", pipeline); // =>

    This is blinking text.

    ``` -------------------------------- ### ATX Heading Interrupting Paragraph Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Provides an example of an ATX heading interrupting a paragraph and followed by another paragraph. ```markdown Foo bar # baz Bar foo ``` ```html

    Foo bar

    baz

    Bar foo

    ``` -------------------------------- ### Shortcut Reference Link Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates a shortcut reference link where the link label matches a reference definition. The link text is parsed as inlines. ```markdown [foo] [foo]: /url "title" ``` ```html

    foo

    ``` -------------------------------- ### Valid ordered list with large start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md An ordered list start number is valid if it is nine digits or less. ```markdown 123456789. ok . ``` -------------------------------- ### Pipe Table with Starting and Ending Pipes Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/PipeTableSpecs.md A pipe table that starts and ends with pipe characters, demonstrating alignment for each column. ```markdown | abc | def | ghi | |:---:|-----|----:| | 1 | 2 | 3 | . ``` -------------------------------- ### List item with negative start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Demonstrates that a negative number as a start for a list item is not interpreted as an ordered list marker. ```markdown -1. not ok . ``` ```html

    -1. not ok

    ``` -------------------------------- ### Enable JIRA Links Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/other.md Use UseJiraLinks() with a base URL to automatically convert JIRA-style project references (e.g., PROJECT-123) into clickable HTML links. ```csharp 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); // =>

    Fixed in PROJ-456.

    ``` -------------------------------- ### Applying Attributes to Images Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/generic-attributes.md Example of adding CSS classes and HTML attributes like 'width' to an image. ```markdown ![Photo](photo.jpg){.rounded width="200"} ``` -------------------------------- ### List Delimiter Change Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates how changing the list marker character or delimiter starts a new list. ```markdown - foo - bar + baz ``` ```html
    • foo
    • bar
    • baz
    ``` -------------------------------- ### Markdown Input for Block Structure Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md This is the sample Markdown text used to illustrate the block structure parsing process. ```markdown > Lorem ipsum dolor sit amet. > - Qui *quodsi iracundia* > - aliquando id ``` -------------------------------- ### Run Markdig Benchmarks Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/performance.md Command to navigate to the benchmarks directory and run the Markdig benchmarks project using dotnet. ```bash cd src dotnet run -c Release --project Markdig.Benchmarks ``` -------------------------------- ### Valid ordered list with leading zeros in start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md Ordered list start numbers can begin with zero(s) and are parsed correctly. ```markdown 0. ok . ``` ```markdown 003. ok . ``` -------------------------------- ### Markdown Media Link Examples Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/MediaSpecs.md Demonstrates various ways to use Markdown syntax to embed media links from different platforms, including YouTube, Vimeo, Yandex Music, and Odnoklassniki, as well as static MP4 files. ```markdown ![youtube.com](https://www.youtube.com/watch?v=mswPy5bt3TQ) ![youtube.com with t](https://www.youtube.com/watch?v=mswPy5bt3TQ&t=100) ![youtu.be](https://youtu.be/mswPy5bt3TQ) ![youtu.be with t](https://youtu.be/mswPy5bt3TQ?t=100) ![youtube.com/embed 1](https://www.youtube.com/embed/mswPy5bt3TQ?start=100&rel=0) ![youtube.com/embed 2](https://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6) ![vimeo](https://vimeo.com/8607834) ![static mp4](https://sample.com/video.mp4) ![yandex.ru](https://music.yandex.ru/album/411845/track/4402274) ![ok.ru](https://ok.ru/video/26870090463) ``` -------------------------------- ### Document Tree Structure Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md An example of a document tree representation used in CommonMark parsing, illustrating block structures and open blocks. ```tree -> document -> block_quote paragraph "Lorem ipsum dolor sit amet." -> list (type=bullet tight=true bullet_char=-) list_item paragraph "Qui *quodsi iracundia*" -> list_item -> paragraph "aliquando id" ``` -------------------------------- ### Invalid ordered list with negative start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md A negative number is not a valid start number for an ordered list and is rendered as plain text. ```markdown -1. not ok . ``` -------------------------------- ### Registering Extension with Configuration Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/creating-extensions.md Use this method for extensions that require configuration parameters during instantiation. ```csharp var ext = new MyExtension(someConfig); var pipeline = new MarkdownPipelineBuilder() .Use(ext) .Build(); ``` -------------------------------- ### List item with indented content not starting with code Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Shows a list item where the content is indented but does not start with a code block, and how subsequent lines are handled. ```markdown - foo bar ``` ```html
    • foo

    bar

    ``` -------------------------------- ### Avoid Reflection for Parser Instantiation Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/performance.md Demonstrates the correct way to instantiate a parser to ensure compatibility with IL trimming. Avoid using Activator.CreateInstance. ```csharp // Bad — breaks trimming var parser = (BlockParser)Activator.CreateInstance(parserType)! ``` ```csharp // Good — direct construction var parser = new NoteBlockParser(); ``` -------------------------------- ### HTML Block with Malformed Tag Start Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Illustrates an HTML block starting with a string that resembles an opening tag but is not valid. Markdown content is processed. ```markdown
    document -> block_quote paragraph "Lorem ipsum dolor\nsit amet." -> list (type=bullet tight=true bullet_char=-) list_item paragraph "Qui *quodsi iracundia*" -> list_item -> paragraph "aliquando id" ``` -------------------------------- ### URI Autolink Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates a basic URI autolink. The content within angle brackets is treated as a link to that URI. ```markdown .

    http://foo.bar.baz

    ``` -------------------------------- ### Alignment Specification Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/GridTableSpecs.md Illustrates how to specify column alignment using colons in the row separator and the generated HTML. ```markdown +-----+:---:+-----+ | A | B | C | +-----+-----+-----+ . ``` ```html
    A B C
    ``` -------------------------------- ### List item starting with indented code block (complex case) Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Illustrates a list item with a specified start number, followed by an indented code block and then a paragraph. ```markdown 10. foo bar ``` ```html
    1. foo

      bar
      
    ``` -------------------------------- ### Configure Pipeline with All Advanced Extensions Source: https://github.com/xoofx/markdig/blob/main/site/docs/getting-started.md Build a Markdown pipeline that includes all advanced extensions like tables, task lists, and math. This pipeline is then used for conversion. ```csharp using Markdig; // Build a pipeline with all advanced extensions var pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() .Build(); var html = Markdown.ToHtml("This is ~~deleted~~ text.", pipeline); Console.WriteLine(html); // Output:

    This is deleted text.

    ``` -------------------------------- ### Invalid ordered list item with negative start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates an invalid ordered list item where the start number is negative, causing it to be treated as plain text. ```markdown -1. not ok ``` ```html

    -1. not ok

    ``` -------------------------------- ### Valid ordered list item with leading zeros in start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Illustrates a valid ordered list item where the start number begins with zeros, which are correctly interpreted. ```markdown 0. ok ``` ```html
    1. ok
    ``` -------------------------------- ### Running Conformance Tests Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Use this command to run conformance tests against a Markdown program using the specification file. ```bash python test/spec_tests.py --spec spec.txt --program PROGRAM ``` -------------------------------- ### Valid ordered list item with large start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates a valid ordered list item where the start number is within the allowed limit of nine digits. ```markdown 123456789. ok ``` ```html
    1. ok
    ``` -------------------------------- ### Usage of Custom Fluent Extension Method Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/creating-extensions.md Demonstrates how to use the custom fluent extension method to register an extension with options. ```csharp var pipeline = new MarkdownPipelineBuilder() .UseMyExtension(new MyExtensionOptions { /* ... */ }) .Build(); ``` -------------------------------- ### GFM Pipe Table Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/PipeTableGfmSpecs.md Demonstrates a basic GFM pipe table with a header and data rows. Requires at least two dashes in the header separator for list-like lines. ```markdown a | b -- | - 0 | 1 ``` ```html
    a b
    0 1
    ``` -------------------------------- ### HTML Block with Non-Standard Tag Start Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Shows an HTML block starting with a string that looks like a tag but contains invalid characters. Markdown content is processed. ```markdown
    This is not aJIRA-123 issue

    ``` -------------------------------- ### Pipe Table with Header Separator Starting Like a List Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/PipeTableSpecs.md Shows a pipe table where the header separator line starts with a single dash, which is still recognized as a table. ```markdown a | b - | - 0 | 1 ``` -------------------------------- ### Block starting with 3-space indent not forming a list item Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Illustrates that a block starting with a 3-space indent, not preceded by a list marker, does not form a list item and is rendered as paragraphs. ```markdown foo bar . ``` ```html

    foo

    bar

    ``` -------------------------------- ### Prevent Interrupting Paragraphs with CanInterrupt Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/block-parsers.md Override the CanInterrupt method to prevent your custom block syntax from starting in the middle of a paragraph. This ensures your syntax only begins at the start of a block context. ```csharp public override bool CanInterrupt(BlockProcessor processor, Block block) { // Only allow after a blank line, not in the middle of a paragraph return false; } ``` -------------------------------- ### Column Width Calculation Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/GridTableSpecs.md Demonstrates how column widths are calculated based on character counts in the first row separator and the resulting HTML. ```markdown +----+--------+----+ | A | B C D | E | +----+--------+----+ . ``` ```html
    A B C D E
    ``` -------------------------------- ### Valid ordered list item with multiple leading zeros in start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Shows a valid ordered list item where the start number has multiple leading zeros, which are correctly parsed. ```markdown 003. ok ``` ```html
    1. ok
    ``` -------------------------------- ### Correct Pipeline Usage for Parse and Render Source: https://github.com/xoofx/markdig/blob/main/site/docs/usage.md Illustrates the correct way to use a Markdown pipeline by passing the same instance to both the Parse and ToHtml methods. This ensures that extensions registered during parsing are available during rendering, preventing rendering errors. ```csharp // ✅ Correct — same pipeline for parse and render var pipeline = new MarkdownPipelineBuilder().UsePipeTables().Build(); var document = Markdown.Parse(markdownText, pipeline); var html = document.ToHtml(pipeline); ``` -------------------------------- ### Basic Setext Heading Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates a simple Setext heading with a single line of text. ```markdown foo --- . ``` ```html
    foo
    

    ``` -------------------------------- ### Markdown Example with Trivia and LineBreakInline Source: https://github.com/xoofx/markdig/blob/main/src/Markdig/Roundtrip.md This example showcases a more complex case involving leading trivia, a LineBreakInline, the block's newline, and trailing trivia, illustrating the distinction between trivia and inline elements. ```markdown \n text1\ntext2\n\n ``` -------------------------------- ### Configure MarkdownPipeline with Extension Strings Source: https://github.com/xoofx/markdig/blob/main/site/docs/usage.md Dynamically configure the MarkdownPipeline at runtime using a string that lists common and specific extension tokens. This is useful for loading configurations from external sources like config files. ```csharp var pipeline = new MarkdownPipelineBuilder() .Configure("common+pipetables+footnotes+figures") .Build(); ``` -------------------------------- ### Invalid ordered list with start number exceeding nine digits Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md Ordered list start numbers exceeding nine digits are not considered valid list markers and are rendered as plain text. ```markdown 1234567890. not ok . ``` -------------------------------- ### IMarkdownExtension Interface Definition Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/pipeline.md Defines the two Setup methods for IMarkdownExtension: one for the build phase (registering parsers) and one for the rendering phase (registering object renderers). ```csharp public interface IMarkdownExtension { // Phase 1: Called during Build() — register/modify parsers void Setup(MarkdownPipelineBuilder pipeline); // Phase 2: Called during rendering — register object renderers void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer); } ``` -------------------------------- ### Invalid ordered list item with too large start number Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Shows an invalid ordered list item where the start number exceeds the allowed nine digits, resulting in it being treated as plain text. ```markdown 1234567890. not ok ``` ```html

    1234567890. not ok

    ``` -------------------------------- ### Markdown Heading Syntax (ATX Style) Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/NormalizeSpecs/Headings.md Demonstrates the syntax for ATX-style headings from H1 to H6. ```markdown # Heading 1 ## Heading 2 ### Heading 3 #### Heading 4 ##### Heading 5 ###### Heading 6 ``` -------------------------------- ### Ordered List with Specific Starting Alpha Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/ListExtraSpecs.md Illustrates starting an alpha-ordered list from a specific letter (e.g., 'b'). The HTML includes 'type="a"' and 'start="2"'. ```markdown b. First item c. Second item ``` ```html
    1. First item
    2. Second item
    ``` -------------------------------- ### CommonMark Rule 11 Examples Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/CommonMark.md Rule 11: Examples demonstrating how sequences of asterisks that do not form valid emphasis or strong emphasis are rendered as literal text. This includes cases with escaped asterisks or underscores. ```markdown foo *** .

    foo ***

    ``` ```markdown foo *\** .

    foo *

    ``` ```markdown foo *_* .

    foo _

    ``` ```markdown foo ***** .

    foo *****

    ``` -------------------------------- ### List Item Starting with Blank Line Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Demonstrates list items that begin with a blank line, showing how content is parsed into HTML list elements. ```markdown - foo - ``` bar ``` - baz ``` -------------------------------- ### Typed Metadata Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/parser-authoring-api.md Demonstrates how to set and retrieve typed state data on an AST node using DataKey for collision-resistant keys. ```csharp var key = new DataKey(); block.SetData(key, state); if (block.TryGetData(key, out var existing)) { // use existing } ``` -------------------------------- ### Ordered List with Specific Starting Roman Numeral Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/ListExtraSpecs.md Illustrates starting a roman numeral ordered list from a specific numeral (e.g., 'ii'). The HTML includes 'type="i"' and 'start="2"'. ```markdown ii. First item iii. Second item ``` ```html
    1. First item
    2. Second item
    ``` -------------------------------- ### Enabling Media Support Extension Source: https://github.com/xoofx/markdig/blob/main/readme.md Shows how to enable the Media Support extension for rendering media URLs (like YouTube, Vimeo, mp4) as embedded media players. This extension is inspired by CommonMark discussions. ```csharp using Markdig; // ... var pipeline = new MarkdownPipelineBuilder() .UseMedia() .Build(); string markdown = "![My Video](https://www.youtube.com/watch?v=dQw4w9WgXcQ)"; string html = Markdown.ToHtml(markdown, pipeline); // html will render an embedded YouTube player. ``` -------------------------------- ### Multiple Nested Lists Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Example of a list with multiple nested unordered lists. ```markdown - a - b - c - d - e - f ``` -------------------------------- ### Nested Ordered Lists Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Example of nested ordered lists with varying indentation. ```markdown 1. a 2. b 3. c ``` -------------------------------- ### Applying Attributes to Headings Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/generic-attributes.md Example of adding an ID and a class to a Markdown heading. ```markdown ## My Section {\#section-1 .special} ``` -------------------------------- ### Add Custom Extension Benchmark Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/performance.md Example of how to add a benchmark test case for a custom Markdig extension within the benchmarks project. ```csharp [Benchmark] public string ConvertWithMyExtension() { return Markdown.ToHtml(MarkdownText, _pipelineWithMyExtension); } ``` -------------------------------- ### Markdown Syntax for Definition Lists Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/definition-lists.md Demonstrates the basic markdown syntax for creating definition lists with single and multiple definitions per term. ```markdown Term 1 : Definition of term 1. Term 2 : Definition of term 2. : Another definition of term 2. ``` -------------------------------- ### Unclosed Code Span Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md An example of an unclosed code span, resulting in literal backticks. ```Markdown `foo ``` -------------------------------- ### Rendering Markdown AST to Different Formats Source: https://github.com/xoofx/markdig/blob/main/site/docs/usage.md Demonstrates rendering the parsed Markdown AST to various formats including HTML, plain text, and normalized Markdown. Custom renderers can also be implemented. ```csharp // Render to HTML var html = document.ToHtml(pipeline); // Render to plain text var plainText = Markdown.ToPlainText(markdownText, pipeline); // Render to normalized Markdown var normalized = Markdown.Normalize(markdownText, pipeline: pipeline); // Render to a custom format Markdown.Convert(markdownText, myCustomRenderer, pipeline); ``` -------------------------------- ### Build Basic MarkdownPipeline Source: https://github.com/xoofx/markdig/blob/main/site/docs/usage.md Create an immutable MarkdownPipeline with advanced extensions and precise source location tracking enabled. The pipeline can be reused across threads. ```csharp var pipeline = new MarkdownPipelineBuilder() .UseAdvancedExtensions() // Enable extensions .UsePreciseSourceLocation() // Track precise source spans .Build(); // Produce the immutable pipeline ``` -------------------------------- ### Code Span with Adjacent Backticks Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Example of a code span containing adjacent backticks. ```Markdown `foo `` bar` ``` -------------------------------- ### Single Paragraph List Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Example of a list containing only a single paragraph, which is considered tight. ```markdown - a ``` -------------------------------- ### Example of Basic List Item Parsing Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Demonstrates how a sequence of lines with a list marker is parsed into an ordered list item with its contents, including paragraphs, indented code, and block quotes. ```markdown A paragraph with two lines. indented code > A block quote. . ``` ```html

    A paragraph with two lines.

    indented code
    

    A block quote.

    ``` -------------------------------- ### Applying Attributes to Blockquotes Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/generic-attributes.md Example of applying a custom class to a blockquote for distinct styling. ```markdown > A styled blockquote {\.fancy-quote} ``` -------------------------------- ### HTML Block with Closing Tag Only Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Shows an HTML block starting with only a closing tag. ```html *bar* ``` -------------------------------- ### Basic Pipe Table Syntax Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/tables.md Demonstrates the fundamental structure of a pipe table with a header and body rows. ```markdown | Name | Language | Stars | |----------|----------|-------| | Markdig | C# | 4.5k | | cmark | C | 1.6k | | markdown-it | JavaScript | 18k | ``` -------------------------------- ### Backtick Emphasis Example Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Demonstrates how backticks are used for inline code, including nested backticks. ```markdown `foo``bar`` ``` ```html

    `foobar

    ``` -------------------------------- ### Basic Emphasis and Strong Emphasis Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/RoundtripSpecs/CommonMark.md Demonstrates the basic rendering of emphasis and strong emphasis using asterisks. ```markdown *foo**bar*** ``` -------------------------------- ### Unused Link Reference Definition Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md An example of a link reference definition that is not used by any link in the document. ```markdown [foo]: /url . ``` -------------------------------- ### Empty Fenced Code Block Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Shows an example of a completely empty fenced code block. ```markdown ``` ``` ``` -------------------------------- ### Basic AutoLink Formatting Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/AutoLinks.md Demonstrates how common URL and email prefixes are converted into HTML links. This includes http, https, ftp, mailto, tel, and www. prefixes. ```markdown This is a http://www.google.com URL and https://www.google.com This is a ftp://test.com And a mailto:email@toto.com And a tel:+1555123456 And a plain www.google.com . ``` -------------------------------- ### Invalid Jira Link Example 4 Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/Specs/JiraLinks.md An invalid Jira link where the issue number is missing. ```markdown This is not JIRA- issue .

    This is not JIRA- issue

    ``` -------------------------------- ### Markdown Delimiter Run Examples: Both Left and Right-Flanking Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Benchmarks/spec.md Illustrates delimiter runs that satisfy conditions for both left-flanking and right-flanking, applicable in various emphasis scenarios. ```markdown abc***def "abc"_"def" ``` -------------------------------- ### Markdown Superscript Example Source: https://github.com/xoofx/markdig/blob/main/site/docs/extensions/emphasis-extras.md Illustrates using the caret symbol (^) to format text as superscript in Markdown. ```markdown 2^10^ is 1024. ``` -------------------------------- ### Enabling Definition Lists Extension Source: https://github.com/xoofx/markdig/blob/main/readme.md Shows how to enable the Definition Lists extension, which supports the syntax for creating definition lists as defined in PHP Markdown Extra. ```csharp using Markdig; // ... var pipeline = new MarkdownPipelineBuilder() .UseDefinitionLists() .Build(); string markdown = "Term 1\n: Definition 1\n\nTerm 2\n: Definition 2"; string html = Markdown.ToHtml(markdown, pipeline); // html will render a definition list. ``` -------------------------------- ### Markdown Heading Syntax (Setext Style) Source: https://github.com/xoofx/markdig/blob/main/src/Markdig.Tests/NormalizeSpecs/Headings.md Demonstrates the syntax for Setext-style headings using underlines. ```markdown Heading ======= Text after two newlines 1 ``` -------------------------------- ### IMarkdownExtension Interface Source: https://github.com/xoofx/markdig/blob/main/site/docs/advanced/creating-extensions.md Defines the interface for Markdig extensions, with methods for pipeline setup during build and rendering. ```csharp public interface IMarkdownExtension { void Setup(MarkdownPipelineBuilder pipeline); void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer); } ```