Skip to content

Commit

Permalink
Include opening and closing pipes in the table span
Browse files Browse the repository at this point in the history
  • Loading branch information
snnz committed Dec 18, 2024
1 parent 57fad6f commit 68659f4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Markdig/Extensions/Tables/PipeTableParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public bool PostProcess(InlineProcessor state, Inline? root, Inline? lastChild,
tableState.EndOfLines.Add(endOfTable);
}

int lastPipePos = 0;

// Cell loop
// Reconstruct the table from the delimiters
TableRow? row = null;
Expand All @@ -302,6 +304,12 @@ public bool PostProcess(InlineProcessor state, Inline? root, Inline? lastChild,
if (pipeSeparator != null && (delimiter.PreviousSibling is null || delimiter.PreviousSibling is LineBreakInline))
{
delimiter.Remove();
if (table.Span.IsEmpty)
{
table.Span = delimiter.Span;
table.Line = delimiter.Line;
table.Column = delimiter.Column;
}
continue;
}
}
Expand Down Expand Up @@ -354,6 +362,7 @@ public bool PostProcess(InlineProcessor state, Inline? root, Inline? lastChild,
// If the delimiter is a pipe, we need to remove it from the tree
// so that previous loop looking for a parent will not go further on subsequent cells
delimiter.Remove();
lastPipePos = delimiter.Span.End;
}

// We trim whitespace at the beginning and ending of the cell
Expand Down Expand Up @@ -421,6 +430,11 @@ public bool PostProcess(InlineProcessor state, Inline? root, Inline? lastChild,
}
}

if (lastPipePos > table.Span.End)
{
table.UpdateSpanEnd(lastPipePos);
}

// Once we are done with the cells, we can remove all end of lines in the table tree
foreach (var endOfLine in tableState.EndOfLines)
{
Expand Down

0 comments on commit 68659f4

Please sign in to comment.