Fix documentation
[senf.git] / doclib / html-munge.xsl
index 241bc8b..05e0d95 100644 (file)
 <?xml version="1.0" encoding="utf-8"?>\r
-<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\r
-                version="1.0">\r
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">\r
 \r
-  <xsl:output method="html" encoding="html" />\r
+  <xsl:output \r
+    method="html" \r
+    encoding="html" \r
+    doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"\r
+    doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>\r
 \r
-  <xsl:template match="/">\r
-    <html>\r
-      <body bgcolor="#FFFFFF">\r
-        <xsl:apply-templates/>\r
-      </body>\r
-    </html>\r
+  <xsl:param name="topdir" select="''"/>\r
+  \r
+  <xsl:template match="*" name="copy">\r
+    <xsl:copy>\r
+      <xsl:call-template name="copy-attributes"/>\r
+      <xsl:apply-templates/>\r
+    </xsl:copy>\r
   </xsl:template>\r
 \r
-  <xsl:template match="dl[dt/b/a/text()='Bug:']">\r
+  <xsl:template name="copy-attributes">\r
+    <xsl:for-each select="@*">\r
+      <xsl:attribute name="{name(current())}">\r
+        <xsl:choose>\r
+          <xsl:when test="contains(current(),'@TOPDIR@')">\r
+            <xsl:value-of select="substring-before(current(),'@TOPDIR@')"/>\r
+            <xsl:value-of select="$topdir"/>\r
+            <xsl:value-of select="substring-after(current(),'@TOPDIR@')"/>\r
+          </xsl:when>\r
+          <xsl:otherwise>\r
+            <xsl:value-of select="current()"/>\r
+          </xsl:otherwise>\r
+        </xsl:choose>\r
+      </xsl:attribute>\r
+    </xsl:for-each>\r
+  </xsl:template>\r
+\r
+  <!-- Replace @TOPDIR@ with relative top directory path -->\r
+\r
+  <xsl:template match="@*[contains(current(),'@TOPDIR@')]">\r
+    <xsl:value-of select="substring-before(current(),'@TOPDIR@')"/>\r
+    <xsl:value-of select="$topdir"/>\r
+    <xsl:value-of select="substring-after(current(),'@TOPDIR@')"/>\r
+  </xsl:template>\r
+  \r
+  <!-- Add 'class' attribute to some special paragraphs/lists -->\r
+  \r
+  <xsl:template name="add-class">\r
+    <xsl:param name="class"/>\r
     <xsl:copy>\r
-      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>\r
-      <xsl:attribute name="class">xref-bug</xsl:attribute>\r
+      <xsl:call-template name="copy-attributes"/>\r
+      <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>\r
       <xsl:apply-templates/>\r
     </xsl:copy>\r
   </xsl:template>\r
 \r
-  <xsl:template match="dl[dt/b/a/text()='Fixme:']">\r
+  <!-- Add '<br/>' tag after every ', ' -->\r
+  <!-- This code is not very robust, it works with the doxygen output though -->\r
+\r
+  <xsl:template name="break-comma">\r
     <xsl:copy>\r
-      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>\r
-      <xsl:attribute name="class">xref-fixme</xsl:attribute>\r
-      <xsl:apply-templates/>\r
+      <xsl:call-template name="copy-attributes"/>\r
+      <xsl:attribute name="class">commalist</xsl:attribute>\r
+      <xsl:apply-templates mode="break-comma"/>\r
     </xsl:copy>\r
   </xsl:template>\r
\r
+  <xsl:template match="text()[1]" mode="break-comma">\r
+    <xsl:value-of select="current()"/><br/>\r
+  </xsl:template>\r
 \r
-  <xsl:template match="dl[dt/b/a/text()='Todo:']">\r
+  <xsl:template match="*" mode="break-comma">\r
+    <xsl:call-template name="copy"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="text()[contains(current(),' and') or contains(current(),'and ')]" mode="break-comma" priority="1">\r
+    <xsl:value-of select="substring-before(current(),'and')"/>\r
+    <br/>\r
+    <xsl:value-of select="substring-after(current(),'and')"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="text()[contains(current(),',')]" mode="break-comma">\r
+    <xsl:value-of select="substring-before(current(),',')"/>\r
+    <xsl:text>,</xsl:text><br/>\r
+    <xsl:value-of select="substring-after(current(),',')"/>\r
+  </xsl:template>\r
+\r
+  <!-- ====================================================================== -->\r
+\r
+  <!-- Hack Glossary menu highlight -->\r
+\r
+  <xsl:template match="div[@class='tabs menu']/ul[1]">\r
+    <xsl:choose>\r
+      <xsl:when test="//h1[.//text()='Glossary']">\r
+        <xsl:call-template name="add-class">\r
+          <xsl:with-param name="class">glossary</xsl:with-param>\r
+        </xsl:call-template>\r
+      </xsl:when>\r
+      <xsl:otherwise>\r
+        <xsl:copy>\r
+          <xsl:call-template name="copy-attributes"/>\r
+          <xsl:apply-templates/>\r
+        </xsl:copy>\r
+      </xsl:otherwise>\r
+    </xsl:choose>\r
+  </xsl:template>\r
+\r
+  <!-- Autogenerate table-of-contents for a page -->\r
+\r
+  <xsl:template match="div[@id='autotoc']">\r
     <xsl:copy>\r
-      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>\r
-      <xsl:attribute name="class">xref-todo</xsl:attribute>\r
-      <xsl:apply-templates/>\r
+      <xsl:call-template name="copy-attributes"/>\r
+      <h1>Contents</h1>\r
+      <ul>\r
+        <xsl:for-each select="following::h2|following::h3|following::h4">\r
+          <xsl:element name="li">\r
+            <xsl:attribute name="class">\r
+              <xsl:value-of select="concat('level_',local-name())"/>\r
+            </xsl:attribute>\r
+            <b><xsl:call-template name="section-number"/><xsl:text> </xsl:text></b>\r
+            <xsl:element name="a">\r
+              <xsl:choose>\r
+                <xsl:when test="a/@name">\r
+                  <xsl:attribute name="href">\r
+                    <xsl:value-of select="concat('#',a/@name)"/>\r
+                  </xsl:attribute>\r
+                </xsl:when>\r
+                <xsl:otherwise>\r
+                  <xsl:attribute name="href">\r
+                    <xsl:text>#autotoc-</xsl:text>\r
+                    <xsl:call-template name="section-number"/>\r
+                  </xsl:attribute>\r
+                </xsl:otherwise>\r
+              </xsl:choose>\r
+              <xsl:value-of select="string(current())"/>\r
+            </xsl:element>\r
+          </xsl:element>\r
+        </xsl:for-each>\r
+      </ul>\r
     </xsl:copy>\r
   </xsl:template>\r
 \r
-  <xsl:template match="dl[dt/b/a/text()='Idea:']">\r
+  <xsl:template name="section-number">\r
+    <xsl:number level="any" from="div[@id='autotoc']" count="h2"/>\r
+    <xsl:text>.</xsl:text>\r
+    <xsl:if test="self::h3|self::h4">\r
+      <xsl:number level="any" from="h2" count="h3"/>\r
+      <xsl:text>.</xsl:text>\r
+    </xsl:if>\r
+    <xsl:if test="self::h4">\r
+      <xsl:number level="any" from="h3" count="h4"/>\r
+      <xsl:text>.</xsl:text>\r
+    </xsl:if>\r
+  </xsl:template>\r
+  \r
+  <xsl:template match="h2|h3|h4">\r
     <xsl:copy>\r
-      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>\r
-      <xsl:attribute name="class">xref-idea</xsl:attribute>\r
-      <xsl:apply-templates/>\r
+      <xsl:call-template name="copy-attributes"/>\r
+      <xsl:choose>\r
+        <xsl:when test="preceding::div[@id='autotoc']">\r
+          <xsl:call-template name="section-number"/>\r
+          <xsl:text> </xsl:text>\r
+          <xsl:choose>\r
+            <xsl:when test="a">\r
+              <xsl:apply-templates/>\r
+            </xsl:when>\r
+            <xsl:otherwise>\r
+              <xsl:element name="a">\r
+                <xsl:attribute name="class"><xsl:text>anchor</xsl:text></xsl:attribute>\r
+                <xsl:attribute name="name">\r
+                  <xsl:text>autotoc-</xsl:text>\r
+                  <xsl:call-template name="section-number"/>\r
+                </xsl:attribute>\r
+                <xsl:apply-templates/>\r
+              </xsl:element>\r
+            </xsl:otherwise>\r
+          </xsl:choose>\r
+        </xsl:when>\r
+        <xsl:otherwise>\r
+          <xsl:apply-templates/>\r
+        </xsl:otherwise>\r
+      </xsl:choose>\r
     </xsl:copy>\r
   </xsl:template>\r
 \r
-  <xsl:template match="*">\r
+  <!-- Build dia image-map from special div/span elements -->\r
+  <xsl:template match="div[@class='diamap']">\r
+    <xsl:element name="map">\r
+      <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>\r
+      <xsl:for-each select="span">\r
+        <xsl:if test="a">\r
+          <xsl:variable name="name" select="string(a[1])"/>\r
+          <xsl:element name="area">\r
+            <xsl:attribute name="shape">rect</xsl:attribute>\r
+            <xsl:attribute name="alt"><xsl:value-of select="$name"/></xsl:attribute>\r
+            <xsl:attribute name="title"><xsl:value-of select="$name"/></xsl:attribute>\r
+            <xsl:attribute name="href"><xsl:value-of select="a[1]/@href"/></xsl:attribute>\r
+            <xsl:attribute name="coords"><xsl:value-of select="@coords"/></xsl:attribute>\r
+          </xsl:element>\r
+        </xsl:if>\r
+      </xsl:for-each>\r
+    </xsl:element>\r
+  </xsl:template>\r
+\r
+  <!-- Remove the automatically inserted search form (we build our own) -->\r
+  <xsl:template match="li[form]"> \r
+  </xsl:template>\r
+\r
+  <xsl:template match="table[preceding-sibling::*[1][self::div][@class='qindex']]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">qindextable</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+  \r
+  <xsl:template match="dl[dt/b/a/text()='Bug:']">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">xref-bug</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dl[dt/b/a/text()='Fix:']">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">xref-fix</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dl[dt/b/a/text()='Todo:']">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">xref-todo</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dl[dt/b/a/text()='Idea:']">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">xref-idea</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dl[dt/b/text()='Parameters:']|dl[dt/b/text()='Template Parameters:']">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">parameters</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="dl[dt/b/text()='Implementation note:']">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">implementation</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="table[descendant::td[@class='memItemLeft']]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">members</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="a[@href=string(current())]" priority="1">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">literal</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="a[contains(@href,'http://')]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">ext</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="a[not(@href)]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">anchor</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="div[@class='memdoc']/p[1]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">memtitle</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="p[starts-with(text(),'Definition at line ')]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">sourceline</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'References ')]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">references</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Referenced by ')]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">referencedby</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented from ')]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">reimplementedfrom</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented in ')]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">reimplementedin</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Implemented in ')]">\r
+    <xsl:call-template name="add-class">\r
+      <xsl:with-param name="class">implementedin</xsl:with-param>\r
+    </xsl:call-template>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="p[starts-with(text(),'Inherited by ')]">\r
+    <xsl:call-template name="break-comma"/>\r
+  </xsl:template>\r
+\r
+  <xsl:template match="p[starts-with(text(),'Inherits ')]">\r
+    <xsl:call-template name="break-comma"/>\r
+  </xsl:template>\r
+\r
+  <!-- Remove external items from the namespace index -->\r
+  <xsl:template match="div[@id='content2']/table[contains(preceding-sibling::h1/text(),'Namespace Reference')]/tr[td[@class='memItemRight']/a[1][@class='elRef'][@doxygen]]">\r
+  </xsl:template>\r
+  \r
+  <!-- Remove [external] references from the modules page -->\r
+  <xsl:template match="div[@id='content2']/ul/li[a/@class='elRef'][a/@doxygen][code/text()='[external]'][not(ul)]">\r
+  </xsl:template>\r
+\r
+  <!-- Insert 'senf/'  into include paths -->\r
+  <xsl:template match="code[starts-with(text(),'#include &lt;')]/a">\r
     <xsl:copy>\r
-      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>\r
+      <xsl:call-template name="copy-attributes"/>\r
+      <xsl:text>senf/</xsl:text>\r
       <xsl:apply-templates/>\r
     </xsl:copy>\r
   </xsl:template>\r