Moves TOC index entry generation to rstgen module.
We want it there so that index entries appear in the same order as they are found in the input text.
This commit is contained in:
parent
400dd20858
commit
5962119feb
2 changed files with 23 additions and 26 deletions
|
|
@ -513,24 +513,6 @@ proc generateJson(d: PDoc, n: PNode, jArray: PJsonNode = nil): PJsonNode =
|
||||||
discard generateJson(d, lastSon(n.sons[0]), jArray)
|
discard generateJson(d, lastSon(n.sons[0]), jArray)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc stripTOCHTML(s: string): string =
|
|
||||||
## Ugly quick hack to remove HTML tags from TOC titles.
|
|
||||||
##
|
|
||||||
## A TTocEntry.header field already contains rendered HTML tags. Instead of
|
|
||||||
## implementing a proper version of rstgen.renderRstToOut() which recursively
|
|
||||||
## renders an rst tree to plain text, we simply remove text found between
|
|
||||||
## angled brackets. Given the limited possibilities of rst inside TOC titles
|
|
||||||
## this should be enough.
|
|
||||||
result = s
|
|
||||||
var first = result.find('<')
|
|
||||||
while first >= 0:
|
|
||||||
let last = result.find('>', first)
|
|
||||||
if last < 0:
|
|
||||||
# Abort, since we didn't found a closing angled bracket.
|
|
||||||
return
|
|
||||||
result.delete(first, last)
|
|
||||||
first = result.find('<', first)
|
|
||||||
|
|
||||||
proc genSection(d: PDoc, kind: TSymKind) =
|
proc genSection(d: PDoc, kind: TSymKind) =
|
||||||
const sectionNames: array[skModule..skTemplate, string] = [
|
const sectionNames: array[skModule..skTemplate, string] = [
|
||||||
"Imports", "Types", "Vars", "Lets", "Consts", "Vars", "Procs", "Methods",
|
"Imports", "Types", "Vars", "Lets", "Consts", "Vars", "Procs", "Methods",
|
||||||
|
|
@ -568,13 +550,6 @@ proc genOutFile(d: PDoc): PRope =
|
||||||
# Modules get an automatic title for the HTML, but no entry in the index.
|
# Modules get an automatic title for the HTML, but no entry in the index.
|
||||||
title = "Module " & extractFilename(changeFileExt(d.filename, ""))
|
title = "Module " & extractFilename(changeFileExt(d.filename, ""))
|
||||||
|
|
||||||
# Generate entries also for other entries in the toc.
|
|
||||||
for tocPart in d.tocPart:
|
|
||||||
# Use spaces to indicate the current level for the output HTML.
|
|
||||||
assert tocPart.n.level >= 0
|
|
||||||
setIndexTerm(d[], tocPart.refname, tocPart.header.stripTOCHTML,
|
|
||||||
repeatChar(max(0, tocPart.n.level), ' ') & tocPart.header)
|
|
||||||
|
|
||||||
let bodyname = if d.hasToc: "doc.body_toc" else: "doc.body_no_toc"
|
let bodyname = if d.hasToc: "doc.body_toc" else: "doc.body_no_toc"
|
||||||
content = ropeFormatNamedVars(getConfigVar(bodyname), ["title",
|
content = ropeFormatNamedVars(getConfigVar(bodyname), ["title",
|
||||||
"tableofcontents", "moduledesc", "date", "time", "content"],
|
"tableofcontents", "moduledesc", "date", "time", "content"],
|
||||||
|
|
|
||||||
|
|
@ -532,6 +532,23 @@ proc mergeIndexes*(dir: string): string =
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
proc stripTOCHTML(s: string): string =
|
||||||
|
## Ugly quick hack to remove HTML tags from TOC titles.
|
||||||
|
##
|
||||||
|
## A TTocEntry.header field already contains rendered HTML tags. Instead of
|
||||||
|
## implementing a proper version of renderRstToOut() which recursively
|
||||||
|
## renders an rst tree to plain text, we simply remove text found between
|
||||||
|
## angled brackets. Given the limited possibilities of rst inside TOC titles
|
||||||
|
## this should be enough.
|
||||||
|
result = s
|
||||||
|
var first = result.find('<')
|
||||||
|
while first >= 0:
|
||||||
|
let last = result.find('>', first)
|
||||||
|
if last < 0:
|
||||||
|
# Abort, since we didn't found a closing angled bracket.
|
||||||
|
return
|
||||||
|
result.delete(first, last)
|
||||||
|
first = result.find('<', first)
|
||||||
|
|
||||||
proc renderHeadline(d: PDoc, n: PRstNode, result: var string) =
|
proc renderHeadline(d: PDoc, n: PRstNode, result: var string) =
|
||||||
var tmp = ""
|
var tmp = ""
|
||||||
|
|
@ -545,6 +562,11 @@ proc renderHeadline(d: PDoc, n: PRstNode, result: var string) =
|
||||||
d.tocPart[length].n = n
|
d.tocPart[length].n = n
|
||||||
d.tocPart[length].header = tmp
|
d.tocPart[length].header = tmp
|
||||||
|
|
||||||
|
# Use spaces to indicate the current level for the output HTML index.
|
||||||
|
assert n.level >= 0
|
||||||
|
setIndexTerm(d, refname, tmp.stripTOCHTML,
|
||||||
|
repeatChar(max(0, n.level), ' ') & tmp)
|
||||||
|
|
||||||
dispA(d.target, result,
|
dispA(d.target, result,
|
||||||
"\n<h$1><a class=\"toc-backref\" id=\"$2\" href=\"#$2_toc\">$3</a></h$1>",
|
"\n<h$1><a class=\"toc-backref\" id=\"$2\" href=\"#$2_toc\">$3</a></h$1>",
|
||||||
"\\rsth$4{$3}\\label{$2}\n", [$n.level,
|
"\\rsth$4{$3}\\label{$2}\n", [$n.level,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue