mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 13:30:33 +00:00
fixes docgen regression: don't add newLine for code if it's the first line (#23154)
Before (devel)  After (this PR and stable)  It now keeps the same behavior as before
This commit is contained in:
@@ -1603,6 +1603,7 @@ proc parseMarkdownCodeblock(p: var RstParser): PRstNode =
|
||||
else:
|
||||
args = nil
|
||||
var n = newLeaf("")
|
||||
var isFirstLine = true
|
||||
while true:
|
||||
if currentTok(p).kind == tkEof:
|
||||
rstMessage(p, meMissingClosing,
|
||||
@@ -1614,7 +1615,8 @@ proc parseMarkdownCodeblock(p: var RstParser): PRstNode =
|
||||
inc p.idx, 2
|
||||
break
|
||||
elif currentTok(p).kind == tkIndent:
|
||||
n.text.add "\n"
|
||||
if not isFirstLine:
|
||||
n.text.add "\n"
|
||||
if currentTok(p).ival > baseCol:
|
||||
n.text.add " ".repeat(currentTok(p).ival - baseCol)
|
||||
elif currentTok(p).ival < baseCol:
|
||||
@@ -1624,6 +1626,7 @@ proc parseMarkdownCodeblock(p: var RstParser): PRstNode =
|
||||
else:
|
||||
n.text.add(currentTok(p).symbol)
|
||||
inc p.idx
|
||||
isFirstLine = false
|
||||
result.sons[0] = args
|
||||
if result.sons[2] == nil:
|
||||
var lb = newRstNode(rnLiteralBlock)
|
||||
|
||||
@@ -62,8 +62,7 @@
|
||||
<div id="tocRoot"></div>
|
||||
|
||||
<p class="module-desc"><p>Check</p>
|
||||
<p><pre class="listing">
|
||||
<span class="Identifier">text</span></pre></p>
|
||||
<p><pre class="listing"><span class="Identifier">text</span></pre></p>
|
||||
|
||||
<h1><a class="toc-backref" id="check" href="#check">Check</a></h1>
|
||||
<h1><a class="toc-backref" id="text" href="#text">text</a></h1></p>
|
||||
|
||||
@@ -526,8 +526,7 @@ suite "RST parsing":
|
||||
rnFieldBody
|
||||
rnLeaf 'Nim'
|
||||
rnLiteralBlock
|
||||
rnLeaf '
|
||||
let a = 1
|
||||
rnLeaf 'let a = 1
|
||||
```'
|
||||
"""
|
||||
|
||||
@@ -637,8 +636,7 @@ suite "RST parsing":
|
||||
rnLeaf 'test'
|
||||
rnFieldBody
|
||||
rnLiteralBlock
|
||||
rnLeaf '
|
||||
let a = 1'
|
||||
rnLeaf 'let a = 1'
|
||||
""")
|
||||
|
||||
check(dedent"""
|
||||
@@ -661,8 +659,7 @@ suite "RST parsing":
|
||||
rnFieldBody
|
||||
rnLeaf '1'
|
||||
rnLiteralBlock
|
||||
rnLeaf '
|
||||
let a = 1'
|
||||
rnLeaf 'let a = 1'
|
||||
""")
|
||||
|
||||
test "additional indentation < 4 spaces is handled fine":
|
||||
@@ -682,8 +679,7 @@ suite "RST parsing":
|
||||
rnLeaf 'nim'
|
||||
[nil]
|
||||
rnLiteralBlock
|
||||
rnLeaf '
|
||||
let a = 1'
|
||||
rnLeaf ' let a = 1'
|
||||
""")
|
||||
# | |
|
||||
# | \ indentation of exactly two spaces before 'let a = 1'
|
||||
@@ -717,8 +713,7 @@ suite "RST parsing":
|
||||
rnFieldBody
|
||||
rnLeaf 'Nim'
|
||||
rnLiteralBlock
|
||||
rnLeaf '
|
||||
CodeBlock()'
|
||||
rnLeaf 'CodeBlock()'
|
||||
rnLeaf ' '
|
||||
rnLeaf 'Other'
|
||||
rnLeaf ' '
|
||||
|
||||
@@ -1246,7 +1246,7 @@ Test1
|
||||
"input(8, 4) Warning: language 'anotherLang' not supported"
|
||||
])
|
||||
check(output == "<pre class = \"listing\">anything</pre>" &
|
||||
"<p><pre class = \"listing\">\nsomeCode</pre> </p>")
|
||||
"<p><pre class = \"listing\">someCode</pre> </p>")
|
||||
|
||||
test "RST admonitions":
|
||||
# check that all admonitions are implemented
|
||||
|
||||
Reference in New Issue
Block a user