MarkdownHtmlRendererOptions Class

Configures how MarkdownHtmlRenderer writes HTML.

public sealed class MarkdownHtmlRendererOptions : IEquatable<MarkdownHtmlRendererOptions>
Implements

Constructors

NameDescription
MarkdownHtmlRendererOptions()

MarkdownHtmlRendererOptions()

MarkdownHtmlRendererOptions.cs
public MarkdownHtmlRendererOptions()

No documentation is available.

Properties

NameDescription
AllowedUrlSchemesGets the schemes that the URLs of the links and of the images can have, such as http, https and mailto, or null to write every URL, as CommonMark does. A URL with another scheme, such as javascript: or data:, is written empty. A relative URL has no scheme and is always written.
AttributeFilterGets which attributes of MarkdownExtensions.GenericAttributes the renderer writes, by name. The id and the classes are always written.
BaseUrlGets the URL that the relative URLs of the links and of the images are relative to, or null to keep them relative.
DefaultGets the options used when none are given.
EscapeNonAsciiUrlCharactersGets a value indicating whether the characters of the URLs that are not ASCII are percent-encoded, as CommonMark does. Markdig keeps them for nonascii-noescape.
IdPrefixGets the prefix of the ids that the document sets, such as user-content- as GitHub writes them, or null for none: the ids of MarkdownExtensions.AutoIdentifiers and of MarkdownExtensions.GenericAttributes, the ids of the footnotes and of their references, and the links that the renderer writes to them. Several documents rendered on one page, such as comments, then have different ids.
LinkRelGets the rel attribute of the links, such as nofollow noopener, or null for none. The autolinks of email addresses between < and > have none.
LinkRewriterGets a function that changes the URLs of the links and of the images, after MarkdownHtmlRendererOptions.BaseUrl, or null.
MediaLinksGets how the images of audio, video, and of the sites that host them are rendered with MarkdownExtensions.MediaLinks.
NodeRenderersGets the renderers that write some nodes instead of the built-in rendering, such as the code blocks of a language. Each block and each inline is offered to them in order, and the first one that writes it wins.
PragmaLinesGets a value indicating whether the element of the first block of each line has the id pragma-line-N, where N is the zero-based number of the line, as Markdig does with pragma lines: an editor can scroll its preview to a line. A block whose id is set gets an anchor with the id instead.
SmartyPantsGets the HTML that the renderer writes for each character of MarkdownExtensions.SmartyPants, written as it is: by default, the entities &lsquo;, &rsquo;, &ldquo;, &rdquo;, &laquo;, &raquo;, &hellip;, &ndash; and &mdash;.

Gets the schemes that the URLs of the links and of the images can have, such as http, https and mailto, or null to write every URL, as CommonMark does. A URL with another scheme, such as javascript: or data:, is written empty. A relative URL has no scheme and is always written.

public ImmutableArray<string>? AllowedUrlSchemes { get; init; }

Property value

ImmutableArray<string>?

Remarks

The scheme is compared ignoring case, and read from the URL that is written, after MarkdownHtmlRendererOptions.BaseUrl and MarkdownHtmlRendererOptions.LinkRewriter, as a browser reads it: the spaces and the control characters at the start of the URL, and its tabs and line endings, are ignored.

The filter applies to the URLs that the renderer writes, including the ones of MarkdownHtmlWriter.WriteUrl. It does not apply to raw HTML, nor to the generic attributes that MarkdownHtmlRendererOptions.AttributeFilter allows: it complements an HTML sanitizer, it does not replace one.

Gets which attributes of MarkdownExtensions.GenericAttributes the renderer writes, by name. The id and the classes are always written.

public Func<string, bool> AttributeFilter { get; init; }

Property value

Func<string, bool>

Remarks

By default, only the attributes that describe the content are written, such as title, lang or aria-*: event handlers, URL attributes, style or data-* can run script or change the page when the Markdown is not trusted.

Gets the URL that the relative URLs of the links and of the images are relative to, or null to keep them relative.

public Uri? BaseUrl { get; init; }

Property value

Uri?

Gets the options used when none are given.

public static MarkdownHtmlRendererOptions Default { get; }

EscapeNonAsciiUrlCharacters

MarkdownHtmlRendererOptions.cs

Gets a value indicating whether the characters of the URLs that are not ASCII are percent-encoded, as CommonMark does. Markdig keeps them for nonascii-noescape.

public bool EscapeNonAsciiUrlCharacters { get; init; }

Property value

bool

Gets the prefix of the ids that the document sets, such as user-content- as GitHub writes them, or null for none: the ids of MarkdownExtensions.AutoIdentifiers and of MarkdownExtensions.GenericAttributes, the ids of the footnotes and of their references, and the links that the renderer writes to them. Several documents rendered on one page, such as comments, then have different ids.

public string? IdPrefix { get; init; }

Property value

string?

Remarks

The links that the text writes, such as [a](#b), and the ids of MarkdownHtmlRendererOptions.PragmaLines are kept as they are.

Example

var options = new MarkdownParseOptions { Extensions = MarkdownExtensions.AutoIdentifiers | MarkdownExtensions.Footnotes };
var tree = MarkdownSyntaxTree.ParseText("# Notes\n\nSee[^1].\n\n[^1]: A note.\n", options);

// Several documents rendered on one page, such as comments, have different ids
var html = MarkdownHtmlRenderer.ToHtml(tree, new MarkdownHtmlRendererOptions { IdPrefix = "comment-1-" });
Assert.Equal("<h1 id=\"comment-1-notes\">Notes</h1>\n<p>See<a id=\"comment-1-fnref:1\" href=\"#comment-1-fn:1\" class=\"footnote-ref\"><sup>1</sup></a>.</p>\n<div class=\"footnotes\">\n<hr />\n<ol>\n<li id=\"comment-1-fn:1\">\n<p>A note.<a href=\"#comment-1-fnref:1\" class=\"footnote-back-ref\">&#8617;</a></p>\n</li>\n</ol>\n</div>\n", html);

Gets the rel attribute of the links, such as nofollow noopener, or null for none. The autolinks of email addresses between < and > have none.

public string? LinkRel { get; init; }

Property value

string?

Gets a function that changes the URLs of the links and of the images, after MarkdownHtmlRendererOptions.BaseUrl, or null.

public Func<string, string>? LinkRewriter { get; init; }

Property value

Func<string, string>?

Gets the renderers that write some nodes instead of the built-in rendering, such as the code blocks of a language. Each block and each inline is offered to them in order, and the first one that writes it wins.

public ImmutableArray<MarkdownHtmlNodeRenderer> NodeRenderers { get; init; }

Gets a value indicating whether the element of the first block of each line has the id pragma-line-N, where N is the zero-based number of the line, as Markdig does with pragma lines: an editor can scroll its preview to a line. A block whose id is set gets an anchor with the id instead.

public bool PragmaLines { get; init; }

Property value

bool

Gets the HTML that the renderer writes for each character of MarkdownExtensions.SmartyPants, written as it is: by default, the entities &lsquo;, &rsquo;, &ldquo;, &rdquo;, &laquo;, &raquo;, &hellip;, &ndash; and &mdash;.

public IReadOnlyDictionary<MarkdownSmartyPant, string> SmartyPants { get; init; }

Property value

IReadOnlyDictionary<MarkdownSmartyPant, string>

Remarks

A character that the mapping does not have is written as the default entity.

Methods

NameDescription
Equals(MarkdownHtmlRendererOptions?)
Equals(object?)
GetHashCode()
IsSafeAttributeName(string)Gets whether an attribute only describes the content: whatever its value, it cannot run script or load a resource.
ToString()

Equals overloads

Equals(MarkdownHtmlRendererOptions?)

public bool Equals(MarkdownHtmlRendererOptions? other)
Parameters
other MarkdownHtmlRendererOptions?
Returns

bool

No documentation is available.

Equals(object?)

public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetHashCode()

public override int GetHashCode()

Returns

int

No documentation is available.

IsSafeAttributeName(string)

MarkdownHtmlRendererOptions.cs

Gets whether an attribute only describes the content: whatever its value, it cannot run script or load a resource.

public static bool IsSafeAttributeName(string name)

Parameters

name string

Returns

bool

Exceptions

ArgumentNullException
name is null.

ToString()

public override string ToString()

Returns

string

No documentation is available.

Operators

NameDescription
operator ==(MarkdownHtmlRendererOptions?, MarkdownHtmlRendererOptions?)
operator !=(MarkdownHtmlRendererOptions?, MarkdownHtmlRendererOptions?)

operator ==(MarkdownHtmlRendererOptions?, MarkdownHtmlRendererOptions?)

public static bool operator ==(MarkdownHtmlRendererOptions? left, MarkdownHtmlRendererOptions? right)

No documentation is available.

operator !=(MarkdownHtmlRendererOptions?, MarkdownHtmlRendererOptions?)

public static bool operator !=(MarkdownHtmlRendererOptions? left, MarkdownHtmlRendererOptions? right)

No documentation is available.