summaryrefslogtreecommitdiff
path: root/templates/reST.xsl
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2009-08-31 16:42:18 +0200
committerdakkar <dakkar@thenautilus.net>2009-08-31 16:42:18 +0200
commit8703a0d42c3c1da47d764c41c74a72ef4f14dbef (patch)
treeecaa72a41012cc6a26a921e8467d672929f24a00 /templates/reST.xsl
parentfiles to configure Apache for this site (diff)
downloadthenautilus-8703a0d42c3c1da47d764c41c74a72ef4f14dbef.tar.gz
thenautilus-8703a0d42c3c1da47d764c41c74a72ef4f14dbef.tar.bz2
thenautilus-8703a0d42c3c1da47d764c41c74a72ef4f14dbef.zip
stylesheets, and better ReST conformance
- layout with two columns and fixed footer - imported docutils official stylesheet - changed the XSLT code to produce XHTML more in line with rst2html.py
Diffstat (limited to 'templates/reST.xsl')
-rw-r--r--templates/reST.xsl234
1 files changed, 161 insertions, 73 deletions
diff --git a/templates/reST.xsl b/templates/reST.xsl
index ecf3bd5..db6e93b 100644
--- a/templates/reST.xsl
+++ b/templates/reST.xsl
@@ -1,6 +1,8 @@
<!--
Copyright (c) 2006, Michael Alyn Miller <malyn@strangeGizmo.com>.
All rights reserved.
+
+ Modified by Gianni Ceccarelli <dakkar@thenautilus.net>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
@@ -35,18 +37,24 @@
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns="http://www.w3.org/1999/xhtml">
+ xmlns:e="http://exslt.org/common"
+ xmlns:s="http://exslt.org/strings"
+ xmlns="http://www.w3.org/1999/xhtml"
+ exclude-result-prefixes="e s"
+ >
<xsl:template match="@classes">
- <xsl:attribute name="class"><xsl:value-of select="."/></xsl:attribute>
+ <xsl:param name="add" select="/.."/>
+ <xsl:if test=".|$add">
+ <xsl:attribute name="class"><xsl:value-of select="."/> <xsl:value-of select="$add"/></xsl:attribute>
+ </xsl:if>
</xsl:template>
-<!-- Suppress the reST document title, information, and topic name.
+<!-- Suppress the reST document title and information.
These values should be pulled in by the main XSL template. -->
<xsl:template match="/document/title" />
<xsl:template match="/document/docinfo" />
-<xsl:template match="/document/topic" />
<!-- Suppress all field lists. These are only used for 'special
features' implemented by the author of the site-specific reST
@@ -64,7 +72,19 @@
</xsl:template>
<xsl:template match="literal">
- <tt><xsl:apply-templates /></tt>
+ <tt class="docutils literal"><span class="pre"><xsl:apply-templates /></span></tt>
+</xsl:template>
+
+<xsl:template match="title_reference">
+ <cite><xsl:apply-templates/></cite>
+</xsl:template>
+
+<xsl:template match="superscript">
+ <sup><xsl:apply-templates/></sup>
+</xsl:template>
+
+<xsl:template match="subscript">
+ <sub><xsl:apply-templates/></sub>
</xsl:template>
<xsl:template match="reference">
@@ -132,18 +152,22 @@
</xsl:template>
<xsl:template match="line_block/line">
- <xsl:apply-templates /><br />
+ <div class="line"><xsl:apply-templates /></div>
</xsl:template>
<xsl:template match="literal_block">
- <div class="literal-block {@classes}"><xsl:apply-templates /></div>
+ <pre class="literal-block {@classes}"><xsl:apply-templates /></pre>
</xsl:template>
<xsl:template match="literal_block/br">
<br />
</xsl:template>
+<xsl:template match="doctest_block">
+ <pre class="doctest-block {@classes}"><xsl:apply-templates /></pre>
+</xsl:template>
+
<xsl:template match="paragraph">
<p><xsl:apply-templates select="@classes"/><xsl:apply-templates /></p>
@@ -162,38 +186,23 @@
<xsl:apply-templates select="@classes"/>
<xsl:apply-templates/>
</blockquote>
-
- <xsl:if test="./attribution">
- <div class="cite {@classes}">
- <span class="cite_label {@classes}">Source: </span>
- <cite class="{attribution/@classes}"><xsl:apply-templates select="attribution/*|attribution/text()" /></cite>
- </div>
- </xsl:if>
</xsl:template>
-<!-- Suppress block_quote/attribution elements since we grab the text of
- the attribution from the block_quote template. -->
-<xsl:template match="block_quote/attribution" />
-
+<xsl:template match="block_quote/attribution" >
+ <p class="attribution {@classes}">
+ <xsl:text>— </xsl:text>
+ <xsl:apply-templates />
+ </p>
+</xsl:template>
<!-- Footnote references are wrapped in brackets ([..]) and enclosed in
an anchor tag with the class "footnoteref". -->
<xsl:template match="footnote_reference">
- <xsl:element name="a">
- <xsl:attribute name="class">footnoteref</xsl:attribute>
- <xsl:attribute name="id">
- <xsl:text>footnote-backref-</xsl:text>
- <xsl:value-of select="@ids" />
- </xsl:attribute>
- <xsl:attribute name="href">
- <xsl:text>#footnote-</xsl:text>
- <xsl:value-of select="@refid" />
- </xsl:attribute>
-
- <xsl:text>[</xsl:text>
- <xsl:apply-templates />
- <xsl:text>]</xsl:text>
- </xsl:element>
+ <a class="footnote-reference" id="{@ids}" href="#{@refid}">
+ <xsl:text>[</xsl:text>
+ <xsl:apply-templates />
+ <xsl:text>]</xsl:text>
+ </a>
</xsl:template>
<!-- The footnote itself is wrapped in a div tag with a class of
@@ -201,41 +210,55 @@
"footnotereturn") that links back to the part of the document where
the footnote appeared. -->
<xsl:template match="footnote">
- <xsl:element name="div">
- <xsl:attribute name="class">footnote <xsl:value-of select="@classes"/></xsl:attribute>
- <xsl:attribute name="id">
- <xsl:text>footnote-</xsl:text>
- <xsl:value-of select="@ids" />
- </xsl:attribute>
-
- <xsl:element name="a">
- <xsl:attribute name="class">footnotereturn</xsl:attribute>
- <xsl:attribute name="href">
- <xsl:text>#footnote-backref-</xsl:text>
- <xsl:value-of select="@backrefs" />
- </xsl:attribute>
- <xsl:attribute name="title">
- <xsl:text>return to content</xsl:text>
- </xsl:attribute>
-
- <xsl:text>#</xsl:text>
- <xsl:value-of select="label" />
- <xsl:text>: </xsl:text>
- </xsl:element>
-
- <xsl:apply-templates />
- </xsl:element>
+ <xsl:variable name="label" select="label"/>
+ <xsl:variable name="backrefs" select="s:split(@backrefs,' ')/token"/>
+ <div class="footnote {@classes}" id="{@ids}">
+ <xsl:choose>
+ <xsl:when test="count($backrefs) &lt;= 1">
+ <span class="label"><a class="fn-backref" href="$backrefs">[<xsl:value-of select="$label"/>]</a></span>
+ </xsl:when>
+ <xsl:otherwise>
+ <span class="label">[<xsl:value-of select="$label"/>]</span>
+ <em><xsl:text> (</xsl:text>
+ <xsl:for-each select="$backrefs">
+ <a class="fn-backref" href="{.}" title="return to content">
+ <xsl:value-of select="position()" />
+ </a>
+ <xsl:if test="following-sibling::token">, </xsl:if>
+ </xsl:for-each>
+ <xsl:text>)</xsl:text></em>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> </xsl:text>
+ <xsl:apply-templates />
+ </div>
</xsl:template>
<xsl:template match="footnote/label" />
<!-- Basic lists. -->
+<xsl:template name="list-class">
+ <xsl:attribute name="class">
+ <xsl:value-of select="@enumtype"/>
+ <xsl:value-of select="@classes"/>
+ </xsl:attribute>
+</xsl:template>
+
<xsl:template match="bullet_list">
- <ul><xsl:apply-templates select="@classes"/><xsl:apply-templates /></ul>
+ <ul>
+ <xsl:call-template name="list-class"/>
+ <xsl:apply-templates />
+ </ul>
</xsl:template>
<xsl:template match="enumerated_list">
- <ol><xsl:apply-templates select="@classes"/><xsl:apply-templates /></ol>
+ <ol>
+ <xsl:call-template name="list-class"/>
+ <xsl:if test="@start">
+ <xsl:attribute name="start"><xsl:value-of select="@start"/></xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates />
+ </ol>
</xsl:template>
<!-- Basic list items. -->
@@ -260,24 +283,29 @@
<dl><xsl:apply-templates select="@classes"/><xsl:apply-templates /></dl>
</xsl:template>
+<xsl:template match="definition_list_item">
+ <xsl:apply-templates select="term|definition"/>
+</xsl:template>
+
<xsl:template match="definition_list_item/term">
- <dt><xsl:apply-templates select="@classes"/><xsl:apply-templates /></dt>
+ <dt><xsl:apply-templates select="@classes"/><xsl:apply-templates /> <xsl:apply-templates select="../classifier"/></dt>
</xsl:template>
<xsl:template match="definition_list_item/definition">
<dd><xsl:apply-templates select="@classes"/><xsl:apply-templates /></dd>
</xsl:template>
+<xsl:template match="definition_list_item/classifier">
+ <span class="classifier-delimiter">:</span>
+ <xsl:text> </xsl:text>
+ <span class="classifier"><xsl:apply-templates/></span>
+</xsl:template>
<!-- Option lists. -->
<xsl:template match="option_list">
- <table class="option-list {@classes}" cellpadding="0" cellspacing="0">
- <tr>
- <th>Option</th>
- <th>Description</th>
- </tr>
-
- <xsl:apply-templates />
+ <table class="docutils option-list {@classes}" cellpadding="0" cellspacing="0">
+ <col class="option" /><col class="description" />
+ <xsl:apply-templates />
</table>
</xsl:template>
@@ -286,19 +314,21 @@
</xsl:template>
<xsl:template match="option_group">
- <td>
+ <td class="option-group {@classes}">
<xsl:for-each select="option">
- <xsl:apply-templates select="." /><br />
+ <xsl:apply-templates select="." />
+ <xsl:if test="following-sibling::option">, </xsl:if>
</xsl:for-each>
</td>
</xsl:template>
<xsl:template match="option_group/option">
- <span class="option-string"><xsl:value-of select="option_string" /></span>
+ <kbd><span class="option"><xsl:value-of select="option_string" /></span>
<xsl:if test="option_argument">
<span class="option-delimiter"><xsl:value-of select="option_argument/@delimiter" /></span>
- <span class="option-argument"><xsl:value-of select="option_argument" /></span>
+ <var><span class="option-argument"><xsl:value-of select="option_argument" /></span></var>
</xsl:if>
+ </kbd>
</xsl:template>
<xsl:template match="option_list_item/description">
@@ -326,6 +356,62 @@
</xsl:element>
</xsl:template>
+<xsl:template match="title" priority="-1">
+ <h1 class="{@classes}">
+ <xsl:apply-templates/>
+ </h1>
+</xsl:template>
+
+<xsl:template match="subtitle" priority="-1">
+ <h2 class="{@classes}">
+ <xsl:apply-templates/>
+ </h2>
+</xsl:template>
+
+<!-- admonitions -->
+
+<xsl:template match="attention|caution|danger|error|hint|important|note|tip|warning">
+ <div class="{local-name()} {@classes}">
+ <p class="admonition-title"><xsl:apply-templates select="." mode="admonition-title"/></p>
+ <xsl:apply-templates/>
+ </div>
+</xsl:template>
+
+<xsl:template match="*" mode="admonition-title"><!-- to be overridden -->
+ <xsl:value-of select="local-name()"/>
+</xsl:template>
+
+<xsl:template match="admonition">
+ <div class="admonition {@classes}">
+ <xsl:apply-templates/>
+ </div>
+</xsl:template>
+
+<xsl:template match="admonition/title">
+ <p class="admonition-title"><xsl:apply-templates/></p>
+</xsl:template>
+
+<!-- other directives -->
+
+<xsl:template match="topic|sidebar">
+ <div class="{local-name()} {@classes}">
+ <xsl:if test="@ids">
+ <xsl:attribute name="id"><xsl:value-of select="@ids"/></xsl:attribute>
+ <a name="{@ids}" />
+ </xsl:if>
+ <xsl:apply-templates />
+ </div>
+</xsl:template>
+
+<xsl:template match="sidebar/title|sidebar/subtitle|topic/title|topic/subtitle">
+ <p class="{local-name(parent::*)}-{local-name()} {@classes}">
+ <xsl:apply-templates/>
+ </p>
+</xsl:template>
+
+<xsl:template match="rubric">
+ <p class="rubric {@classes}"><xsl:apply-templates/></p>
+</xsl:template>
<!-- Tables.
@@ -341,8 +427,7 @@
A similar field exists for specifying the valign value. This field
is called ":table-cell-valign:". -->
<xsl:template match="table">
- <table>
- <xsl:if test="@classes"><xsl:attribute name="class"><xsl:value-of select="@classes"/></xsl:attribute></xsl:if>
+ <table class="docutils {@classes}" border="1">
<xsl:apply-templates />
</table>
</xsl:template>
@@ -407,5 +492,8 @@
</xsl:element>
</xsl:template>
+<xsl:template match="transition">
+ <hr />
+</xsl:template>
</xsl:stylesheet>