docgen: support markdown headings too
This commit is contained in:
parent
5ef5dc86c5
commit
ee7f2d97cc
4 changed files with 57 additions and 11 deletions
|
|
@ -1065,15 +1065,32 @@ proc isOptionList(p: RstParser): bool =
|
||||||
result = match(p, p.idx, "-w") or match(p, p.idx, "--w") or
|
result = match(p, p.idx, "-w") or match(p, p.idx, "--w") or
|
||||||
match(p, p.idx, "/w") or match(p, p.idx, "//w")
|
match(p, p.idx, "/w") or match(p, p.idx, "//w")
|
||||||
|
|
||||||
|
proc isMarkdownHeadlinePattern(s: string): bool =
|
||||||
|
if s.len >= 1 and s.len <= 6:
|
||||||
|
for c in s:
|
||||||
|
if c != '#': return false
|
||||||
|
result = true
|
||||||
|
|
||||||
|
proc isMarkdownHeadline(p: RstParser): bool =
|
||||||
|
if roSupportMarkdown in p.s.options:
|
||||||
|
if isMarkdownHeadlinePattern(p.tok[p.idx].symbol) and p.tok[p.idx+1].kind == tkWhite:
|
||||||
|
if p.tok[p.idx+2].kind in {tkWord, tkOther, tkPunct}:
|
||||||
|
result = true
|
||||||
|
|
||||||
proc whichSection(p: RstParser): RstNodeKind =
|
proc whichSection(p: RstParser): RstNodeKind =
|
||||||
case p.tok[p.idx].kind
|
case p.tok[p.idx].kind
|
||||||
of tkAdornment:
|
of tkAdornment:
|
||||||
if match(p, p.idx + 1, "ii"): result = rnTransition
|
if match(p, p.idx + 1, "ii"): result = rnTransition
|
||||||
elif match(p, p.idx + 1, " a"): result = rnTable
|
elif match(p, p.idx + 1, " a"): result = rnTable
|
||||||
elif match(p, p.idx + 1, "i"): result = rnOverline
|
elif match(p, p.idx + 1, "i"): result = rnOverline
|
||||||
else: result = rnLeaf
|
elif isMarkdownHeadline(p):
|
||||||
|
result = rnHeadline
|
||||||
|
else:
|
||||||
|
result = rnLeaf
|
||||||
of tkPunct:
|
of tkPunct:
|
||||||
if match(p, tokenAfterNewline(p), "ai"):
|
if isMarkdownHeadline(p):
|
||||||
|
result = rnHeadline
|
||||||
|
elif match(p, tokenAfterNewline(p), "ai"):
|
||||||
result = rnHeadline
|
result = rnHeadline
|
||||||
elif p.tok[p.idx].symbol == "::":
|
elif p.tok[p.idx].symbol == "::":
|
||||||
result = rnLiteralBlock
|
result = rnLiteralBlock
|
||||||
|
|
@ -1158,6 +1175,12 @@ proc parseParagraph(p: var RstParser, result: PRstNode) =
|
||||||
|
|
||||||
proc parseHeadline(p: var RstParser): PRstNode =
|
proc parseHeadline(p: var RstParser): PRstNode =
|
||||||
result = newRstNode(rnHeadline)
|
result = newRstNode(rnHeadline)
|
||||||
|
if isMarkdownHeadline(p):
|
||||||
|
result.level = p.tok[p.idx].symbol.len
|
||||||
|
assert(p.tok[p.idx+1].kind == tkWhite)
|
||||||
|
inc p.idx, 2
|
||||||
|
parseUntilNewline(p, result)
|
||||||
|
else:
|
||||||
parseUntilNewline(p, result)
|
parseUntilNewline(p, result)
|
||||||
assert(p.tok[p.idx].kind == tkIndent)
|
assert(p.tok[p.idx].kind == tkIndent)
|
||||||
assert(p.tok[p.idx + 1].kind == tkAdornment)
|
assert(p.tok[p.idx + 1].kind == tkAdornment)
|
||||||
|
|
|
||||||
|
|
@ -1238,7 +1238,12 @@ function main() {
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<ul class="simple simple-toc" id="toc-list">
|
<ul class="simple simple-toc" id="toc-list">
|
||||||
<li>
|
<li><a class="reference" id="this-is-now-a-header_toc" href="#this-is-now-a-header">This is now a header</a></li>
|
||||||
|
<ul class="simple"><li><a class="reference" id="this-is-now-a-header-next-header_toc" href="#this-is-now-a-header-next-header">Next header</a></li>
|
||||||
|
<ul class="simple"><li><a class="reference" id="next-header-and-so-on_toc" href="#next-header-and-so-on">And so on</a></li>
|
||||||
|
</ul></ul><li><a class="reference" id="more-headers_toc" href="#more-headers">More headers</a></li>
|
||||||
|
<ul class="simple"><li><a class="reference" id="more-headers-up-to-level-6_toc" href="#more-headers-up-to-level-6">Up to level 6</a></li>
|
||||||
|
</ul><li>
|
||||||
<a class="reference reference-toplevel" href="#7" id="57">Types</a>
|
<a class="reference reference-toplevel" href="#7" id="57">Types</a>
|
||||||
<ul class="simple simple-toc-section">
|
<ul class="simple simple-toc-section">
|
||||||
<li><a class="reference" href="#SomeType"
|
<li><a class="reference" href="#SomeType"
|
||||||
|
|
@ -1271,7 +1276,12 @@ function main() {
|
||||||
</div>
|
</div>
|
||||||
<div class="nine columns" id="content">
|
<div class="nine columns" id="content">
|
||||||
<div id="tocRoot"></div>
|
<div id="tocRoot"></div>
|
||||||
<p class="module-desc"></p>
|
<p class="module-desc">
|
||||||
|
<h1><a class="toc-backref" id="this-is-now-a-header" href="#this-is-now-a-header">This is now a header</a></h1>
|
||||||
|
<h2><a class="toc-backref" id="this-is-now-a-header-next-header" href="#this-is-now-a-header-next-header">Next header</a></h2>
|
||||||
|
<h3><a class="toc-backref" id="next-header-and-so-on" href="#next-header-and-so-on">And so on</a></h3>
|
||||||
|
<h1><a class="toc-backref" id="more-headers" href="#more-headers">More headers</a></h1>
|
||||||
|
<h6><a class="toc-backref" id="more-headers-up-to-level-6" href="#more-headers-up-to-level-6">Up to level 6</a></h6></p>
|
||||||
<div class="section" id="7">
|
<div class="section" id="7">
|
||||||
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
||||||
<dl class="item">
|
<dl class="item">
|
||||||
|
|
|
||||||
|
|
@ -1220,7 +1220,7 @@ function main() {
|
||||||
<div class="document" id="documentId">
|
<div class="document" id="documentId">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="title">Index</h1>
|
<h1 class="title">Index</h1>
|
||||||
Modules: <a href="subdir/subdir_b/utils.html">subdir/subdir_b/utils</a>, <a href="testproject.html">testproject</a>.<br/><p /><h2>API symbols</h2>
|
Modules: <a href="testproject.html">testproject</a>, <a href="utils.html">utils</a>.<br/><p /><h2>API symbols</h2>
|
||||||
<dl><dt><a name="A" href="#A"><span>A:</span></a></dt><dd><ul class="simple">
|
<dl><dt><a name="A" href="#A"><span>A:</span></a></dt><dd><ul class="simple">
|
||||||
<li><a class="reference external"
|
<li><a class="reference external"
|
||||||
data-doc-search-tag="testproject: A" href="testproject.html#A">testproject: A</a></li>
|
data-doc-search-tag="testproject: A" href="testproject.html#A">testproject: A</a></li>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,16 @@
|
||||||
|
##[
|
||||||
|
|
||||||
|
# This is now a header
|
||||||
|
|
||||||
|
## Next header
|
||||||
|
|
||||||
|
### And so on
|
||||||
|
|
||||||
|
# More headers
|
||||||
|
|
||||||
|
###### Up to level 6
|
||||||
|
|
||||||
|
]##
|
||||||
|
|
||||||
type
|
type
|
||||||
SomeType* = enum
|
SomeType* = enum
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue