BlockProcessor Class

The block processor.

public class BlockProcessor

Constructors

NameDescription
BlockProcessor(MarkdownDocument, BlockParserList, MarkdownParserContext?, bool)Initializes a new instance of the BlockProcessor class.

BlockProcessor(MarkdownDocument, BlockParserList, MarkdownParserContext?, bool)

BlockProcessor.cs

Initializes a new instance of the BlockProcessor class.

public BlockProcessor(MarkdownDocument document, BlockParserList parsers, MarkdownParserContext? context, bool trackTrivia = false)

Parameters

document MarkdownDocument
The document to build blocks into.
parsers BlockParserList
The list of parsers.
context MarkdownParserContext?
A parser context used for the parsing.
trackTrivia bool
Whether to parse trivia such as whitespace, extra heading characters and unescaped string values.

Exceptions

ArgumentNullException

Properties

NameDescription
ColumnGets or sets the column.
ColumnBeforeIndentGets the column position before the indent occurred.
ContextGets the parser context or null if none is available.
CurrentBlockGets the last block that is opened.
CurrentCharGets the current character being processed.
CurrentContainerGets the current active container.
CurrentLineStartPositionGets or sets the current line start position.
DocumentGets the root document.
IndentGets the current indent position (number of columns between the previous indent and the current position).
IsBlankLineGets a value indicating whether the line is blank (valid only after BlockProcessor.ParseIndent has been called).
IsCodeIndentGets a value indicating whether a code indentation is at the beginning of the line being processed.
IsLazyGets a boolean indicating whether the current line being parsed is lazy continuation.
LastBlockGets the last block that is created.
LineIndexGets the index of the line in the source text.
LinesBeforeGets or sets the stack of empty lines not yet assigned to any Block. An entry may contain an empty StringSlice. In that case the StringSlice.NewLine is relevant. Otherwise, the StringSlice entry will contain trivia.
NewBlocksGets the new blocks to push. A BlockParser is required to push new blocks that it creates to this property.
NextContinueGets the next block in a BlockParser.TryContinue.
ParsersGets the list of BlockParsers configured with this parser state.
SkipFirstUnwindSpaceGets or sets the skip first unwind space.
StartGets the position of the current character in the line being processed.
StartBeforeIndentGets the character position before the indent occurred.
TrackTriviaTrue to parse trivia such as whitespace, extra heading characters and unescaped string values.
TriviaStartGets or sets the position of the first character trivia is encountered and not yet assigned to a syntax node. Trivia: only used when BlockProcessor.TrackTrivia is enabled, otherwise 0.

Gets or sets the column.

public int Column { get; set; }

Property value

int

ColumnBeforeIndent

BlockProcessor.cs

Gets the column position before the indent occurred.

public int ColumnBeforeIndent { get; }

Property value

int

Gets the parser context or null if none is available.

public MarkdownParserContext? Context { get; }

CurrentBlock

BlockProcessor.cs

Gets the last block that is opened.

public Block? CurrentBlock { get; }

Property value

Block?

Gets the current character being processed.

public char CurrentChar { get; }

Property value

char

CurrentContainer

BlockProcessor.cs

Gets the current active container.

public ContainerBlock? CurrentContainer { get; }

Property value

ContainerBlock?

CurrentLineStartPosition

BlockProcessor.cs

Gets or sets the current line start position.

public int CurrentLineStartPosition { get; }

Property value

int

Gets the root document.

public MarkdownDocument Document { get; }

Property value

MarkdownDocument

Gets the current indent position (number of columns between the previous indent and the current position).

public int Indent { get; }

Property value

int

Gets a value indicating whether the line is blank (valid only after BlockProcessor.ParseIndent has been called).

public bool IsBlankLine { get; }

Property value

bool

IsCodeIndent

BlockProcessor.cs

Gets a value indicating whether a code indentation is at the beginning of the line being processed.

public bool IsCodeIndent { get; }

Property value

bool

Gets a boolean indicating whether the current line being parsed is lazy continuation.

public bool IsLazy { get; }

Property value

bool

Gets the last block that is created.

public Block? LastBlock { get; }

Property value

Block?

Gets the index of the line in the source text.

public int LineIndex { get; set; }

Property value

int

Gets or sets the stack of empty lines not yet assigned to any Block. An entry may contain an empty StringSlice. In that case the StringSlice.NewLine is relevant. Otherwise, the StringSlice entry will contain trivia.

public List<StringSlice>? LinesBefore { get; set; }

Property value

List<StringSlice>?

Gets the new blocks to push. A BlockParser is required to push new blocks that it creates to this property.

public Stack<Block> NewBlocks { get; }

Property value

Stack<Block>

NextContinue

BlockProcessor.cs

Gets the next block in a BlockParser.TryContinue.

public Block? NextContinue { get; }

Property value

Block?

Gets the list of BlockParsers configured with this parser state.

public BlockParserList Parsers { get; }

Property value

BlockParserList

SkipFirstUnwindSpace

BlockProcessor.cs

Gets or sets the skip first unwind space.

public bool SkipFirstUnwindSpace { get; set; }

Property value

bool

Gets the position of the current character in the line being processed.

public int Start { get; }

Property value

int

StartBeforeIndent

BlockProcessor.cs

Gets the character position before the indent occurred.

public int StartBeforeIndent { get; }

Property value

int

True to parse trivia such as whitespace, extra heading characters and unescaped string values.

public bool TrackTrivia { get; }

Property value

bool

Gets or sets the position of the first character trivia is encountered and not yet assigned to a syntax node. Trivia: only used when BlockProcessor.TrackTrivia is enabled, otherwise 0.

public int TriviaStart { get; set; }

Property value

int

Methods

NameDescription
Close(Block)Force closing the specified block.
CreateChild()Performs the create child operation.
Discard(Block)Discards the specified block from the stack, remove from its parent.
GetCurrentContainerOpened()Get the current Container that is currently opened
GoToCodeIndent(int)Moves to the position to the code indent (BlockProcessor.ColumnBeforeIndent + 4 spaces).
GoToColumn(int)Moves to the position to the specified column position, taking into account spaces in tabs.
IsOpen(Block)Checks whether the specified block is currently part of the open block stack.
NextChar()Returns the next character in the line being processed. Update BlockProcessor.Start and BlockProcessor.Column.
NextColumn()Returns the next character in the line taking into space taken by tabs. Update BlockProcessor.Start and BlockProcessor.Column.
Open(Block)Opens the specified block.
ParseIndent()Parses the indentation from the current position in the line, updating BlockProcessor.StartBeforeIndent, BlockProcessor.ColumnBeforeIndent, BlockProcessor.Start and BlockProcessor.Column accordingly taking into account space taken by tabs.
PeekChar(int)Peeks a character at the specified offset from the current position in the line.
ProcessLine(StringSlice)Processes a new line.
ProcessLinePart(StringSlice, int)Processes part of a line.
ReleaseChild()Performs the release child operation.
RestartIndent()Restarts the indent from the current position.
TakeLinesBefore()Takes the current stack of BlockProcessor.LinesBefore to assign it to a Block. Afterwards, BlockProcessor.LinesBefore is set to null.
TryDiscard(Block)Tries to discard the specified block from the open stack and remove it from its parent.
UnwindAllIndents()Unwind any previous indent from the current character back to the first space.
UseTrivia(int)Returns trivia that has not yet been assigned to any node and advances the position of trivia to the ending position.

Close(Block)

BlockProcessor.cs

Force closing the specified block.

public void Close(Block block)

Parameters

block Block
The block.

CreateChild()

BlockProcessor.cs

Performs the create child operation.

public BlockProcessor CreateChild()

Discard(Block)

BlockProcessor.cs

Discards the specified block from the stack, remove from its parent.

public void Discard(Block block)

Parameters

block Block
The block.

GetCurrentContainerOpened()

BlockProcessor.cs

Get the current Container that is currently opened

public ContainerBlock GetCurrentContainerOpened()

Returns

ContainerBlock The current Container that is currently opened

GoToCodeIndent(int)

BlockProcessor.cs

Moves to the position to the code indent (BlockProcessor.ColumnBeforeIndent + 4 spaces).

public void GoToCodeIndent(int columnOffset = 0)

Parameters

columnOffset int
The column offset to apply to this indent.

GoToColumn(int)

BlockProcessor.cs

Moves to the position to the specified column position, taking into account spaces in tabs.

public void GoToColumn(int newColumn)

Parameters

newColumn int
The new column position to move the cursor to.

IsOpen(Block)

BlockProcessor.cs

Checks whether the specified block is currently part of the open block stack.

public bool IsOpen(Block block)

Parameters

block Block
The block to check.

Returns

bool true if the block is open; otherwise false.

Returns the next character in the line being processed. Update BlockProcessor.Start and BlockProcessor.Column.

public char NextChar()

Returns

char The next character or `\0` if end of line is reached

NextColumn()

BlockProcessor.cs

Returns the next character in the line taking into space taken by tabs. Update BlockProcessor.Start and BlockProcessor.Column.

public void NextColumn()

Opens the specified block.

public void Open(Block block)

Parameters

block Block
The block.

Exceptions

ArgumentNullException
ArgumentException
The block must be opened

ParseIndent()

BlockProcessor.cs

Parses the indentation from the current position in the line, updating BlockProcessor.StartBeforeIndent, BlockProcessor.ColumnBeforeIndent, BlockProcessor.Start and BlockProcessor.Column accordingly taking into account space taken by tabs.

public void ParseIndent()

PeekChar(int)

BlockProcessor.cs

Peeks a character at the specified offset from the current position in the line.

public char PeekChar(int offset)

Parameters

offset int
The offset.

Returns

char A character peeked at the specified offset

ProcessLine(StringSlice)

BlockProcessor.cs

Processes a new line.

public void ProcessLine(StringSlice newLine)

Parameters

newLine StringSlice
The new line.

ProcessLinePart(StringSlice, int)

BlockProcessor.cs

Processes part of a line.

public void ProcessLinePart(StringSlice line, int column)

Parameters

line StringSlice
The line.
column int
The column.

ReleaseChild()

BlockProcessor.cs

Performs the release child operation.

public void ReleaseChild()

RestartIndent()

BlockProcessor.cs

Restarts the indent from the current position.

public void RestartIndent()

TakeLinesBefore()

BlockProcessor.cs

Takes the current stack of BlockProcessor.LinesBefore to assign it to a Block. Afterwards, BlockProcessor.LinesBefore is set to null.

public List<StringSlice>? TakeLinesBefore()

Returns

List<StringSlice>? The pending list of lines before the current block, or null if none.

TryDiscard(Block)

BlockProcessor.cs

Tries to discard the specified block from the open stack and remove it from its parent.

public bool TryDiscard(Block block)

Parameters

block Block
The block to discard.

Returns

bool true if the block was discarded; otherwise false.

Exceptions

ArgumentNullException
Thrown when block is null.

UnwindAllIndents()

BlockProcessor.cs

Unwind any previous indent from the current character back to the first space.

public void UnwindAllIndents()

UseTrivia(int)

BlockProcessor.cs

Returns trivia that has not yet been assigned to any node and advances the position of trivia to the ending position.

public StringSlice UseTrivia(int end)

Parameters

end int
End position of the trivia

Returns

StringSlice

Fields

NameDescription
LineThe current line being processed.

Line

The current line being processed.

public StringSlice Line