parent
e94aec20da
commit
1590d14575
4 changed files with 39 additions and 10 deletions
|
|
@ -852,6 +852,9 @@ proc isInlineMarkupEnd(p: RstParser, markup: string): bool =
|
||||||
if not result: return
|
if not result: return
|
||||||
# Rule 4:
|
# Rule 4:
|
||||||
if p.idx > 0:
|
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 == "\\":
|
if markup != "``" and prevTok(p).symbol == "\\":
|
||||||
result = false
|
result = false
|
||||||
|
|
||||||
|
|
@ -1089,7 +1092,15 @@ proc parseUntil(p: var RstParser, father: PRstNode, postfix: string,
|
||||||
if isInlineMarkupEnd(p, postfix):
|
if isInlineMarkupEnd(p, postfix):
|
||||||
inc p.idx
|
inc p.idx
|
||||||
break
|
break
|
||||||
elif interpretBackslash:
|
else:
|
||||||
|
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)
|
parseBackslash(p, father)
|
||||||
else:
|
else:
|
||||||
father.add(newLeaf(p))
|
father.add(newLeaf(p))
|
||||||
|
|
@ -1243,7 +1254,7 @@ proc parseInline(p: var RstParser, father: PRstNode) =
|
||||||
father.add(n)
|
father.add(n)
|
||||||
elif isInlineMarkupStart(p, "`"):
|
elif isInlineMarkupStart(p, "`"):
|
||||||
var n = newRstNode(rnInterpretedText)
|
var n = newRstNode(rnInterpretedText)
|
||||||
parseUntil(p, n, "`", true)
|
parseUntil(p, n, "`", false) # bug #17260
|
||||||
n = parsePostfix(p, n)
|
n = parsePostfix(p, n)
|
||||||
father.add(n)
|
father.add(n)
|
||||||
elif isInlineMarkupStart(p, "|"):
|
elif isInlineMarkupStart(p, "|"):
|
||||||
|
|
|
||||||
|
|
@ -2827,7 +2827,7 @@ when declared(initDebugger):
|
||||||
proc addEscapedChar*(s: var string, c: char) {.noSideEffect, inline.} =
|
proc addEscapedChar*(s: var string, c: char) {.noSideEffect, inline.} =
|
||||||
## Adds a char to string `s` and applies the following escaping:
|
## 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 `"` by `\"`
|
## * replaces any `"` by `\"`
|
||||||
## * replaces any `\a` by `\\a`
|
## * 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 `\f` by `\\f`
|
||||||
## * replaces any `\r` by `\\r`
|
## * replaces any `\r` by `\\r`
|
||||||
## * replaces any `\e` by `\\e`
|
## * 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.
|
## by `\xHH` where `HH` is its hexadecimal value.
|
||||||
##
|
##
|
||||||
## The procedure has been designed so that its output is usable for many
|
## 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>
|
<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>
|
<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>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>E1 | text</td><td></td></tr>
|
||||||
<tr><td></td><td>F2 without pipe</td></tr>
|
<tr><td></td><td>F2 without pipe</td></tr>
|
||||||
</table><p>not in table </p>
|
</table><p>not in table </p>
|
||||||
|
|
|
||||||
|
|
@ -196,9 +196,15 @@ suite "RST/Markdown general":
|
||||||
| | F2 without pipe
|
| | F2 without pipe
|
||||||
not in table"""
|
not in table"""
|
||||||
let output1 = input1.toHtml
|
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>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>E1 | text</td><td></td></tr>
|
||||||
<tr><td></td><td>F2 without pipe</td></tr>
|
<tr><td></td><td>F2 without pipe</td></tr>
|
||||||
</table><p>not in table</p>
|
</table><p>not in table</p>
|
||||||
|
|
@ -549,6 +555,18 @@ let x = 1
|
||||||
let output2 = input2.toHtml
|
let output2 = input2.toHtml
|
||||||
doAssert "<pre" in output2 and "class=\"Keyword\"" in output2
|
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":
|
test "RST comments":
|
||||||
let input1 = """
|
let input1 = """
|
||||||
Check that comment disappears:
|
Check that comment disappears:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue