MarkdownGridTableCell Class

A cell of a grid table: its text is a document of its own.

public sealed class MarkdownGridTableCell

Remarks

The positions of the nodes of MarkdownGridTableCell.Content are in the text of the cell: MarkdownGridTableCell.MapPosition and MarkdownGridTableCell.MapSpan give the positions in the text of the tree of the table.

Properties

NameDescription
ColumnIndexGets the index of the first column of the cell.
ColumnSpanGets the number of columns of the cell.
ContentGets the content of the cell: its text, parsed with the options of the table, whose reference links can use the definitions of the tree of the table.
RowSpanGets the number of rows of the cell.
TextGets the text of the cell: the text of each of its lines between its |, without the whitespace at the end.

Gets the index of the first column of the cell.

public int ColumnIndex { get; }

Property value

int

Gets the number of columns of the cell.

public int ColumnSpan { get; }

Property value

int

Gets the content of the cell: its text, parsed with the options of the table, whose reference links can use the definitions of the tree of the table.

public MarkdownSyntaxTree Content { get; }

Property value

MarkdownSyntaxTree

Gets the number of rows of the cell.

public int RowSpan { get; }

Property value

int

Gets the text of the cell: the text of each of its lines between its |, without the whitespace at the end.

public string Text { get; }

Property value

string

Methods

NameDescription
MapPosition(int)Gets the position in the text of the tree of the table of a position in MarkdownGridTableCell.Text, the text of MarkdownGridTableCell.Content. The line ending that separates two lines of the text is the end of the first one.
MapSpan(TextSpan)Gets the span in the text of the tree of the table of a span of MarkdownGridTableCell.Text, the text of MarkdownGridTableCell.Content, such as the span of a node of MarkdownGridTableCell.Content. A span on several lines covers the borders of the cells between them, and the cells next to the cell on these lines.

MapPosition(int)

MarkdownGridTableCell.cs

Gets the position in the text of the tree of the table of a position in MarkdownGridTableCell.Text, the text of MarkdownGridTableCell.Content. The line ending that separates two lines of the text is the end of the first one.

public int MapPosition(int position)

Parameters

position int
A position in MarkdownGridTableCell.Text, from 0 to its length.

Returns

int

Exceptions

ArgumentOutOfRangeException
position is negative or greater than the length of MarkdownGridTableCell.Text.

Example

var options = new MarkdownParseOptions { Extensions = MarkdownExtensions.GridTables };
var text = "Intro\n\n+---------------+\n| See [a](/u)   |\n| and [b](/v)   |\n+---------------+\n";
var tree = MarkdownSyntaxTree.ParseText(text, options);
var cell = tree.GetRoot().Blocks.OfType<MarkdownGridTableSyntax>().Single().Rows[0].Cells[0];

// The nodes of the content of the cell are not in the tree, and their spans are in the text of the cell
Assert.Empty(tree.GetRoot().DescendantNodes().OfType<MarkdownLinkSyntax>());
var link = cell.Content.GetRoot().DescendantNodes().OfType<MarkdownLinkSyntax>().Last();
Assert.Equal("[b](/v)", cell.Text.Substring(link.Span.Start, link.Span.Length));

// MapSpan gives the span of the link in the text of the tree
var span = cell.MapSpan(link.Span);
Assert.Equal("[b](/v)", text.Substring(span.Start, span.Length));

MapSpan(TextSpan)

MarkdownGridTableCell.cs

Gets the span in the text of the tree of the table of a span of MarkdownGridTableCell.Text, the text of MarkdownGridTableCell.Content, such as the span of a node of MarkdownGridTableCell.Content. A span on several lines covers the borders of the cells between them, and the cells next to the cell on these lines.

public TextSpan MapSpan(TextSpan span)

Parameters

span TextSpan

Returns

TextSpan

Exceptions

ArgumentOutOfRangeException
The span ends after MarkdownGridTableCell.Text.