Skip to content

Commit 420b0c1

Browse files
authored
Fix option lists with additional indentation in Markdown (#21633)
This is more Markdown-ish way to fix issue #21055, then PR #21625. It does not enable RST definition lists, instead it makes adding additional indentation (less than 4) right after a paragraph be ignored, as it's done for all block elements in Markdown. (In this case this tenet is applied to option lists that are not part of CommonMark spec by themselves).
1 parent 4c073cf commit 420b0c1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/packages/docutils/rst.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,9 @@ proc parseParagraph(p: var RstParser, result: PRstNode) =
24472447
result.addIfNotNil(parseLineBlock(p))
24482448
of rnMarkdownBlockQuote:
24492449
result.addIfNotNil(parseMarkdownBlockQuote(p))
2450-
else: break
2450+
else:
2451+
dec p.idx # allow subsequent block to be parsed as another section
2452+
break
24512453
else:
24522454
break
24532455
of tkPunct:

tests/stdlib/trst.nim

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,32 @@ suite "RST parsing":
689689
rnLeaf 'desc2'
690690
""")
691691

692+
test "definition lists work correctly with additional indentation in Markdown":
693+
check(dedent"""
694+
Paragraph:
695+
-c desc1
696+
-b desc2
697+
""".toAst() ==
698+
dedent"""
699+
rnInner
700+
rnInner
701+
rnLeaf 'Paragraph'
702+
rnLeaf ':'
703+
rnOptionList
704+
rnOptionListItem order=1
705+
rnOptionGroup
706+
rnLeaf '-'
707+
rnLeaf 'c'
708+
rnDescription
709+
rnLeaf 'desc1'
710+
rnOptionListItem order=2
711+
rnOptionGroup
712+
rnLeaf '-'
713+
rnLeaf 'b'
714+
rnDescription
715+
rnLeaf 'desc2'
716+
""")
717+
692718
test "RST comment":
693719
check(dedent"""
694720
.. comment1

0 commit comments

Comments
 (0)