Block Class

Base class for a block structure. Either a LeafBlock or a ContainerBlock.

public abstract class Block : MarkdownObject, IBlock, IMarkdownObject
Inheritance
MarkdownObject Block
Implements

Constructors

NameDescription
Block(BlockParser?)Initializes a new instance of the Block class.

Block(BlockParser?)

Block.cs

Initializes a new instance of the Block class.

protected Block(BlockParser? parser)

Parameters

parser BlockParser?
The parser used to create this block.

Properties

NameDescription
IsBreakableGets or sets a value indicating whether this block is breakable. Default is true.
IsOpenGets or sets a value indicating whether this instance is still open.
LinesAfterGets or sets the empty lines occurring after this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise null.
LinesBeforeGets or sets the empty lines occurring before this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise null.
NewLineThe last newline of this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled
ParentGets the parent of this container. May be null.
ParserGets the parser associated to this instance.
RemoveAfterProcessInlinesGets or sets a value indicating whether this block must be removed from its container after inlines have been processed.
TriviaAfterGets or sets trivia occurring after this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise StringSlice.Empty.
TriviaBeforeGets or sets the trivia right before this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise StringSlice.Empty.

IsBreakable

Block.cs

Gets or sets a value indicating whether this block is breakable. Default is true.

public bool IsBreakable { get; set; }

Property value

bool

IsOpen

Block.cs

Gets or sets a value indicating whether this instance is still open.

public bool IsOpen { get; set; }

Property value

bool

LinesAfter

Block.cs

Gets or sets the empty lines occurring after this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise null.

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

Property value

List<StringSlice>?

LinesBefore

Block.cs

Gets or sets the empty lines occurring before this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise null.

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

Property value

List<StringSlice>?

NewLine

Block.cs

The last newline of this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled

public NewLine NewLine { get; set; }

Property value

NewLine

Parent

Block.cs

Gets the parent of this container. May be null.

public ContainerBlock? Parent { get; }

Property value

ContainerBlock?

Parser

Block.cs

Gets the parser associated to this instance.

public BlockParser? Parser { get; }

Property value

BlockParser?

RemoveAfterProcessInlines

Block.cs

Gets or sets a value indicating whether this block must be removed from its container after inlines have been processed.

public bool RemoveAfterProcessInlines { get; set; }

Property value

bool

TriviaAfter

Block.cs

Gets or sets trivia occurring after this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise StringSlice.Empty.

public StringSlice TriviaAfter { get; set; }

Property value

StringSlice

TriviaBefore

Block.cs

Gets or sets the trivia right before this block. Trivia: only parsed when MarkdownPipeline.TrackTrivia is enabled, otherwise StringSlice.Empty.

public StringSlice TriviaBefore { get; set; }

Property value

StringSlice

Methods

NameDescription
Remove()Removes this block from its parent container.
ReplaceBy(Block, bool)Replaces this block with replacement in its parent container.
UpdateSpanEnd(int)Performs the update span end operation.
UpdateSpanToInclude(SourceSpan)Updates this block span and all parent container spans to include the specified span.

Remove()

Block.cs

Removes this block from its parent container.

public void Remove()

ReplaceBy(Block, bool)

Block.cs

Replaces this block with replacement in its parent container.

public void ReplaceBy(Block replacement, bool moveChildren = true)

Parameters

replacement Block
The replacement block.
moveChildren bool
true to transfer children when both this block and replacement are containers.

Exceptions

ArgumentNullException
Thrown if replacement is null.
ArgumentException
Thrown if replacement is already attached to a parent container.
InvalidOperationException
Thrown if this block has no parent container.

Remarks

This method does not recompute spans or trivia. Callers are responsible for updating those values if a transform requires exact source information after replacement.

UpdateSpanEnd(int)

Block.cs

Performs the update span end operation.

public void UpdateSpanEnd(int spanEnd)

Parameters

spanEnd int

UpdateSpanToInclude(SourceSpan)

Block.cs

Updates this block span and all parent container spans to include the specified span.

public void UpdateSpanToInclude(SourceSpan span)

Parameters

span SourceSpan
The span to include.

Events

NameDescription
ProcessInlinesBeginOccurs when the process of inlines begin.
ProcessInlinesEndOccurs when the process of inlines ends for this instance.

ProcessInlinesBegin

Block.cs

Occurs when the process of inlines begin.

public event ProcessInlineDelegate? ProcessInlinesBegin

ProcessInlinesEnd

Block.cs

Occurs when the process of inlines ends for this instance.

public event ProcessInlineDelegate? ProcessInlinesEnd