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 : MarkdownSyntaxExtensionRemarks
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
MarkdownSyntaxExtensionMarkdownFencedBlockExtension
Constructors
| Name | Description |
|---|---|
| MarkdownFencedBlockExtension(string, string, MarkdownFencedBlockContent) | Initializes a new instance of the MarkdownFencedBlockExtension class. |
MarkdownFencedBlockExtension(string, string, MarkdownFencedBlockContent)
MarkdownFencedBlockExtension.csInitializes a new instance of the MarkdownFencedBlockExtension class.
protected MarkdownFencedBlockExtension(string name, string triggerCharacters, MarkdownFencedBlockContent content)Parameters
namestring- The name of the extension, which the nodes of its blocks have.
triggerCharactersstring- The characters that an opening fence can start with: not whitespace.
contentMarkdownFencedBlockContent- What the lines between the fences are.
Exceptions
ArgumentExceptionnameortriggerCharactersis empty, ortriggerCharactershas whitespace.ArgumentNullExceptionnameortriggerCharactersisnull.
Properties
| Name | Description |
|---|---|
| CanInterruptParagraph | 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. |
| Content | Gets what the lines between the fences are. |
| ParseInfoAsInlines | Gets a value indicating whether the info, the text after the opening fence, is read as inlines, such as emphasis: MarkdownExtensionBlockSyntax.Inlines. |
| TriggerCharacters | Gets the characters that an opening fence can start with. |
CanInterruptParagraph
MarkdownFencedBlockExtension.csGets what the lines between the fences are.
public MarkdownFencedBlockContent Content { get; }Property value
ParseInfoAsInlines
MarkdownFencedBlockExtension.csGets 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
TriggerCharacters
MarkdownFencedBlockExtension.csMethods
| Name | Description |
|---|---|
| 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.csCalled 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
contextMarkdownFencedBlockContext- 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
lineReadOnlySpan<char>- The line, from its first character that is not whitespace, without its line ending.
openingFenceReadOnlySpan<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
lineReadOnlySpan<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.