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:
Andrey Makarov 2022-08-16 01:37:45 +03:00 • committed by GitHub
commit 9f408ea943
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 9 deletions

View file

@ -1833,14 +1833,18 @@ proc parseFootnoteName(p: var RstParser, reference: bool): PRstNode =
inc i
p.idx = i
proc isMarkdownCodeBlock(p: RstParser): bool =
proc isMarkdownCodeBlock(p: RstParser, idx: int): bool =
let tok = p.tok[idx]
template allowedSymbol: bool =
(currentTok(p).symbol[0] == '`' or
roPreferMarkdown in p.s.options and currentTok(p).symbol[0] == '~')
(tok.symbol[0] == '`' or
roPreferMarkdown in p.s.options and tok.symbol[0] == '~')
result = (roSupportMarkdown in p.s.options and
currentTok(p).kind in {tkPunct, tkAdornment} and
tok.kind in {tkPunct, tkAdornment} 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) =
var n: PRstNode # to be used in `if` condition
@ -2200,6 +2204,8 @@ proc isAdornmentHeadline(p: RstParser, adornmentIdx: int): bool =
## 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