InlineProcessor Class

The inline parser state used by all InlineParser.

public class InlineProcessor

Constructors

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

InlineProcessor(MarkdownDocument, InlineParserList, bool, MarkdownParserContext?, bool)

InlineProcessor.cs

Initializes a new instance of the InlineProcessor class.

public InlineProcessor(MarkdownDocument document, InlineParserList parsers, bool preciseSourcelocation, MarkdownParserContext? context, bool trackTrivia = false)

Parameters

document MarkdownDocument
The document.
parsers InlineParserList
The parsers.
preciseSourcelocation bool
A value indicating whether to provide precise source location.
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
BlockGets the current block being processed.
BlockNewGets or sets the new block to replace the block being processed.
ContextGets the parser context or null if none is available.
DebugLogGets or sets the debug log writer. No log if null.
DocumentGets the root document.
InlineGets or sets the current inline. Used by InlineParser to return a new inline if match was successfull
LineIndexGets or sets the index of the line from the begining of the document being processed.
LiteralInlineParserGets the literal inline parser.
ParserStatesGets the parser states that can be used by InlineParser using their ParserBase<TProcessor>.Index property.
ParsersGets the list of inline parsers.
PreciseSourceLocationGets a value indicating whether to provide precise source location.
RootGets the root container of the current InlineProcessor.Block.
TrackTriviaTrue to parse trivia such as whitespace, extra heading characters and unescaped string values.

Gets the current block being processed.

public LeafBlock? Block { get; }

Property value

LeafBlock?

Gets or sets the new block to replace the block being processed.

public Block? BlockNew { get; set; }

Property value

Block?

Gets the parser context or null if none is available.

public MarkdownParserContext? Context { get; }

Gets or sets the debug log writer. No log if null.

public TextWriter? DebugLog { get; set; }

Property value

TextWriter?

Gets the root document.

public MarkdownDocument Document { get; }

Property value

MarkdownDocument

Gets or sets the current inline. Used by InlineParser to return a new inline if match was successfull

public Inline? Inline { get; set; }

Property value

Inline?

Gets or sets the index of the line from the begining of the document being processed.

public int LineIndex { get; }

Property value

int

LiteralInlineParser

InlineProcessor.cs

Gets the literal inline parser.

public LiteralInlineParser LiteralInlineParser { get; }

Property value

LiteralInlineParser

ParserStates

InlineProcessor.cs

Gets the parser states that can be used by InlineParser using their ParserBase<TProcessor>.Index property.

public object[] ParserStates { get; }

Property value

object[]

Gets the list of inline parsers.

public InlineParserList Parsers { get; }

Property value

InlineParserList

PreciseSourceLocation

InlineProcessor.cs

Gets a value indicating whether to provide precise source location.

public bool PreciseSourceLocation { get; }

Property value

bool

Gets the root container of the current InlineProcessor.Block.

public ContainerInline? Root { get; }

Property value

ContainerInline?

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

public bool TrackTrivia { get; }

Property value

bool

Methods

NameDescription
Emit(Inline)Emits an inline into the deepest open inline container for the current leaf.
GetParserState<TState>(InlineParser)Gets or creates a parser state instance scoped to the current leaf processing pass.
GetParserState<TState>(InlineParser, Func<TState>)Gets or creates a parser state instance scoped to the current leaf processing pass.
GetSourcePosition(int)Gets the source position for the specified offset within the current slice.
GetSourcePosition(int, int, int)Gets the source position for the specified offset within the current slice.
GetSourcePositionFromLocalSpan(SourceSpan)Gets source position from local span.
PostProcessInlines(int, Inline?, Inline?, bool)Performs the post process inlines operation.
ProcessInlineLeaf(LeafBlock)Processes the inline of the specified LeafBlock.
ReplaceParentContainer(ContainerBlock, ContainerBlock)Requests a replacement for a parent container while processing the current leaf block.

Emit(Inline)

InlineProcessor.cs

Emits an inline into the deepest open inline container for the current leaf.

public void Emit(Inline inline)

Parameters

inline Inline
The inline to emit.

Exceptions

ArgumentNullException
Thrown when inline is null.
ArgumentException
Thrown when inline is already attached to a parent.

GetParserState overloads

GetParserState<TState>(InlineParser)

InlineProcessor.cs

Gets or creates a parser state instance scoped to the current leaf processing pass.

public TState GetParserState<TState>(InlineParser parser) where TState : class, new()
Type parameters
TState
The type of state to get or create.
Parameters
parser InlineParser
The parser requesting the state.
Returns

TState The existing or newly created state instance.

GetParserState<TState>(InlineParser, Func<TState>)

InlineProcessor.cs

Gets or creates a parser state instance scoped to the current leaf processing pass.

public TState GetParserState<TState>(InlineParser parser, Func<TState> factory) where TState : class
Type parameters
TState
The type of state to get or create.
Parameters
parser InlineParser
The parser requesting the state.
factory Func<TState>
A factory used to create a state instance when none exists yet.
Returns

TState The existing or newly created state instance.

Exceptions
ArgumentNullException
Thrown when parser or factory is null.
InvalidOperationException
Thrown if factory returns null.

GetSourcePosition overloads

GetSourcePosition(int)

InlineProcessor.cs

Gets the source position for the specified offset within the current slice.

public int GetSourcePosition(int sliceOffset)
Parameters
sliceOffset int
The slice offset.
Returns

int The source position

GetSourcePosition(int, int, int)

InlineProcessor.cs

Gets the source position for the specified offset within the current slice.

public int GetSourcePosition(int sliceOffset, out int lineIndex, out int column)
Parameters
sliceOffset int
The slice offset.
lineIndex int
The line index.
column int
The column.
Returns

int The source position

GetSourcePositionFromLocalSpan(SourceSpan)

InlineProcessor.cs

Gets source position from local span.

public SourceSpan GetSourcePositionFromLocalSpan(SourceSpan span)

Parameters

span SourceSpan

Returns

SourceSpan

PostProcessInlines(int, Inline?, Inline?, bool)

InlineProcessor.cs

Performs the post process inlines operation.

public void PostProcessInlines(int startingIndex, Inline? root, Inline? lastChild, bool isFinalProcessing)

Parameters

startingIndex int
root Inline?
lastChild Inline?
isFinalProcessing bool

ProcessInlineLeaf(LeafBlock)

InlineProcessor.cs

Processes the inline of the specified LeafBlock.

public void ProcessInlineLeaf(LeafBlock leafBlock)

Parameters

leafBlock LeafBlock
The leaf block.

ReplaceParentContainer(ContainerBlock, ContainerBlock)

InlineProcessor.cs

Requests a replacement for a parent container while processing the current leaf block.

public void ReplaceParentContainer(ContainerBlock previousParentContainer, ContainerBlock newParentContainer)

Parameters

previousParentContainer ContainerBlock
The parent container that has already been replaced in the block tree.
newParentContainer ContainerBlock
The replacement parent container.

Exceptions

ArgumentNullException
Thrown if previousParentContainer or newParentContainer is null.
InvalidOperationException
Thrown if a replacement has already been requested for this leaf processing pass.

Remarks

This method does not perform the replacement in the block tree. Callers must already update the AST (replace the parent block and transfer children as needed). This method only synchronizes the traversal state used by MarkdownParser.ProcessInlines.