rst: allow comment to continue on second line (#18338)
This commit is contained in:
parent
55c1953f63
commit
0c8d3ae985
2 changed files with 76 additions and 18 deletions
|
|
@ -1615,24 +1615,16 @@ proc getDirective(p: var RstParser): string =
|
||||||
"too many colons for a directive (should be ::)",
|
"too many colons for a directive (should be ::)",
|
||||||
p.tok[afterIdx].line, p.tok[afterIdx].col)
|
p.tok[afterIdx].line, p.tok[afterIdx].col)
|
||||||
|
|
||||||
proc parseComment(p: var RstParser): PRstNode =
|
proc parseComment(p: var RstParser, col: int): PRstNode =
|
||||||
case currentTok(p).kind
|
|
||||||
of tkIndent, tkEof:
|
|
||||||
if currentTok(p).kind != tkEof and nextTok(p).kind == tkIndent:
|
if currentTok(p).kind != tkEof and nextTok(p).kind == tkIndent:
|
||||||
inc p.idx # empty comment
|
inc p.idx # empty comment
|
||||||
else:
|
else:
|
||||||
var indent = currentTok(p).ival
|
while currentTok(p).kind != tkEof:
|
||||||
while true:
|
if currentTok(p).kind == tkIndent and currentTok(p).ival > col or
|
||||||
case currentTok(p).kind
|
currentTok(p).kind != tkIndent and currentTok(p).col > col:
|
||||||
of tkEof:
|
|
||||||
break
|
|
||||||
of tkIndent:
|
|
||||||
if currentTok(p).ival < indent: break
|
|
||||||
else:
|
|
||||||
discard
|
|
||||||
inc p.idx
|
inc p.idx
|
||||||
else:
|
else:
|
||||||
while currentTok(p).kind notin {tkIndent, tkEof}: inc p.idx
|
break
|
||||||
result = nil
|
result = nil
|
||||||
|
|
||||||
proc parseLine(p: var RstParser, father: PRstNode) =
|
proc parseLine(p: var RstParser, father: PRstNode) =
|
||||||
|
|
@ -2841,7 +2833,7 @@ proc parseDotDot(p: var RstParser): PRstNode =
|
||||||
(n = parseFootnote(p); n != nil):
|
(n = parseFootnote(p); n != nil):
|
||||||
result = n
|
result = n
|
||||||
else:
|
else:
|
||||||
result = parseComment(p)
|
result = parseComment(p, col)
|
||||||
|
|
||||||
proc rstParsePass1*(fragment, filename: string,
|
proc rstParsePass1*(fragment, filename: string,
|
||||||
line, column: int,
|
line, column: int,
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,72 @@ suite "RST parsing":
|
||||||
rnLeaf 'set'
|
rnLeaf 'set'
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
test "RST comment":
|
||||||
|
check(dedent"""
|
||||||
|
.. comment1
|
||||||
|
comment2
|
||||||
|
someParagraph""".toAst ==
|
||||||
|
dedent"""
|
||||||
|
rnLeaf 'someParagraph'
|
||||||
|
""")
|
||||||
|
|
||||||
|
check(dedent"""
|
||||||
|
..
|
||||||
|
comment1
|
||||||
|
comment2
|
||||||
|
someParagraph""".toAst ==
|
||||||
|
dedent"""
|
||||||
|
rnLeaf 'someParagraph'
|
||||||
|
""")
|
||||||
|
|
||||||
|
test "check that additional line right after .. ends comment":
|
||||||
|
check(dedent"""
|
||||||
|
..
|
||||||
|
|
||||||
|
notAcomment1
|
||||||
|
notAcomment2
|
||||||
|
someParagraph""".toAst ==
|
||||||
|
dedent"""
|
||||||
|
rnInner
|
||||||
|
rnBlockQuote
|
||||||
|
rnInner
|
||||||
|
rnLeaf 'notAcomment1'
|
||||||
|
rnLeaf ' '
|
||||||
|
rnLeaf 'notAcomment2'
|
||||||
|
rnParagraph
|
||||||
|
rnLeaf 'someParagraph'
|
||||||
|
""")
|
||||||
|
|
||||||
|
test "but blank lines after 2nd non-empty line don't end the comment":
|
||||||
|
check(dedent"""
|
||||||
|
..
|
||||||
|
comment1
|
||||||
|
|
||||||
|
|
||||||
|
comment2
|
||||||
|
someParagraph""".toAst ==
|
||||||
|
dedent"""
|
||||||
|
rnLeaf 'someParagraph'
|
||||||
|
""")
|
||||||
|
|
||||||
|
test "using .. as separator b/w directives and block quotes":
|
||||||
|
check(dedent"""
|
||||||
|
.. note:: someNote
|
||||||
|
|
||||||
|
..
|
||||||
|
|
||||||
|
someBlockQuote""".toAst ==
|
||||||
|
dedent"""
|
||||||
|
rnInner
|
||||||
|
rnAdmonition adType=note
|
||||||
|
[nil]
|
||||||
|
[nil]
|
||||||
|
rnLeaf 'someNote'
|
||||||
|
rnBlockQuote
|
||||||
|
rnInner
|
||||||
|
rnLeaf 'someBlockQuote'
|
||||||
|
""")
|
||||||
|
|
||||||
suite "RST indentation":
|
suite "RST indentation":
|
||||||
test "nested bullet lists":
|
test "nested bullet lists":
|
||||||
let input = dedent """
|
let input = dedent """
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue