Fix thematic break inside a list item closing the list (#970)

A thematic break indented to the content column of the current list item is parsed inside the item instead of closing the list, matching cmark and commonmark.js.
This commit is contained in:
Wleeaf
2026-10-28 22:58:30 +03:00
committed by GitHub
parent ac2134b46a
commit f36a2548d1
2 changed files with 13 additions and 2 deletions

View File

@@ -129,6 +129,15 @@ public class MiscTests
TestParser.TestSpec(input, expected);
}
[Test]
public void ThematicBreakIndentedToListItemContentStaysInTheItem()
{
TestParser.TestSpec("- item one\n\n ---\n\n- item two", "<ul>\n<li>\n<p>item one</p>\n<hr />\n</li>\n<li>\n<p>item two</p>\n</li>\n</ul>");
TestParser.TestSpec("1. o\n\n ***", "<ol>\n<li>\n<p>o</p>\n<hr />\n</li>\n</ol>");
TestParser.TestSpec("-\n ***", "<ul>\n<li>\n<hr />\n</li>\n</ul>");
TestParser.TestSpec("> - o\n>\n> ---", "<blockquote>\n<ul>\n<li>\n<p>o</p>\n<hr />\n</li>\n</ul>\n</blockquote>");
}
[Test]
public void TestAltTextIsCorrectlyEscaped()
{

View File

@@ -91,10 +91,12 @@ public class ListBlockParser : BlockParser
}
// When both a thematic break and a list item are possible
// interpretations of a line, the thematic break takes precedence
// interpretations of a line, the thematic break takes precedence.
// A thematic break indented to the content of the current list item belongs to that item.
BlockState result;
var thematicParser = ThematicBreakParser.Default;
if (processor.LastBlock is not FencedCodeBlock && thematicParser.HasOpeningCharacter(processor.CurrentChar))
if (processor.LastBlock is not FencedCodeBlock && thematicParser.HasOpeningCharacter(processor.CurrentChar)
&& !(block is ListItemBlock currentItem && processor.Indent >= Math.Abs(currentItem.ColumnWidth)))
{
result = thematicParser.TryOpen(processor);
if (result.IsBreak())