MarkdownBlockSyntax Class
A block of a document: a paragraph, a heading, a list, a block quote, a code block...
public abstract class MarkdownBlockSyntax : MarkdownSyntaxNode- Inheritance
MarkdownSyntaxNodeMarkdownBlockSyntax
Methods
| Name | Description |
|---|---|
| GetGenericAttributes() | Gets the generic attributes of the block, which the HTML renderer writes on its element. |
| WithGenericAttributes(MarkdownGenericAttributes?) | Returns this block with the generic attributes attributes, or itself when it has them. |
GetGenericAttributes()
MarkdownBlockSyntax.csGets the generic attributes of the block, which the HTML renderer writes on its element.
public MarkdownGenericAttributes GetGenericAttributes()Returns
MarkdownGenericAttributes The attributes, or MarkdownGenericAttributes.Empty when the block has none.
Remarks
The attributes are read with MarkdownExtensions.GenericAttributes, from every {...} that is for the block: the ones at the end of the first line of a heading or of a fenced block, at the end of a paragraph, or on the line before the block. As in the HTML renderer, the id of the last ones wins, the classes are added, and a property is kept from the first attributes that have it. The attributes of all the blocks of a document are read once, the first time the attributes of one of them are read. Change them with MarkdownBlockSyntax.WithGenericAttributes, MarkdownSyntaxTree.WithGenericAttributes or MarkdownSyntaxTreeEditor.SetGenericAttributes.
WithGenericAttributes(MarkdownGenericAttributes?)
MarkdownBlockSyntax.csReturns this block with the generic attributes attributes, or itself when it has them.
public MarkdownBlockSyntax WithGenericAttributes(MarkdownGenericAttributes? attributes)Parameters
attributesMarkdownGenericAttributes?- The attributes of the block, or
nullto remove them.
Returns
MarkdownBlockSyntax A copy of the block, in no tree, whose MarkdownBlockSyntax.GetGenericAttributes returns attributes once it replaces this block.
Exceptions
ArgumentExceptionattributescannot be written, such as a class with whitespace or an attribute name that starts with a digit.InvalidOperationException- The block is in no tree, or its tree is parsed without
MarkdownExtensions.GenericAttributes, or the attributes cannot be written in the block: the block is of another kind, such as a list or a block quote, whose attributes are on a line before it, it has attributes on a line before it or before a line break of its text, or its text would not read them as its attributes, such as a heading that has a{, or the attributes would change how the blocks around it are read. Change them withMarkdownSyntaxTree.WithGenericAttributes.
Remarks
Unlike MarkdownSyntaxTree.WithGenericAttributes, which parses the document again, this method only changes the block, so it can be called for many blocks, such as in a MarkdownSyntaxRewriter: replace this block with the copy, with SyntaxNodeExtensions.ReplaceNode, or return the copy from the rewriter. The block has to be in a tree, so that its attributes and the options of the tree are known.
The attributes are written in the block, where Markdig reads them: at the end of the first line of a heading, of a fenced code block, of a math block and of a custom container, and at the end of the last line of a paragraph or of the text of a setext heading. The {...} that are for the block are removed: they have to be in the block, at the end of a line that does not continue the text of a paragraph. To check that the copy is the block that parsing its text gives, with the attributes, and that the attributes do not change how the text around it is read, only the block at the top of the document that contains the block is parsed again, with the blocks before and after it.