Markdown.TryParseCodeFence Method
- Namespace
- Kampute.DocToolkit.Support
- Assembly
- Kampute.DocToolkit.dll
Definition
Attempts to parse a line of Markdown as a code fence, which opens or closes a fenced code block.
public static bool TryParseCodeFence(
ReadOnlySpan<char> line,
out char fenceChar,
out int fenceLength,
out ReadOnlySpan<char> infoString)Parameters
lineReadOnlySpan<char>- The line to parse, without its line break.
fenceCharchar- When this method returns, contains the fence character ('`' or '~') if the line is a code fence; otherwise, '\0'.
fenceLengthint- When this method returns, contains the number of fence characters if the line is a code fence; otherwise, 0.
infoStringReadOnlySpan<char>- When this method returns, contains the text after the fence characters without leading and trailing whitespace, such as the language of the code, if the line is a code fence; otherwise, an empty span.

A fenced code block is closed by a fence that uses the same character, is at least as long as the opening fence, and has an empty info string. Determining whether a line closes a block is left to the caller, which knows the opening fence.