nim doc: fixes cross-link generation when --out is used

This commit is contained in:
Araq
2018-09-10 23:27:45 +02:00
parent 2d8adb8e03
commit f14f554435
2 changed files with 10 additions and 5 deletions

View File

@@ -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],

View File

@@ -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]: