Skip to content

Commit f4d1547

Browse files
author
Sanders Kleinfeld
committed
Added parameter ncx.toc.section.depth to enable configuration of the depth of the NCX TOC.
1 parent 165c78d commit f4d1547

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

htmlbook-xsl/epub.xsl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@
167167
<!-- ID to use in the manifest for the NCX TOC (if $generate.ncx.toc is enabled) -->
168168
<xsl:param name="ncx.toc.id">toc.ncx</xsl:param>
169169

170+
<!-- Specify how many levels of sections to include in NCX TOC.
171+
An $ncx.toc.section.depth of 0 indicates only chapter-level headings and above to be included in NCX TOC
172+
An $ncx.toc.section depth of 1 indicates only sect1-level headings and above to be included in NCX TOC
173+
And so on...
174+
-->
175+
<xsl:param name="ncx.toc.section.depth" select="4"/>
176+
170177
<!-- Include labels in NCX TOC? -->
171178
<xsl:param name="ncx.toc.include.labels" select="1"/>
172179

htmlbook-xsl/ncx.xsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@
7878
</xsl:template>
7979

8080
<xsl:template match="h:section[not(@data-type = 'dedication' or @data-type = 'titlepage' or @data-type = 'toc' or @data-type = 'colophon' or @data-type = 'copyright-page' or @data-type = 'halftitlepage')]|h:div[@data-type='part']" mode="ncx.toc.gen">
81-
<xsl:call-template name="generate.navpoint"/>
81+
<xsl:if test="not(self::h:section[contains(@data-type, 'sect') and htmlbook:section-depth(.) != '' and htmlbook:section-depth(.) &gt; $ncx.toc.section.depth])">
82+
<xsl:call-template name="generate.navpoint"/>
83+
</xsl:if>
8284
</xsl:template>
8385

8486
<!-- Only put the Nav doc in the NCX TOC if $nav.in.ncx is enabled -->

htmlbook-xsl/xspec/ncx.xspec

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ sect4:none
2727
sect5:none
2828
</x:param>
2929

30+
<x:param name="ncx.toc.section.depth" select="2"/>
31+
3032
<x:scenario label="When generating full NCX TOC content">
3133
<x:call template="generate.ncx.toc.content">
3234
<!-- Test XSL is output to a subdir of the .xspec dir, which also contains skeleton, so relative path contains .. to go up a directory level -->
@@ -81,8 +83,10 @@ sect5:none
8183
<ncx:navPoint id="...">...</ncx:navPoint>
8284
</x:expect>
8385

86+
<!-- Note: the following test is dependent on the global param set in this xspec document -->
87+
<!-- If test fails, double-check expected value is in sync with these params -->
8488
<x:scenario label="when source TOC elements are at a lower level than specified NCX Level">
85-
<x:context mode="ncx.toc.gen" select="//h:section[@data-type='sect2'][1]">
89+
<x:context mode="ncx.toc.gen" select="//h:section[@data-type='sect3'][1]">
8690
<section data-type="chapter">
8791
<h1>Test Chapter</h1>
8892
<p>It was the worst of times!</p>
@@ -92,6 +96,10 @@ sect5:none
9296
<section data-type="sect2">
9397
<h2>Test Sect2</h2>
9498
<p>One fish, two fish, red fish, blue fish</p>
99+
<section data-type="sect3">
100+
<h3>Test SEct3</h3>
101+
<p>It was a dark and stormy night</p>
102+
</section>
95103
</section>
96104
</section>
97105
</section>
@@ -151,7 +159,7 @@ sect5:none
151159
<x:call>
152160
<x:param name="ncx.toc.include.labels" select="1"/>
153161
</x:call>
154-
<!-- Note: the following value is dependent on the global param set in this xspec document -->
162+
<!-- Note: the following value is dependent on the global params set in this xspec document -->
155163
<!-- If test fails, double-check expected value is in sync with these params -->
156164
<x:expect label="A navLabel's text content should include labels"
157165
test="count(ncx:navPoint/ncx:navLabel[contains(., 'A. ')]) = 1"/>

0 commit comments

Comments
 (0)