Fixes cell contents not displaying after colspan merged cell

This commit is contained in:
Chris Rodgers
2016-07-16 13:37:26 +01:00
parent ba8557d3bf
commit 6d8f8996d5
3 changed files with 16 additions and 7 deletions

View File

@@ -131,11 +131,12 @@ namespace Markdig.Extensions.Tables
// | ------------- | ------------ | ---------------------------------------- |
// Calculate the colspan for the new row
int columnIndex = -1;
foreach (var columnSlice in columns)
for (int i = 0; i < columns.Count; i++)
{
var columnSlice = columns[i];
if (line.PeekCharExtra(columnSlice.Start) == '|')
{
columnIndex++;
columnIndex = i;
}
if (columnIndex >= 0)
{
@@ -301,8 +302,9 @@ namespace Markdig.Extensions.Tables
{
var columns = tableState.ColumnSlices;
TableRow currentRow = null;
foreach (var columnSlice in columns)
for (int i = 0; i < columns.Count; i++)
{
var columnSlice = columns[i];
if (columnSlice.CurrentCell != null)
{
if (currentRow == null)
@@ -332,7 +334,8 @@ namespace Markdig.Extensions.Tables
// Else we can create a new cell
columnSlice.CurrentCell = new TableCell(this)
{
ColumnSpan = columnSlice.CurrentColumnSpan
ColumnSpan = columnSlice.CurrentColumnSpan,
ColumnIndex = i
};
if (columnSlice.BlockProcessor == null)

View File

@@ -78,10 +78,10 @@ namespace Markdig.Extensions.Tables
{
renderer.Write($" colspan=\"{cell.ColumnSpan}\"");
}
if (table.ColumnDefinitions != null && i < table.ColumnDefinitions.Count)
var columnIndex = cell.ColumnIndex == -1 ? i : cell.ColumnIndex;
if (table.ColumnDefinitions != null && columnIndex < table.ColumnDefinitions.Count)
{
switch (table.ColumnDefinitions[i].Alignment)
switch (table.ColumnDefinitions[columnIndex].Alignment)
{
case TableColumnAlign.Center:
renderer.Write(" style=\"text-align: center;\"");

View File

@@ -27,8 +27,14 @@ namespace Markdig.Extensions.Tables
public TableCell(BlockParser parser) : base(parser)
{
ColumnSpan = 1;
ColumnIndex = -1;
}
/// <summary>
/// Gets or sets the index of the column to which this cell belongs.
/// </summary>
public int ColumnIndex { get; set; }
/// <summary>
/// Gets or sets the column span this cell is covering. Default is 1.
/// </summary>