mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 06:20:38 +00:00
restyle RST option lists (#17637)
* WIP: restyle RST option lists * apply similar style to Latex * fix tests * minor visual tweaks * update tests * remove leftover comments
This commit is contained in:
@@ -2085,6 +2085,7 @@ proc parseBulletList(p: var RstParser): PRstNode =
|
||||
proc parseOptionList(p: var RstParser): PRstNode =
|
||||
result = newRstNodeA(p, rnOptionList)
|
||||
let col = currentTok(p).col
|
||||
var order = 1
|
||||
while true:
|
||||
if currentTok(p).col == col and isOptionList(p):
|
||||
var a = newRstNode(rnOptionGroup)
|
||||
@@ -2107,6 +2108,7 @@ proc parseOptionList(p: var RstParser): PRstNode =
|
||||
if currentTok(p).kind == tkIndent: inc p.idx
|
||||
c.add(a)
|
||||
c.add(b)
|
||||
c.order = order; inc order
|
||||
result.add(c)
|
||||
else:
|
||||
if currentTok(p).kind != tkEof: dec p.idx # back to tkIndent
|
||||
|
||||
@@ -90,7 +90,7 @@ type
|
||||
level*: int ## level of headings starting from 1 (main
|
||||
## chapter) to larger ones (minor sub-sections)
|
||||
## level=0 means it's document title or subtitle
|
||||
of rnFootnote, rnCitation, rnFootnoteRef:
|
||||
of rnFootnote, rnCitation, rnFootnoteRef, rnOptionListItem:
|
||||
order*: int ## footnote order (for auto-symbol footnotes and
|
||||
## auto-numbered ones without a label)
|
||||
else:
|
||||
@@ -368,7 +368,7 @@ proc renderRstToStr*(node: PRstNode, indent=0): string =
|
||||
result.add txt
|
||||
of rnHeadline, rnOverline, rnMarkdownHeadline:
|
||||
result.add "\tlevel=" & $node.level
|
||||
of rnFootnote, rnCitation, rnFootnoteRef:
|
||||
of rnFootnote, rnCitation, rnFootnoteRef, rnOptionListItem:
|
||||
result.add (if node.order == 0: "" else: "\torder=" & $node.order)
|
||||
else:
|
||||
discard
|
||||
|
||||
@@ -1165,7 +1165,7 @@ proc renderRstToOut(d: PDoc, n: PRstNode, result: var string) =
|
||||
renderAux(d, n, "<dl$2 class=\"docutils\">$1</dl>\n",
|
||||
"\\begin{description}\n$2\n$1\\end{description}\n", result)
|
||||
of rnDefItem: renderAux(d, n, result)
|
||||
of rnDefName: renderAux(d, n, "<dt$2>$1</dt>\n", "$2\\item[$1] ", result)
|
||||
of rnDefName: renderAux(d, n, "<dt$2>$1</dt>\n", "$2\\item[$1]\\ ", result)
|
||||
of rnDefBody: renderAux(d, n, "<dd$2>$1</dd>\n", "$2\n$1\n", result)
|
||||
of rnFieldList:
|
||||
var tmp = ""
|
||||
@@ -1189,14 +1189,20 @@ proc renderRstToOut(d: PDoc, n: PRstNode, result: var string) =
|
||||
of rnIndex:
|
||||
renderRstToOut(d, n.sons[2], result)
|
||||
of rnOptionList:
|
||||
renderAux(d, n, "<table$2 frame=\"void\">$1</table>",
|
||||
"\\begin{description}\n$2\n$1\\end{description}\n", result)
|
||||
renderAux(d, n, "<div$2 class=\"option-list\">$1</div>",
|
||||
"\\begin{rstoptlist}$2\n$1\\end{rstoptlist}", result)
|
||||
of rnOptionListItem:
|
||||
renderAux(d, n, "<tr>$1</tr>\n", "$1", result)
|
||||
var addclass = if n.order mod 2 == 1: " odd" else: ""
|
||||
renderAux(d, n,
|
||||
"<div class=\"option-list-item" & addclass & "\">$1</div>\n",
|
||||
"$1", result)
|
||||
of rnOptionGroup:
|
||||
renderAux(d, n, "<th align=\"left\">$1</th>", "\\item[$1]", result)
|
||||
renderAux(d, n,
|
||||
"<div class=\"option-list-label\">$1</div>",
|
||||
"\\item[$1]", result)
|
||||
of rnDescription:
|
||||
renderAux(d, n, "<td align=\"left\">$1</td>\n", " $1\n", result)
|
||||
renderAux(d, n, "<div class=\"option-list-description\">$1</div>",
|
||||
" $1\n", result)
|
||||
of rnOption, rnOptionString, rnOptionArgument:
|
||||
doAssert false, "renderRstToOut"
|
||||
of rnLiteralBlock:
|
||||
|
||||
Reference in New Issue
Block a user