fix #17260 render \ properly in nim doc, rst2html (#17315)

This commit is contained in:
Timothee Cour 2021-03-24 02:58:29 -07:00 • committed by GitHub
commit 1590d14575
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 10 deletions

View file

@ -852,6 +852,9 @@ proc isInlineMarkupEnd(p: RstParser, markup: string): bool =
if not result: return
# Rule 4:
if p.idx > 0:
# see bug #17260; for now `\` must be written ``\``, likewise with sequences
# ending in an un-escaped `\`; `\\` is legal but not `\\\` for example;
# for this reason we can't use `["``", "`"]` here.
if markup != "``" and prevTok(p).symbol == "\\":
result = false
@ -1089,11 +1092,19 @@ proc parseUntil(p: var RstParser, father: PRstNode, postfix: string,
if isInlineMarkupEnd(p, postfix):
inc p.idx
break
elif interpretBackslash:
parseBackslash(p, father)
else:
father.add(newLeaf(p))
inc p.idx
if postfix == "`":
if prevTok(p).symbol == "\\" and currentTok(p).symbol == "`":
father.sons[^1] = newLeaf(p) # instead, we should use lookahead
else:
father.add(newLeaf(p))
inc p.idx
else:
if interpretBackslash:
parseBackslash(p, father)
else:
father.add(newLeaf(p))
inc p.idx
of tkAdornment, tkWord, tkOther:
father.add(newLeaf(p))
inc p.idx
@ -1243,7 +1254,7 @@ proc parseInline(p: var RstParser, father: PRstNode) =
father.add(n)
elif isInlineMarkupStart(p, "`"):
var n = newRstNode(rnInterpretedText)
parseUntil(p, n, "`", true)
parseUntil(p, n, "`", false) # bug #17260
n = parsePostfix(p, n)
father.add(n)
elif isInlineMarkupStart(p, "|"):