Skip to content

Commit

Permalink
Don't require blank line before Markdown code
Browse files Browse the repository at this point in the history
Fixes bug reported in nim-lang#20189
affecting nimforum.
(manually backported version to 1.6 from devel)
  • Loading branch information
a-mr committed Aug 13, 2022
1 parent 65e0906 commit d7872c0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
3 changes: 1 addition & 2 deletions compiler/ic/rodfiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ from typetraits import supportsCopyMem
##
## Now read the bits below to understand what's missing.
##
## Issues with the Example
## ```````````````````````
## ### Issues with the Example
## Missing Sections:
## This is a low level API, so headers and sections need to be stored and
## loaded by the user, see `storeHeader` & `loadHeader` and `storeSection` &
Expand Down
7 changes: 6 additions & 1 deletion lib/packages/docutils/rst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1864,11 +1864,16 @@ proc countTitles(s: PRstSharedState, n: PRstNode) =
if s.hTitleCnt >= 2:
break

proc isMarkdownCodeBlock(p: RstParser, idx: int): bool =
roSupportMarkdown in p.s.options and p.tok[idx].symbol == "```"

proc isAdornmentHeadline(p: RstParser, adornmentIdx: int): bool =
## check that underline/overline length is enough for the heading.
## No support for Unicode.
if p.tok[adornmentIdx].symbol in ["::", "..", "|"]:
return false
if isMarkdownCodeBlock(p, adornmentIdx):
return false
var headlineLen = 0
var failure = ""
if p.idx < adornmentIdx: # check for underline
Expand Down Expand Up @@ -1946,7 +1951,7 @@ proc findPipe(p: RstParser, start: int): bool =
proc whichSection(p: RstParser): RstNodeKind =
if currentTok(p).kind in {tkAdornment, tkPunct}:
# for punctuation sequences that can be both tkAdornment and tkPunct
if roSupportMarkdown in p.s.options and currentTok(p).symbol == "```":
if isMarkdownCodeBlock(p, p.idx):
return rnCodeBlock
elif currentTok(p).symbol == "::":
return rnLiteralBlock
Expand Down
27 changes: 27 additions & 0 deletions tests/stdlib/trst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,33 @@ suite "RST parsing":
rnLeaf 'desc2'
""")

test "no blank line is required before or after Markdown code block":
check(dedent"""
Some text
```
CodeBlock()
```
Other text""".toAst ==
dedent"""
rnInner
rnParagraph
rnLeaf 'Some'
rnLeaf ' '
rnLeaf 'text'
rnParagraph
rnCodeBlock
[nil]
[nil]
rnLiteralBlock
rnLeaf '
CodeBlock()
'
rnLeaf ' '
rnLeaf 'Other'
rnLeaf ' '
rnLeaf 'text'
""")

test "option list has priority over definition list":
check(dedent"""
defName
Expand Down

0 comments on commit d7872c0

Please sign in to comment.