RST: implement admonitions (#16438)

This commit is contained in:
Andrey Makarov 2020-12-27 13:16:12 +03:00 • committed by GitHub
commit 2bdc479622
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 239 additions and 54 deletions

View file

@ -41,8 +41,11 @@ type
rnLabel, # used for footnotes and other things
rnFootnote, # a footnote
rnCitation, # similar to footnote
rnStandaloneHyperlink, rnHyperlink, rnRef, rnDirective, # a directive
rnDirArg, rnRaw, rnTitle, rnContents, rnImage, rnFigure, rnCodeBlock,
rnStandaloneHyperlink, rnHyperlink, rnRef,
rnDirective, # a general directive
rnDirArg, # a directive argument (for some directives).
# here are directives that are not rnDirective:
rnRaw, rnTitle, rnContents, rnImage, rnFigure, rnCodeBlock, rnAdmonition,
rnRawHtml, rnRawLatex,
rnContainer, # ``container`` directive
rnIndex, # index directve:
@ -70,6 +73,7 @@ type
kind*: RstNodeKind ## the node's kind
text*: string ## valid for leafs in the AST; and the title of
## the document or the section; and rnEnumList
## and rnAdmonition
level*: int ## valid for some node kinds
sons*: RstNodeSeq ## the node's sons
@ -316,3 +320,17 @@ proc renderRstToJson*(node: PRstNode): string =
## "sons":optional node array
## }
renderRstToJsonNode(node).pretty
proc renderRstToStr*(node: PRstNode, indent=0): string =
## Writes the parsed RST `node` into a compact string
## representation in the format (one line per every sub-node):
## ``indent - kind - text - level (if non-zero)``
## (suitable for debugging of RST parsing).
if node == nil:
result.add " ".repeat(indent) & "[nil]\n"
return
result.add " ".repeat(indent) & $node.kind & "\t" &
(if node.text == "": "" else: "'" & node.text & "'") &
(if node.level == 0: "" else: "\tlevel=" & $node.level) & "\n"
for son in node.sons:
result.add renderRstToStr(son, indent=indent+2)