mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
docgen: support markdown link syntax; enable markdown extensions
This commit is contained in:
@@ -119,7 +119,7 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef,
|
||||
result.conf = conf
|
||||
result.cache = cache
|
||||
initRstGenerator(result[], (if conf.cmd != cmdRst2tex: outHtml else: outLatex),
|
||||
conf.configVars, filename.string, {roSupportRawDirective},
|
||||
conf.configVars, filename.string, {roSupportRawDirective, roSupportMarkdown},
|
||||
docgenFindFile, compilerMsgHandler)
|
||||
|
||||
if conf.configVars.hasKey("doc.googleAnalytics"):
|
||||
@@ -991,7 +991,7 @@ proc commandRstAux(cache: IdentCache, conf: ConfigRef;
|
||||
|
||||
d.isPureRst = true
|
||||
var rst = parseRst(readFile(filen.string), filen.string, 0, 1, d.hasToc,
|
||||
{roSupportRawDirective}, conf)
|
||||
{roSupportRawDirective, roSupportMarkdown}, conf)
|
||||
var modDesc = newStringOfCap(30_000)
|
||||
renderRstToOut(d[], rst, modDesc)
|
||||
d.modDesc = rope(modDesc)
|
||||
|
||||
@@ -780,6 +780,31 @@ proc parseMarkdownCodeblock(p: var RstParser): PRstNode =
|
||||
add(result, nil)
|
||||
add(result, lb)
|
||||
|
||||
proc parseMarkdownLink(p: var RstParser; father: PRstNode): bool =
|
||||
result = true
|
||||
var desc, link = ""
|
||||
var i = p.idx
|
||||
|
||||
template parse(endToken, dest) =
|
||||
inc i # skip begin token
|
||||
while true:
|
||||
if p.tok[i].kind in {tkEof, tkIndent}: return false
|
||||
if p.tok[i].symbol == endToken: break
|
||||
dest.add p.tok[i].symbol
|
||||
inc i
|
||||
inc i # skip end token
|
||||
|
||||
parse("]", desc)
|
||||
if p.tok[i].symbol != "(": return false
|
||||
parse(")", link)
|
||||
let child = newRstNode(rnHyperlink)
|
||||
child.add desc
|
||||
child.add link
|
||||
# only commit if we detected no syntax error:
|
||||
father.add child
|
||||
p.idx = i
|
||||
result = true
|
||||
|
||||
proc parseInline(p: var RstParser, father: PRstNode) =
|
||||
case p.tok[p.idx].kind
|
||||
of tkPunct:
|
||||
@@ -811,6 +836,9 @@ proc parseInline(p: var RstParser, father: PRstNode) =
|
||||
var n = newRstNode(rnSubstitutionReferences)
|
||||
parseUntil(p, n, "|", false)
|
||||
add(father, n)
|
||||
elif roSupportMarkdown in p.s.options and p.tok[p.idx].symbol == "[" and
|
||||
parseMarkdownLink(p, father):
|
||||
discard "parseMarkdownLink already processed it"
|
||||
else:
|
||||
if roSupportSmilies in p.s.options:
|
||||
let n = parseSmiley(p)
|
||||
|
||||
@@ -89,6 +89,9 @@ proc lastSon*(n: PRstNode): PRstNode =
|
||||
proc add*(father, son: PRstNode) =
|
||||
add(father.sons, son)
|
||||
|
||||
proc add*(father: PRstNode; s: string) =
|
||||
add(father.sons, newRstNode(rnLeaf, s))
|
||||
|
||||
proc addIfNotNil*(father, son: PRstNode) =
|
||||
if son != nil: add(father, son)
|
||||
|
||||
|
||||
@@ -28,5 +28,5 @@ proc test(dir: string; fixup = false) =
|
||||
echo "SUCCESS: files identical: ", produced
|
||||
removeDir(dir / "htmldocs")
|
||||
|
||||
test("nimdoc/testproject", false)
|
||||
test("nimdoc/testproject", defined(fixup))
|
||||
if failures > 0: quit($failures & " failures occurred.")
|
||||
|
||||
@@ -1369,7 +1369,7 @@ The enum B.
|
||||
<a id="someFunc,"></a>
|
||||
<dt><pre><span class="Keyword">func</span> <span class="Identifier">someFunc</span><span class="Other">(</span><span class="Other">)</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
|
||||
<dd>
|
||||
My someFunc.
|
||||
My someFunc. Stuff in <tt class="docutils literal"><span class="pre">quotes</span></tt> here. <a class="reference external" href="https://nim-lang.org">Some link</a>
|
||||
|
||||
</dd>
|
||||
|
||||
|
||||
@@ -23,4 +23,6 @@ template bEnum*(): untyped =
|
||||
|
||||
func someFunc*() =
|
||||
## My someFunc.
|
||||
## Stuff in `quotes` here.
|
||||
## [Some link](https://nim-lang.org)
|
||||
discard
|
||||
|
||||
Reference in New Issue
Block a user