diff --git a/tools/MarkdownConverter.Tests/MarkdownSourceConverterTests.cs b/tools/MarkdownConverter.Tests/MarkdownSourceConverterTests.cs index b8af5ca60..eb14ee562 100644 --- a/tools/MarkdownConverter.Tests/MarkdownSourceConverterTests.cs +++ b/tools/MarkdownConverter.Tests/MarkdownSourceConverterTests.cs @@ -21,6 +21,7 @@ public class MarkdownSourceConverterTests [InlineData("antlr-with-line-comment")] [InlineData("note")] [InlineData("code-block-in-list")] + [InlineData("table-in-list")] public void SingleResourceConversion(string name) { var reporter = new Reporter(TextWriter.Null); @@ -55,6 +56,8 @@ public void SingleResourceConversion(string name) diff.DifferenceListener += (comparison, outcome) => differences.Add(comparison); diff.Compare(expectedDoc, actualDoc); Assert.Empty(differences); + Assert.Equal(0, reporter.Warnings); + Assert.Equal(0, reporter.Errors); } [Theory] diff --git a/tools/MarkdownConverter.Tests/table-in-list.md b/tools/MarkdownConverter.Tests/table-in-list.md new file mode 100644 index 000000000..cc81d23e3 --- /dev/null +++ b/tools/MarkdownConverter.Tests/table-in-list.md @@ -0,0 +1,12 @@ +# 1 Heading + +Before a list + +- List item + + + +
+ + More list text +- Next list item diff --git a/tools/MarkdownConverter.Tests/table-in-list.xml b/tools/MarkdownConverter.Tests/table-in-list.xml new file mode 100644 index 000000000..49a6429f6 --- /dev/null +++ b/tools/MarkdownConverter.Tests/table-in-list.xml @@ -0,0 +1,109 @@ + +

+ + + + + + Heading + + +

+

+ + Before a list + +

+

+ + + + + + + + + List item + +

+

+ + + + + + +

+ + + + + + + + + + + + + + + + + + + + + +

+ + Normal cell + +

+
+ + + + + +

+ + + + + + Code cell + +

+
+ +
+

+ + + + + + +

+

+ + + + + More list text + +

+

+ + + + + + + + + Next list item + +

+
\ No newline at end of file diff --git a/tools/MarkdownConverter/Converter/MarkdownSourceConverter.cs b/tools/MarkdownConverter/Converter/MarkdownSourceConverter.cs index aceabf835..1233b8662 100644 --- a/tools/MarkdownConverter/Converter/MarkdownSourceConverter.cs +++ b/tools/MarkdownConverter/Converter/MarkdownSourceConverter.cs @@ -285,6 +285,13 @@ IEnumerable Paragraph2Paragraphs(MarkdownParagraph md) yield return table; } } + else if (content is MarkdownParagraph.InlineBlock inlineBlock && GetCustomBlockId(inlineBlock) is string customBlockId) + { + foreach (var element in GenerateCustomBlockElements(customBlockId, inlineBlock)) + { + yield return element; + } + } else { reporter.Error("MD08", $"Unexpected item in list '{content.GetType().Name}'"); @@ -459,13 +466,13 @@ IEnumerable Paragraph2Paragraphs(MarkdownParagraph md) reporter.Error("MD11", $"Unrecognized markdown element {md.GetType().Name}"); yield return new Paragraph(new Run(new Text($"[{md.GetType().Name}]"))); } + } - string GetCustomBlockId(MarkdownParagraph.InlineBlock block) - { - Regex customBlockComment = new Regex(@"^"); - var match = customBlockComment.Match(block.code); - return match.Success ? match.Groups[1].Value : null; - } + static string GetCustomBlockId(MarkdownParagraph.InlineBlock block) + { + Regex customBlockComment = new Regex(@"^"); + var match = customBlockComment.Match(block.code); + return match.Success ? match.Groups[1].Value : null; } IEnumerable FlattenList(MarkdownParagraph.ListBlock md) @@ -565,7 +572,7 @@ IEnumerable FlattenList(MarkdownParagraph.ListBlock md, int level) yield return subitem; } } - else if (mdp.IsTableBlock) + else if (mdp.IsTableBlock || mdp is MarkdownParagraph.InlineBlock inline && GetCustomBlockId(inline) is not null) { yield return new FlatItem(level, false, isOrdered, mdp); } @@ -935,6 +942,8 @@ IEnumerable Literal2Elements(string literal, bool isNested, bool "function_members" => TableHelpers.CreateFunctionMembersTable(block.code), "format_strings_1" => new[] { new Paragraph(new Run(new Text("FIXME: Replace with first format strings table"))) }, "format_strings_2" => new[] { new Paragraph(new Run(new Text("FIXME: Replace with second format strings table"))) }, + // This is for the sake of a simple unit test. It's a single-row table with two cells. + "test" => TableHelpers.CreateTestTable(), _ => HandleInvalidCustomBlock(customBlockId) }; @@ -1124,6 +1133,13 @@ internal static IEnumerable CreateSubtractionTable() return CreateTableElements(table); } + internal static IEnumerable CreateTestTable() + { + Table table = CreateTable(indentation: 900, width: 8000); + table.Append(CreateTableRow(CreateNormalTableCell("Normal cell"), CreateCodeTableCell("Code cell"))); + return CreateTableElements(table); + } + private static TableRow CreateTableRow(params TableCell[] cells) => new TableRow(cells); internal static Table CreateTable(int indentation = 360, int? width = null)