mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-03 04:24:45 +00:00
parse RST headings when EOF follows them (#17014)
This commit is contained in:
@@ -724,6 +724,7 @@ proc match(p: RstParser, start: int, expr: string): bool =
|
|||||||
# ' ' tkWhite
|
# ' ' tkWhite
|
||||||
# 'a' tkAdornment
|
# 'a' tkAdornment
|
||||||
# 'i' tkIndent
|
# 'i' tkIndent
|
||||||
|
# 'I' tkIndent or tkEof
|
||||||
# 'p' tkPunct
|
# 'p' tkPunct
|
||||||
# 'T' always true
|
# 'T' always true
|
||||||
# 'E' whitespace, indent or eof
|
# 'E' whitespace, indent or eof
|
||||||
@@ -738,6 +739,7 @@ proc match(p: RstParser, start: int, expr: string): bool =
|
|||||||
of 'w': result = p.tok[j].kind == tkWord
|
of 'w': result = p.tok[j].kind == tkWord
|
||||||
of ' ': result = p.tok[j].kind == tkWhite
|
of ' ': result = p.tok[j].kind == tkWhite
|
||||||
of 'i': result = p.tok[j].kind == tkIndent
|
of 'i': result = p.tok[j].kind == tkIndent
|
||||||
|
of 'I': result = p.tok[j].kind in {tkIndent, tkEof}
|
||||||
of 'p': result = p.tok[j].kind == tkPunct
|
of 'p': result = p.tok[j].kind == tkPunct
|
||||||
of 'a': result = p.tok[j].kind == tkAdornment
|
of 'a': result = p.tok[j].kind == tkAdornment
|
||||||
of 'o': result = p.tok[j].kind == tkOther
|
of 'o': result = p.tok[j].kind == tkOther
|
||||||
@@ -1266,7 +1268,7 @@ proc whichSection(p: RstParser): RstNodeKind =
|
|||||||
return rnDirective
|
return rnDirective
|
||||||
case currentTok(p).kind
|
case currentTok(p).kind
|
||||||
of tkAdornment:
|
of tkAdornment:
|
||||||
if match(p, p.idx + 1, "ii") and currentTok(p).symbol.len >= 4:
|
if match(p, p.idx + 1, "iI") and currentTok(p).symbol.len >= 4:
|
||||||
result = rnTransition
|
result = rnTransition
|
||||||
elif match(p, p.idx, "+a+"):
|
elif match(p, p.idx, "+a+"):
|
||||||
result = rnGridTable
|
result = rnGridTable
|
||||||
@@ -1286,7 +1288,7 @@ proc whichSection(p: RstParser): RstNodeKind =
|
|||||||
result = rnMarkdownTable
|
result = rnMarkdownTable
|
||||||
elif currentTok(p).symbol == "|" and isLineBlock(p):
|
elif currentTok(p).symbol == "|" and isLineBlock(p):
|
||||||
result = rnLineBlock
|
result = rnLineBlock
|
||||||
elif match(p, tokenAfterNewline(p), "ai") and
|
elif match(p, tokenAfterNewline(p), "aI") and
|
||||||
isAdornmentHeadline(p, tokenAfterNewline(p)):
|
isAdornmentHeadline(p, tokenAfterNewline(p)):
|
||||||
result = rnHeadline
|
result = rnHeadline
|
||||||
elif predNL(p) and
|
elif predNL(p) and
|
||||||
@@ -1306,7 +1308,7 @@ proc whichSection(p: RstParser): RstNodeKind =
|
|||||||
result = rnParagraph
|
result = rnParagraph
|
||||||
of tkWord, tkOther, tkWhite:
|
of tkWord, tkOther, tkWhite:
|
||||||
let tokIdx = tokenAfterNewline(p)
|
let tokIdx = tokenAfterNewline(p)
|
||||||
if match(p, tokIdx, "ai"):
|
if match(p, tokIdx, "aI"):
|
||||||
if isAdornmentHeadline(p, tokIdx): result = rnHeadline
|
if isAdornmentHeadline(p, tokIdx): result = rnHeadline
|
||||||
else: result = rnParagraph
|
else: result = rnParagraph
|
||||||
elif match(p, p.idx, "e) ") or match(p, p.idx, "e. "): result = rnEnumList
|
elif match(p, p.idx, "e) ") or match(p, p.idx, "e. "): result = rnEnumList
|
||||||
|
|||||||
@@ -271,6 +271,13 @@ Some chapter
|
|||||||
let output5 = rstToHtml(input5, {roSupportMarkdown}, defaultConfig())
|
let output5 = rstToHtml(input5, {roSupportMarkdown}, defaultConfig())
|
||||||
doAssert ""punctuation symbols"" in output5 and "<h1" in output5
|
doAssert ""punctuation symbols"" in output5 and "<h1" in output5
|
||||||
|
|
||||||
|
# check that EOF after adornment does not prevent it parsing as heading
|
||||||
|
let input6 = dedent """
|
||||||
|
Some chapter
|
||||||
|
------------"""
|
||||||
|
let output6 = rstToHtml(input6, {roSupportMarkdown}, defaultConfig())
|
||||||
|
doAssert "<h1 id=\"some-chapter\">Some chapter</h1>" in output6
|
||||||
|
|
||||||
|
|
||||||
test "RST links":
|
test "RST links":
|
||||||
let input1 = """
|
let input1 = """
|
||||||
|
|||||||
Reference in New Issue
Block a user