Propagate the outDir to rstgen to fix hrefs for modules in subdirs (#14479)

This commit is contained in:
Kaushal Modi 2020-05-28 03:13:24 -04:00 • committed by GitHub
commit e62ccaa4dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 6 deletions

View file

@ -27,8 +27,8 @@
import strutils, os, hashes, strtabs, rstast, rst, highlite, tables, sequtils,
algorithm, parseutils
import "$lib/../compiler/nimpaths"
import "$lib/../compiler/pathutils"
const
HtmlExt = "html"
@ -57,7 +57,9 @@ type
options*: RstParseOptions
findFile*: FindFileHandler
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]
currentSection: string ## \
## 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.
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)
proc renderOverline(d: PDoc, n: PRstNode, result: var string) =