[yelp-xsl] html.xsl: Added common html.syntax.class for syntax brush



commit 812ec501a6391e8179e263a4283903c525462c29
Author: Shaun McCance <shaunm gnome org>
Date:   Sat Nov 2 11:03:16 2013 -0400

    html.xsl: Added common html.syntax.class for syntax brush
    
    Switched both db2html and mal2html to use this common template
    to determine the syntax highlighter. This makes it easier for
    outside tools to determine the brush, such as the file-copying
    code in yelp-build.

 xslt/common/html.xsl                 |   79 ++++++++++++++++++++++++++++++++++
 xslt/docbook/html/db2html-block.xsl  |   61 +++-----------------------
 xslt/mallard/html/mal2html-block.xsl |   64 +++-------------------------
 3 files changed, 91 insertions(+), 113 deletions(-)
---
diff --git a/xslt/common/html.xsl b/xslt/common/html.xsl
index d2ab7dd..f44c924 100644
--- a/xslt/common/html.xsl
+++ b/xslt/common/html.xsl
@@ -2249,4 +2249,83 @@ if ${dir} is non-empty.
   </xsl:if>
 </xsl:template>
 
+
+<!--**==========================================================================
+html.syntax.class
+Output HTML class values for syntax highlighting.
+:Revision:version="3.12" date="2013-11-02" status="final"
+$node: The source element whose content will be syntax highlighted.
+$mime: A MIME type identifying the content, as from a Mallard #{mime} attribute.
+$language: A name identifying the content as from a DocBook #{language} attribute.
+
+This template looks at ${mime} and ${language} and determines if there is a
+suitable syntax highlighting brush available. If so, it outputs a string that
+should be placed in the #{class} attribute of a #{pre} element by the calling
+template.
+-->
+<xsl:template name="html.syntax.class">
+  <xsl:param name="node" select="."/>
+  <xsl:param name="mime" select="$node/@mime"/>
+  <xsl:param name="language" select="$node/@language"/>
+  <xsl:choose>
+    <xsl:when test="$mime = 'application/x-shellscript' or $language = 'bash'">
+      <xsl:text>syntax brush-bash-script</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-csrc' or $mime = 'text/x-chdr' or
+                    $mime = 'text/x-c++hdr' or $mime = 'text/x-c++src' or
+                    $mime = 'text/x-objcsrc' or $language = 'c' or
+                    $language = 'cpp' or $language = 'objc'">
+      <xsl:text>syntax brush-clang</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-csharp' or $language = 'csharp'">
+      <xsl:text>syntax brush-csharp</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/css' or $language = 'css'">
+      <xsl:text>syntax brush-css</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-patch' or $language = 'diff'">
+      <xsl:text>syntax brush-diff</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/html' or $mime = 'application/xml' or
+                    substring($mime, string-length($mime) - 3) = '+xml' or
+                    $language = 'html' or $language = 'xml'">
+      <xsl:text>syntax brush-html</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-java' or $language = 'java'">
+      <xsl:text>syntax brush-java</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'application/javascript' or $language = 'javascript'">
+      <xsl:text>syntax brush-javascript</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-scheme' or $mime = 'text/x-emacs-lisp' or
+                    $language = 'lisp'">
+      <xsl:text>syntax brush-lisp</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-lua' or $language = 'lua'">
+      <xsl:text>syntax brush-lua</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-pascal' or $language = 'pascal'">
+      <xsl:text>syntax brush-pascal</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'application/x-perl' or $language = 'perl'">
+      <xsl:text>syntax brush-perl5</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'application/x-php' or $language = 'php'">
+      <xsl:text>syntax brush-php-script</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-python' or $language = 'python'">
+      <xsl:text>syntax brush-python</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'application/x-ruby' or $language = 'ruby'">
+      <xsl:text>syntax brush-ruby</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'text/x-sql' or $language = 'sql'">
+      <xsl:text>syntax brush-sql</xsl:text>
+    </xsl:when>
+    <xsl:when test="$mime = 'application/x-yaml' or $language = 'yaml'">
+      <xsl:text>syntax brush-yaml</xsl:text>
+    </xsl:when>
+  </xsl:choose>
+</xsl:template>
+
 </xsl:stylesheet>
diff --git a/xslt/docbook/html/db2html-block.xsl b/xslt/docbook/html/db2html-block.xsl
index d422d38..92de738 100644
--- a/xslt/docbook/html/db2html-block.xsl
+++ b/xslt/docbook/html/db2html-block.xsl
@@ -300,7 +300,7 @@ This template handles conditional processing.
 <!--**==========================================================================
 db2html.pre
 Output an HTML #{pre} element for a block-level element.
-:Revision:version="3.10" date="2013-08-09" status="final"
+:Revision:version="3.12" date="2013-11-02" status="final"
 $node: The block-level element to render.
 $class: The value of the HTML #{class} attribute.
 $children: The child elements to process.
@@ -317,7 +317,8 @@ By default, this template applies templates to all child nodes. Pass child
 nodes in the ${children} parameter to override this behavior.
 
 If @{html.syntax.highlight} is #{true}, this template automatically outputs
-syntax highlighting support based on the #{language} attribute of ${node}.
+syntax highlighting support based on the #{language} attribute of ${node},
+using *{html.syntax.class} to determine the correct highlighter.
 
 This template handles conditional processing.
 -->
@@ -365,59 +366,9 @@ This template handles conditional processing.
       <xsl:attribute name="class">
         <xsl:text>contents </xsl:text>
         <xsl:if test="$html.syntax.highlight and $node/@language">
-          <xsl:choose>
-            <xsl:when test="@language = 'bash'">
-              <xsl:text>syntax brush-bash-script</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'c' or @language = 'cpp' or @language = 'objc'">
-              <xsl:text>syntax brush-clang</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'csharp'">
-              <xsl:text>syntax brush-csharp</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'css'">
-              <xsl:text>syntax brush-css</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'diff'">
-              <xsl:text>syntax brush-diff</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'html' or @language = 'xml'">
-              <xsl:text>syntax brush-html</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'java'">
-              <xsl:text>syntax brush-java</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'javascript'">
-              <xsl:text>syntax brush-javascript</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'lisp'">
-              <xsl:text>syntax brush-lisp</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'lua'">
-              <xsl:text>syntax brush-lua</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'pascal'">
-              <xsl:text>syntax brush-pascal</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'perl'">
-              <xsl:text>syntax brush-perl5</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'php'">
-              <xsl:text>syntax brush-php-script</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'python'">
-              <xsl:text>syntax brush-python</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'ruby'">
-              <xsl:text>syntax brush-ruby</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'sql'">
-              <xsl:text>syntax brush-sql</xsl:text>
-            </xsl:when>
-            <xsl:when test="@language = 'yaml'">
-              <xsl:text>syntax brush-yaml</xsl:text>
-            </xsl:when>
-          </xsl:choose>
+          <xsl:call-template name="html.syntax.class">
+            <xsl:with-param name="node" select="$node"/>
+          </xsl:call-template>
         </xsl:if>
       </xsl:attribute>
       <!-- Strip off a leading newline -->
diff --git a/xslt/mallard/html/mal2html-block.xsl b/xslt/mallard/html/mal2html-block.xsl
index 7ad82dc..d947eb3 100644
--- a/xslt/mallard/html/mal2html-block.xsl
+++ b/xslt/mallard/html/mal2html-block.xsl
@@ -39,7 +39,7 @@ except the list and table elements.
 <!--**==========================================================================
 mal2html.pre
 Output an HTML #{pre} element.
-:Revision:version="1.0" date="2010-06-03" status="final"
+:Revision:version="3.12" date="2013-11-02" status="final"
 $node: The source element to output a #{pre} for.
 
 This template outputs an HTML #{pre} element along with a wrapper #{div} element
@@ -47,7 +47,8 @@ for CSS styling. It should be called for verbatim block elements. It will
 automatically strip leading and trailing newlines using *{utils.strip_newlines}.
 
 If @{html.syntax.highlight} is #{true}, this template automatically outputs
-syntax highlighting support based on the #{mime} attribute of ${node}.
+syntax highlighting support based on the #{mime} attribute of ${node}, using
+*{html.syntax.class} to determine the correct highlighter.
 -->
 <xsl:template name="mal2html.pre">
   <xsl:param name="node" select="."/>
@@ -83,62 +84,9 @@ syntax highlighting support based on the #{mime} attribute of ${node}.
       <xsl:attribute name="class">
         <xsl:text>contents </xsl:text>
         <xsl:if test="$html.syntax.highlight and $node/@mime">
-          <xsl:choose>
-            <xsl:when test="@mime = 'application/x-shellscript'">
-              <xsl:text>syntax brush-bash-script</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-csrc' or @mime = 'text/x-chdr' or
-                            @mime = 'text/x-c++hdr' or @mime = 'text/x-c++src' or
-                            @mime = 'text/x-objcsrc'">
-              <xsl:text>syntax brush-clang</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-csharp'">
-              <xsl:text>syntax brush-csharp</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/css'">
-              <xsl:text>syntax brush-css</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-patch'">
-              <xsl:text>syntax brush-diff</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/html' or @mime = 'application/xml' or
-                            substring(@mime, string-length(@mime) - 3) = '+xml'">
-              <xsl:text>syntax brush-html</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-java'">
-              <xsl:text>syntax brush-java</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'application/javascript'">
-              <xsl:text>syntax brush-javascript</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-scheme' or @mime = 'text/x-emacs-lisp'">
-              <xsl:text>syntax brush-lisp</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-lua'">
-              <xsl:text>syntax brush-lua</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-pascal'">
-              <xsl:text>syntax brush-pascal</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'application/x-perl'">
-              <xsl:text>syntax brush-perl5</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'application/x-php'">
-              <xsl:text>syntax brush-php-script</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-python'">
-              <xsl:text>syntax brush-python</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'application/x-ruby'">
-              <xsl:text>syntax brush-ruby</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'text/x-sql'">
-              <xsl:text>syntax brush-sql</xsl:text>
-            </xsl:when>
-            <xsl:when test="@mime = 'application/x-yaml'">
-              <xsl:text>syntax brush-yaml</xsl:text>
-            </xsl:when>
-          </xsl:choose>
+          <xsl:call-template name="html.syntax.class">
+            <xsl:with-param name="node" select="$node"/>
+          </xsl:call-template>
         </xsl:if>
       </xsl:attribute>
       <xsl:if test="$first">


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]