### 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
bar
baz
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 ``` ```htmlfoo→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 (| 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 . ``` ```htmlaaa
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| a | b |
|---|---|
| 0 | 1 |
| 3 |
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 |
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 |
The number of windows in my house is
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.AddIfNotAlreadyokay
``` -------------------------------- ### 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
```````````````````````````````` ``` ```markdown ```````````````````````````````` example 1. A paragraph with two lines. indented code > A block quote. .A block quote.
A paragraph with two lines.
indented code
A block quote.
foo
bar
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 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 ``` ```htmlFoo bar
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 ``` -------------------------------- ### 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 {.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 ``` ```htmlbar
``` -------------------------------- ### 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| A | B | C |
foo
bar
This is deleted text.
-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| a | b |
|---|---|
| 0 | 1 |
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 |
foo
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 ``` ```htmlfoo ***
``` ```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 DataKeyA paragraph with two lines.
indented code
``` -------------------------------- ### 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`` ``` ```htmlA block quote.
`foobar
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); } ```