mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-19 07:21:19 +00:00
@@ -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, "|"):
|
||||
|
||||
@@ -2827,7 +2827,7 @@ when declared(initDebugger):
|
||||
proc addEscapedChar*(s: var string, c: char) {.noSideEffect, inline.} =
|
||||
## Adds a char to string `s` and applies the following escaping:
|
||||
##
|
||||
## * replaces any `\` by `\\`
|
||||
## * replaces any ``\`` by `\\`
|
||||
## * replaces any `'` by `\'`
|
||||
## * replaces any `"` by `\"`
|
||||
## * replaces any `\a` by `\\a`
|
||||
@@ -2838,7 +2838,7 @@ proc addEscapedChar*(s: var string, c: char) {.noSideEffect, inline.} =
|
||||
## * replaces any `\f` by `\\f`
|
||||
## * replaces any `\r` by `\\r`
|
||||
## * replaces any `\e` by `\\e`
|
||||
## * replaces any other character not in the set `{'\21..'\126'}
|
||||
## * replaces any other character not in the set `{\21..\126}`
|
||||
## by `\xHH` where `HH` is its hexadecimal value.
|
||||
##
|
||||
## The procedure has been designed so that its output is usable for many
|
||||
|
||||
@@ -300,7 +300,7 @@ stmt = IND{>} stmt ^+ IND{=} DED # list of statements
|
||||
<p>However, this does not work. The problem is that the procedure should not only <tt class="docutils literal"><span class="pre">return</span></tt>, but return and <strong>continue</strong> after an iteration has finished. This <em>return and continue</em> is called a <tt class="docutils literal"><span class="pre">yield</span></tt> statement. Now the only thing left to do is to replace the <tt class="docutils literal"><span class="pre">proc</span></tt> keyword by <tt class="docutils literal"><span class="pre">iterator</span></tt> and here it is - our first iterator:</p>
|
||||
<table border="1" class="docutils"><tr><th>A1 header</th><th>A2 | not fooled</th></tr>
|
||||
<tr><td>C1</td><td>C2 <strong>bold</strong></td></tr>
|
||||
<tr><td>D1 <tt class="docutils literal"><span class="pre">code |</span></tt></td><td>D2</td></tr>
|
||||
<tr><td>D1 <tt class="docutils literal"><span class="pre">code \|</span></tt></td><td>D2</td></tr>
|
||||
<tr><td>E1 | text</td><td></td></tr>
|
||||
<tr><td></td><td>F2 without pipe</td></tr>
|
||||
</table><p>not in table </p>
|
||||
|
||||
@@ -196,9 +196,15 @@ suite "RST/Markdown general":
|
||||
| | F2 without pipe
|
||||
not in table"""
|
||||
let output1 = input1.toHtml
|
||||
doAssert output1 == """<table border="1" class="docutils"><tr><th>A1 header</th><th>A2 | not fooled</th></tr>
|
||||
#[
|
||||
TODO: `\|` inside a table cell should render as `|`
|
||||
`|` outside a table cell should render as `\|`
|
||||
consistently with markdown, see https://stackoverflow.com/a/66557930/1426932
|
||||
]#
|
||||
doAssert output1 == """
|
||||
<table border="1" class="docutils"><tr><th>A1 header</th><th>A2 | not fooled</th></tr>
|
||||
<tr><td>C1</td><td>C2 <strong>bold</strong></td></tr>
|
||||
<tr><td>D1 <tt class="docutils literal"><span class="pre">code |</span></tt></td><td>D2</td></tr>
|
||||
<tr><td>D1 <tt class="docutils literal"><span class="pre">code \|</span></tt></td><td>D2</td></tr>
|
||||
<tr><td>E1 | text</td><td></td></tr>
|
||||
<tr><td></td><td>F2 without pipe</td></tr>
|
||||
</table><p>not in table</p>
|
||||
@@ -549,6 +555,18 @@ let x = 1
|
||||
let output2 = input2.toHtml
|
||||
doAssert "<pre" in output2 and "class=\"Keyword\"" in output2
|
||||
|
||||
test "interpreted text":
|
||||
check """`foo.bar`""".toHtml == """<tt class="docutils literal"><span class="pre">foo.bar</span></tt>"""
|
||||
check """`foo\`\`bar`""".toHtml == """<tt class="docutils literal"><span class="pre">foo``bar</span></tt>"""
|
||||
check """`foo\`bar`""".toHtml == """<tt class="docutils literal"><span class="pre">foo`bar</span></tt>"""
|
||||
check """`\`bar`""".toHtml == """<tt class="docutils literal"><span class="pre">`bar</span></tt>"""
|
||||
check """`a\b\x\\ar`""".toHtml == """<tt class="docutils literal"><span class="pre">a\b\x\\ar</span></tt>"""
|
||||
|
||||
test "inline literal":
|
||||
check """``foo.bar``""".toHtml == """<tt class="docutils literal"><span class="pre">foo.bar</span></tt>"""
|
||||
check """``foo\bar``""".toHtml == """<tt class="docutils literal"><span class="pre">foo\bar</span></tt>"""
|
||||
check """``f\`o\\o\b`ar``""".toHtml == """<tt class="docutils literal"><span class="pre">f\`o\\o\b`ar</span></tt>"""
|
||||
|
||||
test "RST comments":
|
||||
let input1 = """
|
||||
Check that comment disappears:
|
||||
|
||||
Reference in New Issue
Block a user