diff options
author | Andrey Makarov <ph.makarov@gmail.com> | 2022-10-05 21:03:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 14:03:10 -0400 |
commit | 6505bd347df557713061d4e84cf9548d104622d9 (patch) | |
tree | 8f48f1d066b9e807b2c5550edb5f743e7cc7fa01 /lib/packages/docutils/rst.nim | |
parent | 594e93a66bd19297d23d3328a3f35aa6ac3789af (diff) | |
download | Nim-6505bd347df557713061d4e84cf9548d104622d9.tar.gz |
Markdown indented code blocks (#20473)
* Implement Markdown indented code blocks Additional indentation of 4 spaces makes a block an "indented code block" (monospaced text without syntax highlighting). Also `::` RST syntax for code blocks is disabled. So instead of ```rst see:: Some code ``` the code block should be written as ```markdown see: Some code ``` * Migrate RST literal blocks :: to Markdown's ones
Diffstat (limited to 'lib/packages/docutils/rst.nim')
-rw-r--r-- | lib/packages/docutils/rst.nim | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/packages/docutils/rst.nim b/lib/packages/docutils/rst.nim index 3c95c9ef0..f81be7a50 100644 --- a/lib/packages/docutils/rst.nim +++ b/lib/packages/docutils/rst.nim @@ -2172,7 +2172,7 @@ proc whichSection(p: RstParser): RstNodeKind = # for punctuation sequences that can be both tkAdornment and tkPunct if isMarkdownCodeBlock(p): return rnCodeBlock - elif currentTok(p).symbol == "::": + elif isRst(p) and currentTok(p).symbol == "::": return rnLiteralBlock elif currentTok(p).symbol == ".." and nextTok(p).kind in {tkWhite, tkIndent}: @@ -2362,8 +2362,10 @@ proc parseParagraph(p: var RstParser, result: PRstNode) = of tkIndent: if nextTok(p).kind == tkIndent: inc p.idx - break - elif currentTok(p).ival == currInd(p): + break # blank line breaks paragraph for both Md & Rst + elif currentTok(p).ival == currInd(p) or ( + isMd(p) and currentTok(p).ival > currInd(p)): + # (Md allows adding additional indentation inside paragraphs) inc p.idx case whichSection(p) of rnParagraph, rnLeaf, rnHeadline, rnMarkdownHeadline, @@ -2377,7 +2379,8 @@ proc parseParagraph(p: var RstParser, result: PRstNode) = else: break of tkPunct: - if (let literalBlockKind = whichRstLiteralBlock(p); + if isRst(p) and ( + let literalBlockKind = whichRstLiteralBlock(p); literalBlockKind != lbNone): result.add newLeaf(":") inc p.idx # skip '::' @@ -2932,11 +2935,11 @@ proc parseSection(p: var RstParser, result: PRstNode) = elif currentTok(p).ival > currInd(p): if roPreferMarkdown in p.s.options: # Markdown => normal paragraphs if currentTok(p).ival - currInd(p) >= 4: - rstMessage(p, mwRstStyle, - "Markdown indented code not implemented") - pushInd(p, currentTok(p).ival) - parseSection(p, result) - popInd(p) + result.add parseLiteralBlock(p) + else: + pushInd(p, currentTok(p).ival) + parseSection(p, result) + popInd(p) else: # RST mode => block quotes pushInd(p, currentTok(p).ival) var a = newRstNodeA(p, rnBlockQuote) |