diff options
author | Andrey Makarov <ph.makarov@gmail.com> | 2022-08-16 01:37:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-15 18:37:45 -0400 |
commit | 9f408ea9430b104eb6c14a84d7a1650bf115b6a0 (patch) | |
tree | 61a9473eb3e4cdd5ef6996fec01bd254c7f8127d /lib/packages/docutils/rst.nim | |
parent | c579243e0cdba83a07357637d4bcef8594263207 (diff) | |
download | Nim-9f408ea9430b104eb6c14a84d7a1650bf115b6a0.tar.gz |
Don't require blank line before Markdown code (#20215)
Fixes bug reported in https://github.com/nim-lang/Nim/pull/20189 affecting nimforum.
Diffstat (limited to 'lib/packages/docutils/rst.nim')
-rw-r--r-- | lib/packages/docutils/rst.nim | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim index 91076bbee..b3adbf9de 100644 --- a/lib/packages/docutils/rst.nim +++ b/lib/packages/docutils/rst.nim @@ -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 |