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 MarkdownHtmlWriterRemarks
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
| Name | Description |
|---|---|
| IsPlainText | Gets a value indicating whether the document is written as plain text, by MarkdownPlainTextRenderer. |
| Options | Gets the options of the renderer. |
IsPlainText
MarkdownHtmlWriter.csGets a value indicating whether the document is written as plain text, by MarkdownPlainTextRenderer.
public bool IsPlainText { get; }Property value
Options
MarkdownHtmlWriter.csMethods
| Name | Description |
|---|---|
| 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.csStarts 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.csWrites 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
valueReadOnlySpan<char>
WriteAttributes(MarkdownSyntaxNode, string?)
MarkdownHtmlWriter.csWrites 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
nodeMarkdownSyntaxNode- The node.
classesstring?- The classes of the element, before the classes of the generic attributes, or
null.
Exceptions
ArgumentNullExceptionnodeisnull.
WriteBlocks(IEnumerable<MarkdownBlockSyntax>)
MarkdownHtmlWriter.csWrites blocks, offering each one to the node renderers.
public void WriteBlocks(IEnumerable<MarkdownBlockSyntax> blocks)WriteDefault(MarkdownSyntaxNode)
MarkdownHtmlWriter.csWrites 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
nodeMarkdownSyntaxNode
Exceptions
ArgumentNullExceptionnodeisnull.ArgumentExceptionnodeis not a block or an inline.
WriteInlines(IEnumerable<SyntaxNodeOrToken>)
MarkdownHtmlWriter.csWrites 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)WriteRawHtml(ReadOnlySpan<char>)
MarkdownHtmlWriter.csWrites HTML as it is, such as tags. Plain text does not write it.
public void WriteRawHtml(ReadOnlySpan<char> html)Parameters
htmlReadOnlySpan<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.csWrites text, with the characters of HTML escaped. Plain text writes it as it is.
public void WriteText(ReadOnlySpan<char> text)Parameters
textReadOnlySpan<char>
WriteUrl(string)
MarkdownHtmlWriter.csWrites 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.