Don't require blank line before Markdown code (#20215)
Fixes bug reported in https://github.com/nim-lang/Nim/pull/20189 affecting nimforum.
This commit is contained in:
parent
c579243e0c
commit
9f408ea943
4 changed files with 53 additions and 9 deletions
|
|
@ -37,8 +37,7 @@ when defined(nimPreviewSlimSystem):
|
||||||
##
|
##
|
||||||
## Now read the bits below to understand what's missing.
|
## Now read the bits below to understand what's missing.
|
||||||
##
|
##
|
||||||
## Issues with the Example
|
## ### Issues with the Example
|
||||||
## ```````````````````````
|
|
||||||
## Missing Sections:
|
## Missing Sections:
|
||||||
## This is a low level API, so headers and sections need to be stored and
|
## This is a low level API, so headers and sections need to be stored and
|
||||||
## loaded by the user, see `storeHeader` & `loadHeader` and `storeSection` &
|
## loaded by the user, see `storeHeader` & `loadHeader` and `storeSection` &
|
||||||
|
|
|
||||||
|
|
@ -1833,14 +1833,18 @@ proc parseFootnoteName(p: var RstParser, reference: bool): PRstNode =
|
||||||
inc i
|
inc i
|
||||||
p.idx = i
|
p.idx = i
|
||||||
|
|
||||||
proc isMarkdownCodeBlock(p: RstParser): bool =
|
proc isMarkdownCodeBlock(p: RstParser, idx: int): bool =
|
||||||
|
let tok = p.tok[idx]
|
||||||
template allowedSymbol: bool =
|
template allowedSymbol: bool =
|
||||||
(currentTok(p).symbol[0] == '`' or
|
(tok.symbol[0] == '`' or
|
||||||
roPreferMarkdown in p.s.options and currentTok(p).symbol[0] == '~')
|
roPreferMarkdown in p.s.options and tok.symbol[0] == '~')
|
||||||
result = (roSupportMarkdown in p.s.options and
|
result = (roSupportMarkdown in p.s.options and
|
||||||
currentTok(p).kind in {tkPunct, tkAdornment} and
|
tok.kind in {tkPunct, tkAdornment} and
|
||||||
allowedSymbol and
|
allowedSymbol and
|
||||||
currentTok(p).symbol.len >= 3)
|
tok.symbol.len >= 3)
|
||||||
|
|
||||||
|
proc isMarkdownCodeBlock(p: RstParser): bool =
|
||||||
|
isMarkdownCodeBlock(p, p.idx)
|
||||||
|
|
||||||
proc parseInline(p: var RstParser, father: PRstNode) =
|
proc parseInline(p: var RstParser, father: PRstNode) =
|
||||||
var n: PRstNode # to be used in `if` condition
|
var n: PRstNode # to be used in `if` condition
|
||||||
|
|
@ -2200,6 +2204,8 @@ proc isAdornmentHeadline(p: RstParser, adornmentIdx: int): bool =
|
||||||
## No support for Unicode.
|
## No support for Unicode.
|
||||||
if p.tok[adornmentIdx].symbol in ["::", "..", "|"]:
|
if p.tok[adornmentIdx].symbol in ["::", "..", "|"]:
|
||||||
return false
|
return false
|
||||||
|
if isMarkdownCodeBlock(p, adornmentIdx):
|
||||||
|
return false
|
||||||
var headlineLen = 0
|
var headlineLen = 0
|
||||||
var failure = ""
|
var failure = ""
|
||||||
if p.idx < adornmentIdx: # check for underline
|
if p.idx < adornmentIdx: # check for underline
|
||||||
|
|
|
||||||
|
|
@ -576,6 +576,45 @@ suite "RST parsing":
|
||||||
# | |
|
# | |
|
||||||
# | \ indentation of exactly two spaces before 'let a = 1'
|
# | \ indentation of exactly two spaces before 'let a = 1'
|
||||||
|
|
||||||
|
test "no blank line is required before or after Markdown code block":
|
||||||
|
let inputBacktick = dedent"""
|
||||||
|
Some text
|
||||||
|
```
|
||||||
|
CodeBlock()
|
||||||
|
```
|
||||||
|
Other text"""
|
||||||
|
let inputTilde = dedent"""
|
||||||
|
Some text
|
||||||
|
~~~~~~~~~
|
||||||
|
CodeBlock()
|
||||||
|
~~~~~~~~~
|
||||||
|
Other text"""
|
||||||
|
let expected = dedent"""
|
||||||
|
rnInner
|
||||||
|
rnParagraph
|
||||||
|
rnLeaf 'Some'
|
||||||
|
rnLeaf ' '
|
||||||
|
rnLeaf 'text'
|
||||||
|
rnParagraph
|
||||||
|
rnCodeBlock
|
||||||
|
[nil]
|
||||||
|
rnFieldList
|
||||||
|
rnField
|
||||||
|
rnFieldName
|
||||||
|
rnLeaf 'default-language'
|
||||||
|
rnFieldBody
|
||||||
|
rnLeaf 'Nim'
|
||||||
|
rnLiteralBlock
|
||||||
|
rnLeaf '
|
||||||
|
CodeBlock()'
|
||||||
|
rnLeaf ' '
|
||||||
|
rnLeaf 'Other'
|
||||||
|
rnLeaf ' '
|
||||||
|
rnLeaf 'text'
|
||||||
|
"""
|
||||||
|
check inputBacktick.toAst == expected
|
||||||
|
check inputTilde.toAst == expected
|
||||||
|
|
||||||
test "option list has priority over definition list":
|
test "option list has priority over definition list":
|
||||||
check(dedent"""
|
check(dedent"""
|
||||||
--defusages
|
--defusages
|
||||||
|
|
|
||||||
|
|
@ -389,7 +389,7 @@ Some chapter
|
||||||
~~~~~
|
~~~~~
|
||||||
|
|
||||||
"""
|
"""
|
||||||
let output9good = input9good.toHtml
|
let output9good = input9good.toHtml(preferRst)
|
||||||
doAssert "<h1 id=\"level1\">Level1</h1>" in output9good
|
doAssert "<h1 id=\"level1\">Level1</h1>" in output9good
|
||||||
doAssert "<h2 id=\"level2\">Level2</h2>" in output9good
|
doAssert "<h2 id=\"level2\">Level2</h2>" in output9good
|
||||||
doAssert "<h3 id=\"level3\">Level3</h3>" in output9good
|
doAssert "<h3 id=\"level3\">Level3</h3>" in output9good
|
||||||
|
|
@ -419,7 +419,7 @@ Some chapter
|
||||||
|
|
||||||
"""
|
"""
|
||||||
var error9Bad = new string
|
var error9Bad = new string
|
||||||
let output9Bad = input9Bad.toHtml(error=error9Bad)
|
let output9Bad = input9Bad.toHtml(preferRst, error=error9Bad)
|
||||||
check(error9Bad[] == "input(15, 1) Error: new section expected (section " &
|
check(error9Bad[] == "input(15, 1) Error: new section expected (section " &
|
||||||
"level inconsistent: underline ~~~~~ unexpectedly found, while " &
|
"level inconsistent: underline ~~~~~ unexpectedly found, while " &
|
||||||
"the following intermediate section level(s) are missing on " &
|
"the following intermediate section level(s) are missing on " &
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue