MarkdownFencedBlockExtension Class

A block between an opening line and a closing line, such as !!! note and !!!. The construct is a MarkdownExtensionBlockSyntax: the opening fence, the rest of its line (the info), the content, and the closing fence.

public abstract class MarkdownFencedBlockExtension : MarkdownSyntaxExtension

Remarks

The parser calls MarkdownFencedBlockExtension.TryOpen on a line indented by 3 spaces or less whose first character is one of MarkdownFencedBlockExtension.TriggerCharacters, before the built-in blocks. The block ends at the line for which MarkdownFencedBlockExtension.TryClose returns a length, or at the end of its container, as a fenced code block. A closing fence closes the blocks in the content too, even a code block.

One instance parses every document, possibly on several threads at once: keep no state between calls, and use MarkdownSyntaxExtension.CreateState for the state of a document.

Inheritance
MarkdownSyntaxExtension MarkdownFencedBlockExtension

Constructors

NameDescription
MarkdownFencedBlockExtension(string, string, MarkdownFencedBlockContent)Initializes a new instance of the MarkdownFencedBlockExtension class.

MarkdownFencedBlockExtension(string, string, MarkdownFencedBlockContent)

MarkdownFencedBlockExtension.cs

Initializes a new instance of the MarkdownFencedBlockExtension class.

protected MarkdownFencedBlockExtension(string name, string triggerCharacters, MarkdownFencedBlockContent content)

Parameters

name string
The name of the extension, which the nodes of its blocks have.
triggerCharacters string
The characters that an opening fence can start with: not whitespace.
content MarkdownFencedBlockContent
What the lines between the fences are.

Exceptions

ArgumentException
name or triggerCharacters is empty, or triggerCharacters has whitespace.
ArgumentNullException
name or triggerCharacters is null.

Properties

NameDescription
CanInterruptParagraphGets a value indicating whether the block can start on the line after a paragraph, as a fenced code block can. When false, the line continues the paragraph.
ContentGets what the lines between the fences are.
ParseInfoAsInlinesGets a value indicating whether the info, the text after the opening fence, is read as inlines, such as emphasis: MarkdownExtensionBlockSyntax.Inlines.
TriggerCharactersGets the characters that an opening fence can start with.

CanInterruptParagraph

MarkdownFencedBlockExtension.cs

Gets a value indicating whether the block can start on the line after a paragraph, as a fenced code block can. When false, the line continues the paragraph.

public bool CanInterruptParagraph { get; init; }

Property value

bool

Gets what the lines between the fences are.

public MarkdownFencedBlockContent Content { get; }

Gets a value indicating whether the info, the text after the opening fence, is read as inlines, such as emphasis: MarkdownExtensionBlockSyntax.Inlines.

public bool ParseInfoAsInlines { get; init; }

Property value

bool

Gets the characters that an opening fence can start with.

public string TriggerCharacters { get; }

Property value

string

Methods

NameDescription
OnClosed(MarkdownFencedBlockContext)Called when the block is closed, during the reading of the blocks, to record what the block defines in the state of the document.
TryClose(ReadOnlySpan<char>, ReadOnlySpan<char>)Reads the closing fence of a block. The rest of the line after the fence must be whitespace.
TryOpen(ReadOnlySpan<char>)Reads the opening fence of a block.

OnClosed(MarkdownFencedBlockContext)

MarkdownFencedBlockExtension.cs

Called when the block is closed, during the reading of the blocks, to record what the block defines in the state of the document.

public virtual void OnClosed(ref MarkdownFencedBlockContext context)

Parameters

context MarkdownFencedBlockContext
The info and the lines of the block, and the state of the document.

TryClose(ReadOnlySpan<char>, ReadOnlySpan<char>)

Reads the closing fence of a block. The rest of the line after the fence must be whitespace.

public abstract int TryClose(ReadOnlySpan<char> line, ReadOnlySpan<char> openingFence)

Parameters

line ReadOnlySpan<char>
The line, from its first character that is not whitespace, without its line ending.
openingFence ReadOnlySpan<char>
The opening fence of the block.

Returns

int The length of the closing fence, the start of line, or 0 when the line does not close the block.

TryOpen(ReadOnlySpan<char>)

Reads the opening fence of a block.

public abstract int TryOpen(ReadOnlySpan<char> line)

Parameters

line ReadOnlySpan<char>
The line, from its first character that is not whitespace, without its line ending.

Returns

int The length of the opening fence, the start of line, or 0 when the line does not open a block.