Markdown.Encode Method

Namespace
Kampute.DocToolkit.Support
Assembly
  • Kampute.DocToolkit.dll
Markdown.Encode(string, bool)Encodes Markdown special characters in the given text.
Markdown.Encode(ReadOnlySpan<char>, TextWriter, bool)Encodes Markdown special characters in the given text and writes the result to the specified TextWriter.

Markdown.Encode(string, bool)

Encodes Markdown special characters in the given text.
public static string Encode(string text, bool atLineStart = true)

Parameters

text string
The text to encode.
atLineStart bool optional
Indicates whether the text is at the start of a line (ignoring leading whitespace).

Returns

string
A string with Markdown special characters escaped.

Exceptions

ArgumentNullException
Thrown when text is null.

Remarks

If atLineStart is true, the method escapes Markdown characters that have special meaning at the start of a line. Otherwise, these characters are escaped only if they are special in other contexts.

Encoding behavior adjusts dynamically, treating newlines as line breaks and ignoring leading whitespace when determining whether a character appears at the start of a line.

Markdown.Encode(ReadOnlySpan<char>, TextWriter, bool)

Encodes Markdown special characters in the given text and writes the result to the specified TextWriter.
public static void Encode(ReadOnlySpan<char> text, TextWriter output, bool atLineStart = true)

Parameters

text ReadOnlySpan<char>
The text to encode.
output TextWriter
The TextWriter to write the encoded text to.
atLineStart bool optional
Indicates whether the text is at the start of a line (ignoring leading whitespace).

Exceptions

ArgumentNullException
Thrown when output is null.

Remarks

If atLineStart is true, the method escapes Markdown characters that have special meaning at the start of a line. Otherwise, these characters are escaped only if they are special in other contexts.

Encoding behavior adjusts dynamically, treating newlines as line breaks and ignoring leading whitespace when determining whether a character appears at the start of a line.