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

NameDescription
MarkdownSyntaxRewriter()

MarkdownSyntaxRewriter()

public MarkdownSyntaxRewriter()

No documentation is available.

Methods

NameDescription
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.cs
public override SyntaxNode? DefaultVisit(MarkdownSyntaxNode node)

Parameters

node MarkdownSyntaxNode

Returns

SyntaxNode?

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.cs

Rewrites each trivium of a list, dropping the ones a rewrite turned into the default trivium.

public virtual SyntaxTriviaList VisitList(SyntaxTriviaList list)

Parameters

list SyntaxTriviaList

Returns

SyntaxTriviaList

VisitToken(SyntaxToken)

MarkdownSyntaxRewriter.cs

Rewrites a token, putting the trivia around it through MarkdownSyntaxRewriter.VisitTrivia.

public virtual SyntaxToken VisitToken(SyntaxToken token)

Parameters

token SyntaxToken

Returns

SyntaxToken

VisitTrivia(SyntaxTrivia)

MarkdownSyntaxRewriter.cs
public virtual SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)

Parameters

trivia SyntaxTrivia

Returns

SyntaxTrivia

No documentation is available.