1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 12:17:58 +01:00

Move to a two-stage parser for the help.

This commit is contained in:
Kris Maglione
2009-11-01 21:30:13 -05:00
parent 84da6102dc
commit eaf184ae9b
3 changed files with 108 additions and 88 deletions

View File

@@ -8,37 +8,108 @@
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:str="http://exslt.org/strings"
xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="str">
extension-element-prefixes="exsl str">
<xsl:output method="xml" indent="no"/>
<!-- Variable Definitions {{{1 -->
<xsl:variable name="doc">
<xsl:apply-templates select="/liberator:document" mode="overlay"/>
</xsl:variable>
<xsl:variable name="root" select="exsl:node-set($doc)"/>
<xsl:variable name="tags">
<xsl:text> </xsl:text>
<xsl:for-each select="//@tag|//liberator:tags/text()|//liberator:tag/text()">
<xsl:for-each select="$root//@tag|$root//liberator:tags/text()|$root//liberator:tag/text()">
<xsl:value-of select="concat(., ' ')"/>
</xsl:for-each>
</xsl:variable>
<!-- Process Overlays {{{1 -->
<xsl:variable name="overlay" select="concat('liberator://help-overlay/', /liberator:document/@name)"/>
<xsl:variable name="overlaydoc" select="document($overlay)/liberator:overlay"/>
<xsl:template name="splice-overlays">
<xsl:param name="elem"/>
<xsl:param name="tag"/>
<xsl:for-each select="$overlaydoc/*[@insertbefore=$tag]">
<xsl:apply-templates select="." mode="overlay"/>
</xsl:for-each>
<xsl:choose>
<xsl:when test="$overlaydoc/*[@replace=$tag] and not($elem[@replace])">
<xsl:for-each select="$overlaydoc/*[@replace=$tag]">
<xsl:apply-templates select="." mode="overlay-2"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$elem">
<xsl:apply-templates select="." mode="overlay-2"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="$overlaydoc/*[@insertafter=$tag]">
<xsl:apply-templates select="." mode="overlay"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="liberator:tags[parent::liberator:document]|liberator:tag" mode="overlay">
<xsl:call-template name="splice-overlays">
<xsl:with-param name="tag" select="substring-before(concat(., ' '), ' ')"/>
<xsl:with-param name="elem" select="self::node()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="*[liberator:tags]" mode="overlay">
<xsl:call-template name="splice-overlays">
<xsl:with-param name="tag" select="substring-before(concat(liberator:tags, ' '), ' ')"/>
<xsl:with-param name="elem" select="self::node()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="liberator:*[@tag and not(@replace)]" mode="overlay">
<xsl:call-template name="splice-overlays">
<xsl:with-param name="tag" select="substring-before(concat(@tag, ' '), ' ')"/>
<xsl:with-param name="elem" select="self::node()"/>
</xsl:call-template>
</xsl:template>
<!-- Process Inclusions {{{1 -->
<xsl:template match="liberator:include" mode="overlay-2">
<xsl:copy>
<xsl:apply-templates select="document(@href)/liberator:document/node()" mode="overlay"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|node()" mode="overlay">
<xsl:apply-templates select="." mode="overlay-2"/>
</xsl:template>
<xsl:template match="@*|node()" mode="overlay-2">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="overlay"/>
</xsl:copy>
</xsl:template>
<!-- Root {{{1 -->
<xsl:template match="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"
src="chrome://liberator/content/help.js"/>
</html:head>
<html:body liberator:highlight="HelpBody">
<html:div class="liberator-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>
<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"
src="chrome://liberator/content/help.js"/>
</html:head>
<html:body liberator:highlight="HelpBody">
<html:div class="liberator-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>
</xsl:for-each>
</xsl:template>
<!-- Table of Contents {{{1 -->
@@ -50,8 +121,8 @@
<xsl:variable name="tag" select="concat('h', $level)"/>
<xsl:variable name="lasttag" select="concat('h', $level - 1)"/>
<xsl:variable name="nodes" select="//liberator:*[
local-name() = $tag and preceding::*[local-name() = $lasttag][position() = 1 and . = $context]]"/>
<xsl:variable name="nodes" select="//following-sibling::liberator:*[
local-name() = $tag and preceding-sibling::*[local-name() = $lasttag][position() = 1 and . = $context]]"/>
<xsl:if test="$nodes">
<html:ol liberator:highlight="HelpOrderedList">
@@ -76,13 +147,16 @@
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
<html:div liberator:highlight="HelpTOC">
<h2>Contents</h2>
<xsl:call-template name="toc">
<xsl:with-param name="level" select="2"/>
<xsl:with-param name="context" select="."/>
</xsl:call-template>
</html:div>
<xsl:if test="not($root//liberator:h1[2])">
<!-- Makes :help all impossibly slow. Why? -->
<html:div liberator:highlight="HelpTOC">
<h2>Contents</h2>
<xsl:call-template name="toc">
<xsl:with-param name="level" select="2"/>
<xsl:with-param name="context" select="."/>
</xsl:call-template>
</html:div>
</xsl:if>
</xsl:template>
<!-- Items {{{1 -->
@@ -273,59 +347,6 @@
</form>
</xsl:template>
<!-- Process Inclusions {{{1 -->
<xsl:template match="liberator:include" mode="pass-2">
<xsl:apply-templates select="document(@href)/liberator:document/node()"/>
</xsl:template>
<!-- Process Overlays {{{1 -->
<xsl:variable name="overlay" select="concat('liberator://help-overlay/', /liberator:document/@name)"/>
<xsl:variable name="overlaydoc" select="document($overlay)/liberator:overlay"/>
<xsl:template name="splice-overlays">
<xsl:param name="elem"/>
<xsl:param name="tag"/>
<xsl:for-each select="$overlaydoc/*[@insertbefore=$tag]">
<xsl:apply-templates select="."/>
</xsl:for-each>
<xsl:choose>
<xsl:when test="$overlaydoc/*[@replace=$tag] and not($elem[@replace])">
<xsl:for-each select="$overlaydoc/*[@replace=$tag]">
<xsl:apply-templates select="." mode="pass-2"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="$elem">
<xsl:apply-templates select="." mode="pass-2"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="$overlaydoc/*[@insertafter=$tag]">
<xsl:apply-templates select="."/>
</xsl:for-each>
</xsl:template>
<xsl:template match="liberator:document/liberator:tags|liberator:document/liberator:tag">
<xsl:call-template name="splice-overlays">
<xsl:with-param name="tag" select="substring-before(concat(., ' '), ' ')"/>
<xsl:with-param name="elem" select="self::node()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="liberator:document/*[liberator:tags]">
<xsl:call-template name="splice-overlays">
<xsl:with-param name="tag" select="substring-before(concat(liberator:tags, ' '), ' ')"/>
<xsl:with-param name="elem" select="self::node()"/>
</xsl:call-template>
</xsl:template>
<xsl:template match="liberator:*[@tag and not(@replace)]">
<xsl:call-template name="splice-overlays">
<xsl:with-param name="tag" select="substring-before(concat(@tag, ' '), ' ')"/>
<xsl:with-param name="elem" select="self::node()"/>
</xsl:call-template>
</xsl:template>
<!-- Process Tree {{{1 -->
<xsl:template match="@*|node()" mode="pass-2">

View File

@@ -58,9 +58,9 @@ function Hints() //{{{
V: Mode("View hint source in external editor", function (elem, loc) buffer.viewSource(loc, true), extended),
y: Mode("Yank hint location", function (elem, loc) util.copyToClipboard(loc, true)),
Y: Mode("Yank hint description", function (elem) util.copyToClipboard(elem.textContent || "", true), extended),
c: Mode("Open context menu", function (elem) buffer.openContextMenu(elem), extended),
i: Mode("Show image", function (elem) liberator.open(elem.src), images),
I: Mode("Show image in a new tab", function (elem) liberator.open(elem.src, liberator.NEW_TAB), images)
c: Mode("Open context menu", function (elem) buffer.openContextMenu(elem), extended),
i: Mode("Show image", function (elem) liberator.open(elem.src), images),
I: Mode("Show image in a new tab", function (elem) liberator.open(elem.src, liberator.NEW_TAB), images)
};
/**
@@ -412,8 +412,7 @@ function Hints() //{{{
if (!rect)
continue;
imgSpan = util.xmlToDom(<span highlight="Hint"/>, doc);
imgSpan.setAttributeNS(NS.uri, "class", "HintImage");
imgSpan = util.xmlToDom(<span highlight="Hint" liberator:class="HintImage" xmlns:liberator={NS}/>, doc);
imgSpan.style.left = (rect.left + offsetX) + "px";
imgSpan.style.top = (rect.top + offsetY) + "px";
imgSpan.style.width = (rect.right - rect.left) + "px";

View File

@@ -261,9 +261,9 @@
<p>The following preferences are set:</p>
<ul>
<li><link target="http://kb.mozillazine.org/Dom.popup_allowed_events">dom.popup_allowed_events</link></li>
<li><link target="http://kb.mozillazine.org/Accessibility.typeaheadfind.autostart">accessibility.typeaheadfind.autostart</link></li>
<li><link target="http://kb.mozillazine.org/Accessibility.typeaheadfind">accessibility.typeaheadfind</link></li>
<li><link topic="http://kb.mozillazine.org/Dom.popup_allowed_events">dom.popup_allowed_events</link></li>
<li><link topic="http://kb.mozillazine.org/Accessibility.typeaheadfind.autostart">accessibility.typeaheadfind.autostart</link></li>
<li><link topic="http://kb.mozillazine.org/Accessibility.typeaheadfind">accessibility.typeaheadfind</link></li>
</ul>
<!-- TODO: others? -->