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

line ReadOnlySpan<char>
The line to parse, without its line break.
fenceChar char
When this method returns, contains the fence character ('`' or '~') if the line is a code fence; otherwise, '\0'.
fenceLength int
When this method returns, contains the number of fence characters if the line is a code fence; otherwise, 0.
infoString ReadOnlySpan<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.

Returns

bool
true if the line is a code fence; otherwise, false.

Remarks

A code fence is a sequence of at least three backticks or three tildes, indented by no more than three spaces. The info string of a backtick fence cannot contain backticks.

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.