Commit 6ecd9423 authored by bperraud's avatar bperraud

add basic toc support

parent 9f80f7b0
......@@ -70,6 +70,12 @@ h4::before {counter-increment: h4; content: counter(h2) "." counter(h3) "." coun
h5::before {counter-increment: h5; content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ".\0000a0\0000a0"}
h6::before {counter-increment: h6; content: counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ".\0000a0\0000a0"}
h2.nocount:before,
h3.nocount:before,
h4.nocount:before,
h5.nocount:before,
h6.nocount:before { content: ""; counter-increment: none }
/* Global lists styling */
......@@ -92,6 +98,37 @@ ul > li::before {
}
/* ToC formatting */
h2.toc-title {
page-break-before: always;
}
ul.toc {
counter-reset: toc;
padding-left: 0;
}
ul.toc > li::before {
left: 0;
position: absolute;
content: counters(toc, ".") ". ";
counter-increment: toc;
}
ul.toc.level2 > li {padding-left: 8mm;}
ul.toc.level3 > li {padding-left: 11mm;}
ul.toc.level4 > li {padding-left: 13mm;}
ul.toc.level5 > li {padding-left: 15mm;}
ul.toc.level6 > li {padding-left: 17mm;}
/* Title formatting */
h1 {
......
......@@ -39,6 +39,10 @@
<xsl:variable name="level" select="count(ancestor::section) + 2"/>
<div>
<xsl:element name="h{$level}">
<xsl:attribute name="id">
<xsl:value-of select="concat('h', $level, '-')"/>
<xsl:number level="any"/>
</xsl:attribute>
<xsl:value-of select="header/h1"/>
</xsl:element>
<xsl:apply-templates/>
......
......@@ -18,12 +18,115 @@
<body>
<h1><xsl:value-of select="/html/head/title"/></h1>
<p class="authors"><xsl:value-of select="/html/head/meta[@name='author']/@content"/></p>
<xsl:apply-templates select="node()|@*"/>
<xsl:call-template name="toc"/>
</body>
</xsl:template>
<!-- Cleaning des footers vides -->
<xsl:template match="footer[not(node())]"/>
<!-- Gestion de la table des matières -->
<xsl:template name="toc">
<xsl:if test="count(//h2) &gt; 0">
<h2 class="nocount toc-title">Table des matières</h2>
<ul class="toc level2">
<xsl:for-each select="//h2">
<li>
<xsl:call-template name="toc-a"/>
<xsl:if test="count(..//h3) &gt; 0">
<ul class="toc level3">
<xsl:for-each select="..//h3">
<li>
<xsl:call-template name="toc-a"/>
<xsl:if test="count(..//h4) &gt; 0">
<ul class="toc level4">
<xsl:for-each select="..//h4">
<li>
<xsl:call-template name="toc-a"/>
<xsl:if test="count(..//h5) &gt; 0">
<ul class="toc level5">
<xsl:for-each select="..//h5">
<li>
<xsl:call-template name="toc-a"/>
<xsl:if test="count(..//h6) &gt; 0">
<ul class="toc level6">
<xsl:for-each select="..//h6">
<li>
<xsl:call-template name="toc-a"/>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:if>
<!-- <li><a href="#">Introduction</a><span>1</span></li> -->
<!-- <li class="nested"> -->
<!-- <ul class="inner"> -->
<!-- <li><a href="#">Header 1</a><span>2</span> -->
<!-- </li> -->
<!-- <li><a href="#">Header 2</a><span>2</span> -->
<!-- </li> -->
<!-- </ul> -->
<!-- </li> -->
<!-- <li><a href="#">Header 2</a><span>3</span></li> -->
</xsl:template>
<xsl:template name="toc-a">
<a>
<xsl:attribute name="href">
<xsl:text>#</xsl:text>
<xsl:value-of select="./@id"/>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
</xsl:template>
</xsl:stylesheet>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment