summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-09-10 23:27:45 +0200
committerAraq <rumpf_a@web.de>2018-09-10 23:27:45 +0200
commitf14f5544354b9731417e5eeea0a42bbfd42739fb (patch)
treeca942f21e1057e38f4dc5e0205b3bd160eaf4a4e
parent2d8adb8e03c4663a5f7148980e636abf187780ef (diff)
downloadNim-f14f5544354b9731417e5eeea0a42bbfd42739fb.tar.gz
nim doc: fixes cross-link generation when --out is used
-rw-r--r--compiler/docgen.nim13
-rw-r--r--compiler/pathutils.nim2
2 files changed, 10 insertions, 5 deletions
diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index 6095745be..e1ae33cf5 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -94,13 +94,18 @@ proc parseRst(text, filename: string,
                     docgenFindFile, compilerMsgHandler)
 
 proc getOutFile2(conf: ConfigRef; filename: RelativeFile,
-                 ext: string, dir: RelativeDir): AbsoluteFile =
+                 ext: string, dir: RelativeDir; guessTarget: bool): AbsoluteFile =
   if optWholeProject in conf.globalOptions:
     # This is correct, for 'nim doc --project' we interpret the '--out' option as an
     # absolute directory, not as a filename!
     let d = if conf.outFile.isEmpty: conf.projectPath / dir else: AbsoluteDir(conf.outFile)
     createDir(d)
     result = d / changeFileExt(filename, ext)
+  elif guessTarget:
+    let d = if not conf.outFile.isEmpty: splitFile(conf.outFile).dir
+    else: conf.projectPath
+    createDir(d)
+    result = d / changeFileExt(filename, ext)
   else:
     result = getOutFile(conf, filename, ext)
 
@@ -138,7 +143,7 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef):
                warnUser, "only 'rst2html' supports the ':test:' attribute")
   result.emitted = initIntSet()
   result.destFile = getOutFile2(conf, relativeTo(filename, conf.projectPath),
-                                HtmlExt, RelativeDir"htmldocs")
+                                HtmlExt, RelativeDir"htmldocs", false)
   result.thisDir = result.destFile.splitFile.dir
 
 proc dispA(conf: ConfigRef; dest: var Rope, xml, tex: string, args: openArray[Rope]) =
@@ -288,7 +293,7 @@ proc nodeToHighlightedHtml(d: PDoc; n: PNode; result: var Rope; renderFlags: TRe
 
         let full = AbsoluteFile toFullPath(d.conf, FileIndex s.owner.position)
         let tmp = getOutFile2(d.conf, full.relativeTo(d.conf.projectPath),
-            HtmlExt, RelativeDir"htmldocs")
+            HtmlExt, RelativeDir"htmldocs", sfMainModule notin s.owner.flags)
 
         let external = tmp.relativeTo(d.thisDir, '/')
         result.addf "<a href=\"$1#$2\"><span class=\"Identifier\">$3</span></a>",
@@ -673,7 +678,7 @@ proc traceDeps(d: PDoc, it: PNode) =
   elif it.kind == nkSym and belongsToPackage(d.conf, it.sym):
     let full = AbsoluteFile toFullPath(d.conf, FileIndex it.sym.position)
     let tmp = getOutFile2(d.conf, full.relativeTo(d.conf.projectPath), HtmlExt,
-        RelativeDir"htmldocs")
+        RelativeDir"htmldocs", sfMainModule notin it.sym.flags)
     let external = relativeTo(tmp, d.thisDir, '/').string
     if d.section[k] != nil: add(d.section[k], ", ")
     dispA(d.conf, d.section[k],
diff --git a/compiler/pathutils.nim b/compiler/pathutils.nim
index b71caf314..ef0fa4abd 100644
--- a/compiler/pathutils.nim
+++ b/compiler/pathutils.nim
@@ -111,7 +111,7 @@ proc canon(x: string; result: var string; state: var int) =
       # f/..
       while d > (state and 1) and result[d-1] != DirSep:
         dec d
-      setLen(result, d-1)
+      if d > 0: setLen(result, d-1)
     elif isDot(x, b):
       discard "discard the dot"
     elif b[1] > b[0]: