diff --git a/compiler/docgen.nim b/compiler/docgen.nim index a2166784b..f34a83145 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -300,13 +300,17 @@ proc externalDep(d: PDoc; module: PSym): string = else: result = extractFilename toFullPath(d.conf, FileIndex module.position) -proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRenderFlags = {}) = +proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRenderFlags = {}; + procLink: Rope) = var r: TSrcGen var literal = "" initTokRender(r, n, renderFlags) var kind = tkEof + var tokenPos = 0 + var procTokenPos = 0 while true: getNextTok(r, kind, literal) + inc tokenPos case kind of tkEof: break @@ -314,6 +318,8 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe dispA(d.conf, result, "$1", "\\spanComment{$1}", [rope(esc(d.target, literal))]) of tokKeywordLow..tokKeywordHigh: + if kind in {tkProc, tkMethod, tkIterator, tkMacro, tkTemplate, tkFunc, tkConverter}: + procTokenPos = tokenPos dispA(d.conf, result, "$1", "\\spanKeyword{$1}", [rope(literal)]) of tkOpr: @@ -333,7 +339,11 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe "\\spanFloatNumber{$1}", [rope(esc(d.target, literal))]) of tkSymbol: let s = getTokSym(r) - if s != nil and s.kind == skType and sfExported in s.flags and + # -2 because of the whitespace in between: + if procTokenPos == tokenPos-2 and procLink != nil: + dispA(d.conf, result, "$1", + "\\spanIdentifier{$1}", [rope(esc(d.target, literal)), procLink]) + elif s != nil and s.kind == skType and sfExported in s.flags and s.owner != nil and belongsToPackage(d.conf, s.owner) and d.target == outHtml: let external = externalDep(d, s.owner) @@ -445,7 +455,7 @@ proc getAllRunnableExamplesRec(d: PDoc; n, orig: PNode; dest: var Rope) = for b in body: if i > 0: dest.add "\n" inc i - nodeToHighlightedHtml(d, b, dest, {}) + nodeToHighlightedHtml(d, b, dest, {}, nil) dest.add(d.config.getOrDefault"doc.listing_end" % id) else: discard for i in 0 ..< n.safeLen: @@ -615,9 +625,6 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) = break plainName.add(literal) - nodeToHighlightedHtml(d, n, result, {renderNoBody, renderNoComments, - renderDocComments, renderSyms}) - inc(d.id) let plainNameRope = rope(xmltree.escape(plainName.strip)) @@ -630,6 +637,9 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) = symbolOrIdRope = symbolOrId.rope symbolOrIdEncRope = encodeUrl(symbolOrId).rope + nodeToHighlightedHtml(d, n, result, {renderNoBody, renderNoComments, + renderDocComments, renderSyms}, symbolOrIdEncRope) + var seeSrcRope: Rope = nil let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc") if docItemSeeSrc.len > 0: diff --git a/nimdoc/tester.nim b/nimdoc/tester.nim index db2095128..997ed8596 100644 --- a/nimdoc/tester.nim +++ b/nimdoc/tester.nim @@ -26,7 +26,8 @@ proc test(dir: string; fixup = false) = copyFile(produced, expected) else: echo "SUCCESS: files identical: ", produced - removeDir(dir / "htmldocs") + if failures == 0: + removeDir(dir / "htmldocs") test("nimdoc/testproject", defined(fixup)) if failures > 0: quit($failures & " failures occurred.") diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html index 9ba3c24e1..5d6dbbc5b 100644 --- a/nimdoc/testproject/expected/subdir/subdir_b/utils.html +++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html @@ -1305,7 +1305,7 @@ function main() {

Procs

-
proc someType(): SomeType {...}{.raises: [], tags: [].}
+
proc someType(): SomeType {...}{.raises: [], tags: [].}
constructor. @@ -1316,13 +1316,13 @@ constructor.

Templates

-
template aEnum(): untyped
+
template aEnum(): untyped
-
template bEnum(): untyped
+
template bEnum(): untyped
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html index dd1541a56..9c13eb6e6 100644 --- a/nimdoc/testproject/expected/testproject.html +++ b/nimdoc/testproject/expected/testproject.html @@ -1350,13 +1350,13 @@ The enum B.

Procs

-
proc bar[T](a, b: T): T
+
proc bar[T](a, b: T): T
-
proc isValid[T](x: T): bool
+
proc isValid[T](x: T): bool
@@ -1367,7 +1367,7 @@ The enum B.

Funcs

-
func someFunc() {...}{.raises: [], tags: [].}
+
func someFunc() {...}{.raises: [], tags: [].}
My someFunc. Stuff in quotes here. Some link @@ -1378,7 +1378,7 @@ My someFunc. Stuff in quotesMacros
-
macro bar(): untyped
+
macro bar(): untyped
@@ -1389,7 +1389,7 @@ My someFunc. Stuff in quotesTemplates
-
template foo(a, b: SomeType)
+
template foo(a, b: SomeType)
This does nothing