Propagate the outDir to rstgen to fix hrefs for modules in subdirs (#14479)
This commit is contained in:
parent
1fc40db984
commit
e62ccaa4dc
5 changed files with 41 additions and 6 deletions
|
|
@ -47,7 +47,6 @@ type
|
||||||
exampleCounter: int
|
exampleCounter: int
|
||||||
emitted: IntSet # we need to track which symbols have been emitted
|
emitted: IntSet # we need to track which symbols have been emitted
|
||||||
# already. See bug #3655
|
# already. See bug #3655
|
||||||
destFile*: AbsoluteFile
|
|
||||||
thisDir*: AbsoluteDir
|
thisDir*: AbsoluteDir
|
||||||
exampleGroups: OrderedTable[string, ExampleGroup]
|
exampleGroups: OrderedTable[string, ExampleGroup]
|
||||||
wroteSupportFiles*: bool
|
wroteSupportFiles*: bool
|
||||||
|
|
@ -179,6 +178,7 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef,
|
||||||
result.module = module
|
result.module = module
|
||||||
result.conf = conf
|
result.conf = conf
|
||||||
result.cache = cache
|
result.cache = cache
|
||||||
|
result.outDir = conf.outDir
|
||||||
initRstGenerator(result[], (if conf.cmd != cmdRst2tex: outHtml else: outLatex),
|
initRstGenerator(result[], (if conf.cmd != cmdRst2tex: outHtml else: outLatex),
|
||||||
conf.configVars, filename.string, {roSupportRawDirective, roSupportMarkdown},
|
conf.configVars, filename.string, {roSupportRawDirective, roSupportMarkdown},
|
||||||
docgenFindFile, compilerMsgHandler)
|
docgenFindFile, compilerMsgHandler)
|
||||||
|
|
@ -1366,4 +1366,3 @@ proc commandBuildIndex*(conf: ConfigRef, dir: string, outFile = RelativeFile"")
|
||||||
|
|
||||||
if not writeRope(code, filename):
|
if not writeRope(code, filename):
|
||||||
rawMessage(conf, errCannotOpenFile, filename.string)
|
rawMessage(conf, errCannotOpenFile, filename.string)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@
|
||||||
|
|
||||||
import strutils, os, hashes, strtabs, rstast, rst, highlite, tables, sequtils,
|
import strutils, os, hashes, strtabs, rstast, rst, highlite, tables, sequtils,
|
||||||
algorithm, parseutils
|
algorithm, parseutils
|
||||||
|
|
||||||
import "$lib/../compiler/nimpaths"
|
import "$lib/../compiler/nimpaths"
|
||||||
|
import "$lib/../compiler/pathutils"
|
||||||
|
|
||||||
const
|
const
|
||||||
HtmlExt = "html"
|
HtmlExt = "html"
|
||||||
|
|
@ -57,7 +57,9 @@ type
|
||||||
options*: RstParseOptions
|
options*: RstParseOptions
|
||||||
findFile*: FindFileHandler
|
findFile*: FindFileHandler
|
||||||
msgHandler*: MsgHandler
|
msgHandler*: MsgHandler
|
||||||
filename*: string
|
outDir*: AbsoluteDir ## output directory, initialized by docgen.nim
|
||||||
|
destFile*: AbsoluteFile ## output (HTML) file, initialized by docgen.nim
|
||||||
|
filename*: string ## source Nim or Rst file
|
||||||
meta*: array[MetaEnum, string]
|
meta*: array[MetaEnum, string]
|
||||||
currentSection: string ## \
|
currentSection: string ## \
|
||||||
## Stores the empty string or the last headline/overline found in the rst
|
## Stores the empty string or the last headline/overline found in the rst
|
||||||
|
|
@ -755,7 +757,15 @@ proc renderHeadline(d: PDoc, n: PRstNode, result: var string) =
|
||||||
|
|
||||||
# Generate index entry using spaces to indicate TOC level for the output HTML.
|
# Generate index entry using spaces to indicate TOC level for the output HTML.
|
||||||
assert n.level >= 0
|
assert n.level >= 0
|
||||||
setIndexTerm(d, changeFileExt(extractFilename(d.filename), HtmlExt), refname, tmp.stripTocHtml,
|
let
|
||||||
|
htmlFileRelPath = if d.outDir.isEmpty():
|
||||||
|
# /foo/bar/zoo.nim -> zoo.html
|
||||||
|
changeFileExt(extractFilename(d.filename), HtmlExt)
|
||||||
|
else: # d is initialized in docgen.nim
|
||||||
|
# outDir = /foo -\
|
||||||
|
# destFile = /foo/bar/zoo.html -|-> bar/zoo.html
|
||||||
|
d.destFile.relativeTo(d.outDir, '/').string
|
||||||
|
setIndexTerm(d, htmlFileRelPath, refname, tmp.stripTocHtml,
|
||||||
spaces(max(0, n.level)) & tmp)
|
spaces(max(0, n.level)) & tmp)
|
||||||
|
|
||||||
proc renderOverline(d: PDoc, n: PRstNode, result: var string) =
|
proc renderOverline(d: PDoc, n: PRstNode, result: var string) =
|
||||||
|
|
|
||||||
12
nimdoc/testproject/expected/subdir/subdir_b/utils.idx
Normal file
12
nimdoc/testproject/expected/subdir/subdir_b/utils.idx
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
This is now a header subdir/subdir_b/utils.html#this-is-now-a-header This is now a header
|
||||||
|
Next header subdir/subdir_b/utils.html#this-is-now-a-header-next-header Next header
|
||||||
|
And so on subdir/subdir_b/utils.html#next-header-and-so-on And so on
|
||||||
|
More headers subdir/subdir_b/utils.html#more-headers More headers
|
||||||
|
Up to level 6 subdir/subdir_b/utils.html#more-headers-up-to-level-6 Up to level 6
|
||||||
|
enumValueA subdir/subdir_b/utils.html#enumValueA SomeType.enumValueA
|
||||||
|
enumValueB subdir/subdir_b/utils.html#enumValueB SomeType.enumValueB
|
||||||
|
enumValueC subdir/subdir_b/utils.html#enumValueC SomeType.enumValueC
|
||||||
|
SomeType subdir/subdir_b/utils.html#SomeType utils: SomeType
|
||||||
|
someType subdir/subdir_b/utils.html#someType_2 utils: someType(): SomeType
|
||||||
|
aEnum subdir/subdir_b/utils.html#aEnum.t utils: aEnum(): untyped
|
||||||
|
bEnum subdir/subdir_b/utils.html#bEnum.t utils: bEnum(): untyped
|
||||||
14
nimdoc/testproject/expected/testproject.idx
Normal file
14
nimdoc/testproject/expected/testproject.idx
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
C_A testproject.html#C_A testproject: C_A
|
||||||
|
C_B testproject.html#C_B testproject: C_B
|
||||||
|
C_C testproject.html#C_C testproject: C_C
|
||||||
|
C_D testproject.html#C_D testproject: C_D
|
||||||
|
foo testproject.html#foo.t,SomeType,SomeType testproject: foo(a, b: SomeType)
|
||||||
|
bar testproject.html#bar,T,T testproject: bar[T](a, b: T): T
|
||||||
|
baz testproject.html#baz,T,T testproject: baz[T](a, b: T): T
|
||||||
|
buzz testproject.html#buzz,T,T testproject: buzz[T](a, b: T): T
|
||||||
|
bar testproject.html#bar.m testproject: bar(): untyped
|
||||||
|
aVariable testproject.html#aVariable testproject: aVariable
|
||||||
|
A testproject.html#A testproject: A
|
||||||
|
B testproject.html#B testproject: B
|
||||||
|
someFunc testproject.html#someFunc testproject: someFunc()
|
||||||
|
isValid testproject.html#isValid,T testproject: isValid[T](x: T): bool
|
||||||
|
|
@ -72,7 +72,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="testproject.html">testproject</a>, <a href="utils.html">utils</a>.<br/><p /><h2>API symbols</h2>
|
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>
|
||||||
<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>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue