MarkdownSyntaxRewriter Class
Builds a new tree by visiting an old one and returning replacements.
public class MarkdownSyntaxRewriter : MarkdownSyntaxVisitor<SyntaxNode?>Remarks
Every node is rewritten the same way: its children are visited, a child for which the rewrite returns null is removed, and a node whose children all come back unchanged is returned as it was, so rewriting a tree and changing nothing in it costs nothing and keeps every node. The text of the removed nodes goes with them, the trivia included: removing a block removes the line endings and the markers of its lines too. The content of the cells of a grid table is not part of the tree, so it is not rewritten: the table is a node whose lines are tokens, which a rewrite can replace as a whole.
Example
private sealed class RemoveHtml : MarkdownSyntaxRewriter
{
public override SyntaxNode? VisitMarkdownHtmlBlock(MarkdownHtmlBlockSyntax node) => null;
public override SyntaxNode? VisitMarkdownRawHtml(MarkdownRawHtmlSyntax node) => null;
}- Inheritance
MarkdownSyntaxVisitor<SyntaxNode?>MarkdownSyntaxRewriter
Constructors
| Name | Description |
|---|---|
| MarkdownSyntaxRewriter() |
MarkdownSyntaxRewriter()
public MarkdownSyntaxRewriter()No documentation is available.
Methods
| Name | Description |
|---|---|
| DefaultVisit(MarkdownSyntaxNode) | |
| VisitList(SyntaxTriviaList) | Rewrites each trivium of a list, dropping the ones a rewrite turned into the default trivium. |
| VisitToken(SyntaxToken) | Rewrites a token, putting the trivia around it through MarkdownSyntaxRewriter.VisitTrivia. |
| VisitTrivia(SyntaxTrivia) |
DefaultVisit(MarkdownSyntaxNode)
MarkdownSyntaxRewriter.cspublic override SyntaxNode? DefaultVisit(MarkdownSyntaxNode node)Parameters
nodeMarkdownSyntaxNode
Returns
Exceptions
InsufficientExecutionStackException- The document is nested too deeply to rewrite.
InvalidOperationException- A rewrite returned a node that is not a Markdown node.
VisitList(SyntaxTriviaList)
MarkdownSyntaxRewriter.csRewrites each trivium of a list, dropping the ones a rewrite turned into the default trivium.
public virtual SyntaxTriviaList VisitList(SyntaxTriviaList list)VisitToken(SyntaxToken)
MarkdownSyntaxRewriter.csRewrites a token, putting the trivia around it through MarkdownSyntaxRewriter.VisitTrivia.
public virtual SyntaxToken VisitToken(SyntaxToken token)VisitTrivia(SyntaxTrivia)
MarkdownSyntaxRewriter.cspublic virtual SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)No documentation is available.