1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-24 00:05:46 +01:00

Completely HTML-ize help transforms. Add intentionally undocumented :exporthelp.

This commit is contained in:
Kris Maglione
2009-11-02 00:18:58 -05:00
parent 3f4602ca3c
commit 108f467fe4
10 changed files with 354 additions and 181 deletions

View File

@@ -2,9 +2,9 @@
<!-- Header {{{1 -->
<xsl:stylesheet version="1.0"
xmlns="http://vimperator.org/namespaces/liberator"
xmlns:liberator="http://vimperator.org/namespaces/liberator"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:liberator="http://vimperator.org/namespaces/liberator"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:exsl="http://exslt.org/common"
@@ -76,9 +76,9 @@
<!-- Process Inclusions {{{1 -->
<xsl:template match="liberator:include" mode="overlay-2">
<xsl:copy>
<div liberator:highlight="HelpInclude">
<xsl:apply-templates select="document(@href)/liberator:document/node()" mode="overlay"/>
</xsl:copy>
</div>
</xsl:template>
<xsl:template match="@*|node()" mode="overlay">
@@ -94,21 +94,20 @@
<xsl:template match="/">
<xsl:for-each select="$root/liberator:document">
<html:html liberator:highlight="Help">
<html:head>
<html:title><xsl:value-of select="@title"/></html:title>
<html:base href="liberator://help/{@name}"/>
<html:script type="text/javascript"
<html liberator:highlight="Help">
<head>
<title><xsl:value-of select="@title"/></title>
<script type="text/javascript"
src="chrome://liberator/content/help.js"/>
</html:head>
<html:body liberator:highlight="HelpBody">
<html:div class="liberator-logo"/>
</head>
<body liberator:highlight="HelpBody">
<div liberator:highlight="Logo"/>
<xsl:call-template name="parse-tags">
<xsl:with-param name="text" select="concat(@name, '.html')"/>
</xsl:call-template>
<xsl:apply-templates/>
</html:body>
</html:html>
</body>
</html>
</xsl:for-each>
</xsl:template>
@@ -126,15 +125,15 @@
local-name() = $tag and not(preceding::*[local-name() = $lasttag][position() = 1 and not(.=$context)])]"/>
<xsl:if test="$nodes">
<html:ol liberator:highlight="HelpOrderedList">
<ol liberator:highlight="HelpOrderedList">
<xsl:for-each select="$nodes">
<li>
<html:a>
<a>
<xsl:if test="@tag">
<xsl:attribute name="href"><xsl:value-of select="concat('#', substring-before(concat(@tag, ' '), ' '))"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates select="node()"/>
</html:a>
</a>
<xsl:call-template name="toc">
<xsl:with-param name="level" select="$level + 1"/>
<xsl:with-param name="context" select="."/>
@@ -142,7 +141,7 @@
</xsl:call-template>
</li>
</xsl:for-each>
</html:ol>
</ol>
</xsl:if>
</xsl:template>
<xsl:template match="liberator:toc" mode="pass-2">
@@ -156,7 +155,7 @@
<xsl:variable name="toc" select="exsl:node-set($TOC)"/>
<xsl:if test="//liberator:toc[1 and self::*]">
<html:div liberator:highlight="HelpTOC">
<div liberator:highlight="HelpTOC">
<h2>Contents</h2>
<xsl:if test="@start">
<xsl:call-template name="toc">
@@ -169,41 +168,41 @@
<xsl:with-param name="toc" select="$toc"/>
</xsl:call-template>
</xsl:if>
</html:div>
</div>
</xsl:if>
</xsl:template>
<!-- Items {{{1 -->
<xsl:template match="liberator:item" mode="pass-2">
<xsl:copy>
<div liberator:highlight="HelpItem">
<xsl:apply-templates select="liberator:tags|liberator:spec"/>
<html:hr style="border: 0; height: 0; margin: 0; width: 100%; float: right;"/>
<html:div liberator:highlight="HelpOptInfo">
<hr style="border: 0; height: 0; margin: 0; width: 100%; float: right;"/>
<div liberator:highlight="HelpOptInfo">
<xsl:apply-templates select="liberator:type|liberator:default"/>
<html:div style="clear: both;"/>
</html:div>
<div style="clear: both;"/>
</div>
<xsl:apply-templates select="liberator:description"/>
<html:div style="clear: both;"/>
</xsl:copy>
<div style="clear: both;"/>
</div>
</xsl:template>
<xsl:template match="liberator:spec[preceding-sibling::liberator:spec]" mode="pass-2">
<html:div style="clear: both;"/>
<xsl:copy>
<div style="clear: both;"/>
<div liberator:highlight="HelpSpec">
<xsl:apply-templates/>
</xsl:copy>
</div>
</xsl:template>
<xsl:template match="liberator:default[not(@type='plain')]" mode="pass-2">
<xsl:variable name="type" select="preceding-sibling::liberator:type[1] | following-sibling::liberator:type[1]"/>
<xsl:copy>
<span liberator:highlight="HelpDefault">(default:<xsl:text> </xsl:text>
<xsl:choose>
<xsl:when test="starts-with($type, 'string')">
<str><xsl:apply-templates/></str>
<span liberator:highlight="HelpString"><xsl:apply-templates/></span>
</xsl:when>
<xsl:otherwise>
<span>
<xsl:attribute name="highlight" namespace="http://vimperator.org/namespaces/liberator">
<xsl:attribute name="liberator:highlight">
<xsl:choose>
<xsl:when test="$type = 'boolean'">Boolean</xsl:when>
<xsl:when test="$type = 'number'">Number</xsl:when>
@@ -213,14 +212,14 @@
<xsl:apply-templates/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</xsl:choose>)
</span>
</xsl:template>
<!-- Tag Definitions {{{1 -->
<xsl:template match="liberator:tags" mode="pass-2">
<html:div style="clear: right"/>
<div style="clear: right"/>
<xsl:call-template name="parse-tags">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
@@ -232,98 +231,157 @@
</xsl:template>
<xsl:template name="parse-tags">
<xsl:param name="text"/>
<tags>
<div liberator:highlight="HelpTags">
<xsl:for-each select="str:tokenize($text)">
<html:a id="{.}"><tag><xsl:value-of select="."/></tag></html:a>
<a id="{.}" liberator:highlight="HelpTag"><xsl:value-of select="."/></a>
</xsl:for-each>
</tags>
</div>
</xsl:template>
<!-- Tag Links {{{1 -->
<xsl:template name="linkify-tag">
<xsl:param name="contents"/>
<xsl:param name="contents" select="text()"/>
<xsl:variable name="tag" select="str:tokenize($contents, ' [')[1]"/>
<html:a href="liberator://help-tag/{$tag}" style="color: inherit;">
<a href="liberator://help-tag/{$tag}" style="color: inherit;">
<xsl:if test="contains($tags, concat(' ', $tag, ' '))">
<xsl:attribute name="href">#<xsl:value-of select="$tag"/></xsl:attribute>
</xsl:if>
<xsl:value-of select="$contents"/>
</html:a>
</a>
</xsl:template>
<xsl:template match="liberator:o" mode="pass-2">
<xsl:copy>
<span liberator:highlight="HelpOption">
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select='concat("&#39;", text(), "&#39;")'/>
</xsl:call-template>
</xsl:copy>
</span>
</xsl:template>
<xsl:template match="liberator:k|liberator:t" mode="pass-2">
<xsl:copy>
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select="text()"/>
</xsl:call-template>
</xsl:copy>
<xsl:template match="liberator:t" mode="pass-2">
<span liberator:highlight="HelpTopic">
<xsl:call-template name="linkify-tag"/>
</span>
</xsl:template>
<xsl:template match="liberator:k" mode="pass-2">
<span liberator:highlight="HelpKey">
<xsl:call-template name="linkify-tag"/>
</span>
</xsl:template>
<xsl:template match="liberator:k[@name]" mode="pass-2">
<xsl:copy>
<span liberator:highlight="HelpKey">
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select="concat('&lt;', @name, '>', .)"/>
</xsl:call-template>
</xsl:copy>
</span>
</xsl:template>
<!-- HTML-ish elements {{{1 -->
<xsl:template match="liberator:ul" mode="pass-2">
<html:ul liberator:highlight="HelpList"><xsl:apply-templates select="@*|node()"/></html:ul>
</xsl:template>
<xsl:template match="liberator:ol" mode="pass-2">
<html:ol liberator:highlight="HelpOrderedList"><xsl:apply-templates select="@*|node()"/></html:ol>
</xsl:template>
<xsl:template match="liberator:ex" mode="pass-2">
<xsl:copy>
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template match="liberator:dl" mode="pass-2">
<xsl:copy>
<dl>
<column/>
<column/>
<xsl:for-each select="liberator:dt">
<tr>
<xsl:apply-templates select="."/>
<xsl:apply-templates select="following-sibling::liberator:dd[position()=1]"/>
<xsl:apply-templates select="following-sibling::liberator:dd[1]"/>
</tr>
</xsl:for-each>
</xsl:copy>
</dl>
</xsl:template>
<xsl:template match="liberator:link" mode="pass-2">
<html:a href="{@topic}"><xsl:apply-templates select="@*|node()"/></html:a>
<a href="{@topic}"><xsl:apply-templates select="@*|node()"/></a>
</xsl:template>
<!-- Plugins {{1 -->
<xsl:template match="liberator:em | liberator:tt | liberator:p |
liberator:dt | liberator:dd |
liberator:ol | liberator:ul | liberator:li |
liberator:h1 | liberator:h2 | liberator:h3"
mode="pass-2">
<xsl:element name="html:{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="liberator:code" mode="pass-2">
<pre liberator:highlight="HelpCode"><xsl:apply-templates select="@*|node()"/></pre>
</xsl:template>
<!-- Help elements {{{1 -->
<xsl:template match="liberator:a" mode="pass-2">
<span liberator:highlight="HelpArg">[<xsl:apply-templates select="@*|node()"/>]</span>
</xsl:template>
<xsl:template match="liberator:oa" mode="pass-2">
<span liberator:highlight="HelpOptionalArg">{<xsl:apply-templates select="@*|node()"/>}</span>
</xsl:template>
<xsl:template match="liberator:note" mode="pass-2">
<p>
<span liberator:highlight="Note">Note:</span>
<xsl:text> </xsl:text>
<xsl:apply-templates select="@*|node()"/>
</p>
</xsl:template>
<xsl:template match="liberator:warning" mode="pass-2">
<p>
<span liberator:highlight="Warning">Warning:</span>
<xsl:text> </xsl:text>
<xsl:apply-templates select="@*|node()"/>
</p>
</xsl:template>
<xsl:template match="liberator:default" mode="pass-2">
<span liberator:highlight="HelpDefault">
(default:<xsl:text> </xsl:text><xsl:apply-templates select="@*|node()"/>)
</span>
</xsl:template>
<!-- HTML-ify other elements {{{1 -->
<xsl:template match="liberator:ex" mode="pass-2">
<span liberator:highlight="HelpEx">
<xsl:call-template name="linkify-tag">
<xsl:with-param name="contents" select="."/>
</xsl:call-template>
</span>
</xsl:template>
<xsl:template match="liberator:description | liberator:example | liberator:spec" mode="pass-2">
<div>
<xsl:if test="self::liberator:description"><xsl:attribute name="liberator:highlight">HelpDescription</xsl:attribute></xsl:if>
<xsl:if test="self::liberator:example"><xsl:attribute name="liberator:highlight">HelpExample</xsl:attribute></xsl:if>
<xsl:if test="self::liberator:spec"><xsl:attribute name="liberator:highlight">HelpSpec</xsl:attribute></xsl:if>
<xsl:apply-templates select="@*|node()"/>
</div>
</xsl:template>
<xsl:template match="liberator:str | liberator:t | liberator:type" mode="pass-2">
<span>
<xsl:if test="self::liberator:str"><xsl:attribute name="liberator:highlight">HelpString</xsl:attribute></xsl:if>
<xsl:if test="self::liberator:t"><xsl:attribute name="liberator:highlight">HelpTopic</xsl:attribute></xsl:if>
<xsl:if test="self::liberator:type"><xsl:attribute name="liberator:highlight">HelpType</xsl:attribute></xsl:if>
<xsl:apply-templates select="@*|node()"/>
</span>
</xsl:template>
<!-- Plugins {{{1 -->
<xsl:template name="info">
<xsl:param name="label"/>
<xsl:param name="prelink" select="''"/>
<xsl:param name="link" select="@href"/>
<html:div liberator:highlight="HelpInfo">
<html:div liberator:highlight="HelpInfoLabel">
<div liberator:highlight="HelpInfo">
<div liberator:highlight="HelpInfoLabel">
<xsl:value-of select="$label"/>:
</html:div>
<html:a liberator:highlight="HelpInfoValue">
</div>
<a liberator:highlight="HelpInfoValue">
<xsl:if test="$link">
<xsl:attribute name="href"><xsl:value-of select="concat($prelink, $link)"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</html:a>
</html:div>
</a>
</div>
</xsl:template>
<xsl:template match="liberator:author" mode="pass-2">
<xsl:call-template name="info">
@@ -338,19 +396,23 @@
</xsl:call-template>
</xsl:template>
<xsl:template match="liberator:plugin" mode="pass-2">
<html:div liberator:highlight="HelpInfo">
<html:div liberator:highlight="HelpInfoLabel">
<div liberator:highlight="HelpInfo">
<div liberator:highlight="HelpInfoLabel">
Plugin:
</html:div>
<html:a liberator:highlight="HelpInfoValue" href="{@href}">
</div>
<a liberator:highlight="HelpInfoValue" href="{@href}">
<xsl:value-of select="@name"/>
</html:a>
</html:div>
</a>
</div>
<xsl:apply-templates/>
</xsl:template>
<!-- Special Element Templates {{{1 -->
<xsl:template match="liberator:logo">
<span liberator:highlight="Logo"/>
</xsl:template>
<xsl:template match="liberator:pan[liberator:handle]">
<form style="text-align:center" xmlns="http://www.w3.org/1999/xhtml"
action="https://www.paypal.com/cgi-bin/webscr" method="post">