MarkdownHtmlWriter Class

Writes the HTML of a node for a MarkdownHtmlNodeRenderer: text and attribute values escaped, URLs changed as the options of the renderer change them, the attributes of the node, and its content.

public sealed class MarkdownHtmlWriter

Remarks

MarkdownPlainTextRenderer uses the node renderers too: then MarkdownHtmlWriter.IsPlainText is true, the text is written as it is, and the HTML, the attributes and the URLs are not written.

Properties

NameDescription
IsPlainTextGets a value indicating whether the document is written as plain text, by MarkdownPlainTextRenderer.
OptionsGets the options of the renderer.

Gets a value indicating whether the document is written as plain text, by MarkdownPlainTextRenderer.

public bool IsPlainText { get; }

Property value

bool

Gets the options of the renderer.

public MarkdownHtmlRendererOptions Options { get; }

Methods

NameDescription
EnsureNewLine()Starts a new line, unless the output is empty or already ends with a line ending, as the renderer does between blocks.
WriteAttributeValue(ReadOnlySpan<char>)Writes the value of an attribute, between its quotes, with the characters of HTML escaped. Plain text does not write it.
WriteAttributes(MarkdownSyntaxNode, string?)Writes the attributes of the element of a node, each after a space, to write between the name of the tag and its >: its id, its classes and the other attributes of MarkdownExtensions.GenericAttributes, the attributes of MarkdownExtensions.Bootstrap and of MarkdownExtensions.Globalization, and the id of MarkdownHtmlRendererOptions.PragmaLines. Plain text does not write them.
WriteBlocks(IEnumerable<MarkdownBlockSyntax>)Writes blocks, offering each one to the node renderers.
WriteDefault(MarkdownSyntaxNode)Writes a block or an inline as the renderer writes it without node renderers, to add HTML around it. The nodes in it are still offered to the node renderers.
WriteInlines(IEnumerable<SyntaxNodeOrToken>)Writes inlines, such as the Inlines of a paragraph or of a heading, offering each inline node to the node renderers. The tokens are written as the renderer writes them: text escaped, line endings and line breaks.
WriteRawHtml(ReadOnlySpan<char>)Writes HTML as it is, such as tags. Plain text does not write it.
WriteText(ReadOnlySpan<char>)Writes text, with the characters of HTML escaped. Plain text writes it as it is.
WriteUrl(string)Writes a URL as the value of an attribute, as the renderer writes the URLs of the links: made absolute with MarkdownHtmlRendererOptions.BaseUrl, changed by MarkdownHtmlRendererOptions.LinkRewriter, percent-encoded, written empty when its scheme is not one of MarkdownHtmlRendererOptions.AllowedUrlSchemes, then escaped. Plain text does not write it.

EnsureNewLine()

MarkdownHtmlWriter.cs

Starts a new line, unless the output is empty or already ends with a line ending, as the renderer does between blocks.

public void EnsureNewLine()

WriteAttributeValue(ReadOnlySpan<char>)

MarkdownHtmlWriter.cs

Writes the value of an attribute, between its quotes, with the characters of HTML escaped. Plain text does not write it.

public void WriteAttributeValue(ReadOnlySpan<char> value)

Parameters

value ReadOnlySpan<char>

WriteAttributes(MarkdownSyntaxNode, string?)

MarkdownHtmlWriter.cs

Writes the attributes of the element of a node, each after a space, to write between the name of the tag and its >: its id, its classes and the other attributes of MarkdownExtensions.GenericAttributes, the attributes of MarkdownExtensions.Bootstrap and of MarkdownExtensions.Globalization, and the id of MarkdownHtmlRendererOptions.PragmaLines. Plain text does not write them.

public void WriteAttributes(MarkdownSyntaxNode node, string? classes = null)

Parameters

node MarkdownSyntaxNode
The node.
classes string?
The classes of the element, before the classes of the generic attributes, or null.

Exceptions

ArgumentNullException
node is null.

WriteBlocks(IEnumerable<MarkdownBlockSyntax>)

MarkdownHtmlWriter.cs

Writes blocks, offering each one to the node renderers.

public void WriteBlocks(IEnumerable<MarkdownBlockSyntax> blocks)

Parameters

blocks IEnumerable<MarkdownBlockSyntax>

Exceptions

ArgumentNullException
blocks is null.

WriteDefault(MarkdownSyntaxNode)

MarkdownHtmlWriter.cs

Writes a block or an inline as the renderer writes it without node renderers, to add HTML around it. The nodes in it are still offered to the node renderers.

public void WriteDefault(MarkdownSyntaxNode node)

Parameters

node MarkdownSyntaxNode

Exceptions

ArgumentNullException
node is null.
ArgumentException
node is not a block or an inline.

WriteInlines(IEnumerable<SyntaxNodeOrToken>)

MarkdownHtmlWriter.cs

Writes inlines, such as the Inlines of a paragraph or of a heading, offering each inline node to the node renderers. The tokens are written as the renderer writes them: text escaped, line endings and line breaks.

public void WriteInlines(IEnumerable<SyntaxNodeOrToken> inlines)

Parameters

inlines IEnumerable<SyntaxNodeOrToken>

Exceptions

ArgumentNullException
inlines is null.

WriteRawHtml(ReadOnlySpan<char>)

MarkdownHtmlWriter.cs

Writes HTML as it is, such as tags. Plain text does not write it.

public void WriteRawHtml(ReadOnlySpan<char> html)

Parameters

html ReadOnlySpan<char>

Remarks

The HTML is not checked: MarkdownParseOptions.DisableHtml, MarkdownExtensions.TagFilter and MarkdownHtmlRendererOptions.AttributeFilter apply to the Markdown, not to the HTML of node renderers. Escape the text that comes from the document with MarkdownHtmlWriter.WriteText or MarkdownHtmlWriter.WriteAttributeValue.

WriteText(ReadOnlySpan<char>)

MarkdownHtmlWriter.cs

Writes text, with the characters of HTML escaped. Plain text writes it as it is.

public void WriteText(ReadOnlySpan<char> text)

Parameters

text ReadOnlySpan<char>

WriteUrl(string)

MarkdownHtmlWriter.cs

Writes a URL as the value of an attribute, as the renderer writes the URLs of the links: made absolute with MarkdownHtmlRendererOptions.BaseUrl, changed by MarkdownHtmlRendererOptions.LinkRewriter, percent-encoded, written empty when its scheme is not one of MarkdownHtmlRendererOptions.AllowedUrlSchemes, then escaped. Plain text does not write it.

public void WriteUrl(string url)

Parameters

url string

Exceptions

ArgumentNullException
url is null.