mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-10 14:00:05 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b04599c44 | ||
|
|
5e6fb2d1c5 | ||
|
|
14406bc60d | ||
|
|
2aa6780a30 | ||
|
|
c43646586c | ||
|
|
d548b82bcd | ||
|
|
aab5543cb5 | ||
|
|
2e1d741aaf | ||
|
|
80c50e31e2 |
@@ -386,4 +386,27 @@ Also not a note.</p>
|
||||
";
|
||||
TestParser.TestSpec(input, expected, new MarkdownPipelineBuilder().UseAlertBlocks().Build());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestIssue845ListItemBlankLine()
|
||||
{
|
||||
TestParser.TestSpec("-\n\n foo",@"
|
||||
<ul>
|
||||
<li></li>
|
||||
</ul>
|
||||
<p>foo</p>");
|
||||
TestParser.TestSpec("-\n-\n\n foo",@"
|
||||
<ul>
|
||||
<li></li>
|
||||
<li></li>
|
||||
</ul>
|
||||
<p>foo</p>");
|
||||
TestParser.TestSpec("-\n\n-\n\n foo",@"
|
||||
<ul>
|
||||
<li></li>
|
||||
<li></li>
|
||||
</ul>
|
||||
<p>foo</p>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ public sealed class TestPipeTable
|
||||
[TestCase("| S | T |\r\n|---|---|\t\r\n| G | H |")]
|
||||
[TestCase("| S | T |\r\n|---|---|\f\r\n| G | H |")]
|
||||
[TestCase("| S | \r\n|---|\r\n| G |\r\n\r\n| D | D |\r\n| ---| ---| \r\n| V | V |", 2)]
|
||||
[TestCase("a\r| S | T |\r|---|---|")]
|
||||
[TestCase("a\n| S | T |\r|---|---|")]
|
||||
public void TestTableBug(string markdown, int tableCount = 1)
|
||||
{
|
||||
MarkdownDocument document =
|
||||
|
||||
@@ -834,6 +834,29 @@ literal ( 2, 2) 11-11
|
||||
", "pipetables");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGridTable()
|
||||
{
|
||||
Check("0\n\n+-+-+\n|A|B|\n+=+=+\n|C|D|\n+-+-+", @"
|
||||
paragraph ( 0, 0) 0-0
|
||||
literal ( 0, 0) 0-0
|
||||
table ( 2, 0) 3-31
|
||||
tablerow ( 3, 0) 9-13
|
||||
tablecell ( 3, 0) 9-11
|
||||
paragraph ( 3, 1) 10-10
|
||||
literal ( 3, 1) 10-10
|
||||
tablecell ( 3, 2) 11-13
|
||||
paragraph ( 3, 3) 12-12
|
||||
literal ( 3, 3) 12-12
|
||||
tablerow ( 5, 0) 21-25
|
||||
tablecell ( 5, 0) 21-23
|
||||
paragraph ( 5, 1) 22-22
|
||||
literal ( 5, 1) 22-22
|
||||
tablecell ( 5, 2) 23-25
|
||||
paragraph ( 5, 3) 24-24
|
||||
literal ( 5, 3) 24-24", "gridtables");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIndentedCode()
|
||||
{
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Copyright (c) Alexandre Mutel. All rights reserved.
|
||||
// This file is licensed under the BSD-Clause 2 license.
|
||||
// This file is licensed under the BSD-Clause 2 license.
|
||||
// See the license.txt file in the project root for more information.
|
||||
|
||||
using Markdig.Helpers;
|
||||
using Markdig.Parsers;
|
||||
using Markdig.Syntax;
|
||||
using System.Linq;
|
||||
|
||||
namespace Markdig.Extensions.Tables;
|
||||
|
||||
@@ -60,7 +61,12 @@ public class GridTableParser : BlockParser
|
||||
}
|
||||
// Store the line (if we need later to build a ParagraphBlock because the GridTable was in fact invalid)
|
||||
tableState.AddLine(ref processor.Line);
|
||||
var table = new Table(this);
|
||||
var table = new Table(this)
|
||||
{
|
||||
Line = processor.LineIndex,
|
||||
Column = processor.Column,
|
||||
Span = { Start = lineStart }
|
||||
};
|
||||
table.SetData(typeof(GridTableState), tableState);
|
||||
|
||||
// Calculate the total width of all columns
|
||||
@@ -94,10 +100,12 @@ public class GridTableParser : BlockParser
|
||||
tableState.AddLine(ref processor.Line);
|
||||
if (processor.CurrentChar == '+')
|
||||
{
|
||||
gridTable.UpdateSpanEnd(processor.Line.End);
|
||||
return HandleNewRow(processor, tableState, gridTable);
|
||||
}
|
||||
if (processor.CurrentChar == '|')
|
||||
{
|
||||
gridTable.UpdateSpanEnd(processor.Line.End);
|
||||
return HandleContents(processor, tableState, gridTable);
|
||||
}
|
||||
TerminateCurrentRow(processor, tableState, gridTable, true);
|
||||
@@ -182,8 +190,18 @@ public class GridTableParser : BlockParser
|
||||
var columnSlice = columns[i];
|
||||
if (columnSlice.CurrentCell != null)
|
||||
{
|
||||
currentRow ??= new TableRow();
|
||||
|
||||
if (currentRow == null)
|
||||
{
|
||||
TableCell firstCell = columns.First(c => c.CurrentCell != null).CurrentCell!;
|
||||
TableCell lastCell = columns.Last(c => c.CurrentCell != null).CurrentCell!;
|
||||
|
||||
currentRow ??= new TableRow()
|
||||
{
|
||||
Span = new SourceSpan(firstCell.Span.Start, lastCell.Span.End),
|
||||
Line = firstCell.Line
|
||||
};
|
||||
}
|
||||
|
||||
// If this cell does not already belong to a row
|
||||
if (columnSlice.CurrentCell.Parent is null)
|
||||
{
|
||||
@@ -271,7 +289,10 @@ public class GridTableParser : BlockParser
|
||||
columnSlice.CurrentCell = new TableCell(this)
|
||||
{
|
||||
ColumnSpan = columnSlice.CurrentColumnSpan,
|
||||
ColumnIndex = i
|
||||
ColumnIndex = i,
|
||||
Column = columnSlice.Start,
|
||||
Line = processor.LineIndex,
|
||||
Span = new SourceSpan(line.Start + columnSlice.Start, line.Start + columnSlice.End)
|
||||
};
|
||||
|
||||
columnSlice.BlockProcessor ??= processor.CreateChild();
|
||||
@@ -281,7 +302,8 @@ public class GridTableParser : BlockParser
|
||||
}
|
||||
// Process the content of the cell
|
||||
columnSlice.BlockProcessor!.LineIndex = processor.LineIndex;
|
||||
columnSlice.BlockProcessor.ProcessLine(sliceForCell);
|
||||
|
||||
columnSlice.BlockProcessor.ProcessLinePart(sliceForCell, sliceForCell.Start - line.Start);
|
||||
}
|
||||
|
||||
// Go to next column
|
||||
|
||||
@@ -48,6 +48,7 @@ public class PipeTableParser : InlineParser, IPostInlineProcessor
|
||||
}
|
||||
|
||||
var c = slice.CurrentChar;
|
||||
var isNewLineFollowedByPipe = (c == '\n' || c == '\r') && slice.PeekChar() == '|';
|
||||
|
||||
// If we have not a delimiter on the first line of a paragraph, don't bother to continue
|
||||
// tracking other delimiters on following lines
|
||||
@@ -60,18 +61,17 @@ public class PipeTableParser : InlineParser, IPostInlineProcessor
|
||||
|
||||
if (tableState is null)
|
||||
{
|
||||
|
||||
// A table could be preceded by an empty line or a line containing an inline
|
||||
// that has not been added to the stack, so we consider this as a valid
|
||||
// start for a table. Typically, with this, we can have an attributes {...}
|
||||
// starting on the first line of a pipe table, even if the first line
|
||||
// doesn't have a pipe
|
||||
if (processor.Inline != null && (localLineIndex > 0 || c == '\n' || c == '\r'))
|
||||
if (processor.Inline != null && (localLineIndex > 0 || c == '\n' || c == '\r') && !isNewLineFollowedByPipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (processor.Inline is null)
|
||||
if (processor.Inline is null || isNewLineFollowedByPipe)
|
||||
{
|
||||
isFirstLineEmpty = true;
|
||||
}
|
||||
|
||||
@@ -493,8 +493,34 @@ public class BlockProcessor
|
||||
|
||||
ContinueProcessingLine = true;
|
||||
|
||||
ResetLine(newLine);
|
||||
ResetLine(newLine, 0);
|
||||
|
||||
Process();
|
||||
|
||||
LineIndex++;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes part of a line.
|
||||
/// </summary>
|
||||
/// <param name="line">The line.</param>
|
||||
/// <param name="column">The column.</param>
|
||||
public void ProcessLinePart(StringSlice line, int column)
|
||||
{
|
||||
CurrentLineStartPosition = line.Start - column;
|
||||
|
||||
ContinueProcessingLine = true;
|
||||
|
||||
ResetLine(line, column);
|
||||
|
||||
Process();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process current string slice.
|
||||
/// </summary>
|
||||
private void Process()
|
||||
{
|
||||
TryContinueBlocks();
|
||||
|
||||
// If the line was not entirely processed by pending blocks, try to process it with any new block
|
||||
@@ -502,8 +528,6 @@ public class BlockProcessor
|
||||
|
||||
// Close blocks that are no longer opened
|
||||
CloseAll(false);
|
||||
|
||||
LineIndex++;
|
||||
}
|
||||
|
||||
internal bool IsOpen(Block block)
|
||||
@@ -956,18 +980,17 @@ public class BlockProcessor
|
||||
ContinueProcessingLine = !result.IsDiscard();
|
||||
}
|
||||
|
||||
private void ResetLine(StringSlice newLine)
|
||||
private void ResetLine(StringSlice newLine, int column)
|
||||
{
|
||||
Line = newLine;
|
||||
Column = 0;
|
||||
Column = column;
|
||||
ColumnBeforeIndent = 0;
|
||||
StartBeforeIndent = Start;
|
||||
originalLineStart = newLine.Start;
|
||||
originalLineStart = newLine.Start - column;
|
||||
TriviaStart = newLine.Start;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[MemberNotNull(nameof(Document), nameof(Parsers))]
|
||||
internal void Setup(MarkdownDocument document, BlockParserList parsers, MarkdownParserContext? context, bool trackTrivia)
|
||||
{
|
||||
|
||||
@@ -145,6 +145,7 @@ public class ListBlockParser : BlockParser
|
||||
if (list.CountBlankLinesReset == 1 && listItem.ColumnWidth < 0)
|
||||
{
|
||||
state.Close(listItem);
|
||||
list.CountBlankLinesReset = 0;
|
||||
|
||||
// Leave the list open
|
||||
list.IsOpen = true;
|
||||
|
||||
Reference in New Issue
Block a user