[yelp-xsl] mal2html: Added MathML support



commit 563a3d6cebf1bc644e5e4fbff3b2d9458d61b7a4
Author: Shaun McCance <shaunm gnome org>
Date:   Tue Nov 13 16:59:25 2012 -0500

    mal2html: Added MathML support

 xslt/common/html.xsl                  |   26 ++++++-
 xslt/mallard/html/Makefile.am         |    1 +
 xslt/mallard/html/mal2html-inline.xsl |    8 +-
 xslt/mallard/html/mal2html-math.xsl   |  135 +++++++++++++++++++++++++++++++++
 xslt/mallard/html/mal2html.xsl        |    4 +-
 xslt/mallard/html/mal2xhtml.xsl       |   13 ++--
 6 files changed, 175 insertions(+), 12 deletions(-)
---
diff --git a/xslt/common/html.xsl b/xslt/common/html.xsl
index 36a9796..5ac785c 100644
--- a/xslt/common/html.xsl
+++ b/xslt/common/html.xsl
@@ -18,11 +18,12 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 xmlns:html="http://www.w3.org/1999/xhtml";
+                xmlns:math="http://www.w3.org/1998/Math/MathML";
                 xmlns:exsl="http://exslt.org/common";
                 xmlns:set="http://exslt.org/sets";
                 xmlns:its="http://www.w3.org/2005/11/its";
                 xmlns="http://www.w3.org/1999/xhtml";
-                exclude-result-prefixes="html set its"
+                exclude-result-prefixes="html math set its"
                 extension-element-prefixes="exsl"
                 version="1.0">
 
@@ -1489,6 +1490,9 @@ ouput the contents of that tag.
   <xsl:call-template name="html.js.jquery">
     <xsl:with-param name="node" select="$node"/>
   </xsl:call-template>
+  <xsl:call-template name="html.js.mathjax">
+    <xsl:with-param name="node" select="$node"/>
+  </xsl:call-template>
   <xsl:call-template name="html.js.custom">
     <xsl:with-param name="node" select="$node"/>
   </xsl:call-template>
@@ -1532,6 +1536,26 @@ output relative to @{html.js.root}.
 
 
 <!--**==========================================================================
+html.js.mathjax
+Output #{script} element to include MathJax.
+:Revision: version="1.0" date="2012-11-13" status="incomplete"
+$node: The node to create JavaScript for.
+
+FIXME
+-->
+<xsl:template name="html.js.mathjax">
+  <xsl:param name="node" select="."/>
+  <xsl:if test="$node//math:*[1]">
+    <script type="text/javascript">
+      <xsl:attribute name="src">
+        <xsl:text>http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML</xsl:text>
+      </xsl:attribute>
+    </script>
+  </xsl:if>
+</xsl:template>
+
+
+<!--**==========================================================================
 html.js.content
 Output JavaScript content for an HTML output page.
 :Revision:version="3.4" date="2011-11-04" status="final"
diff --git a/xslt/mallard/html/Makefile.am b/xslt/mallard/html/Makefile.am
index 9d19611..af12065 100644
--- a/xslt/mallard/html/Makefile.am
+++ b/xslt/mallard/html/Makefile.am
@@ -8,6 +8,7 @@ xsl_DATA =				\
 	mal2html-inline.xsl		\
 	mal2html-links.xsl		\
 	mal2html-list.xsl		\
+	mal2html-math.xsl		\
 	mal2html-media.xsl		\
 	mal2html-page.xsl		\
 	mal2html-svg.xsl		\
diff --git a/xslt/mallard/html/mal2html-inline.xsl b/xslt/mallard/html/mal2html-inline.xsl
index 7d11a1f..e5b28a0 100644
--- a/xslt/mallard/html/mal2html-inline.xsl
+++ b/xslt/mallard/html/mal2html-inline.xsl
@@ -25,8 +25,8 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
 <!--!!==========================================================================
 Mallard to HTML - Inlines
-Handle simple Mallard block elements.
-:Revision:version="3.8" date="2012-11-09" status="final"
+Handle simple Mallard inline elements.
+:Revision:version="3.8" date="2012-11-13" status="final"
 
 This stylesheet contains templates to handle most Mallard inline elements.
 It also maps %{mal.link.content.mode} to %{mal2html.inline.mode}.
@@ -40,11 +40,11 @@ It also maps %{mal.link.content.mode} to %{mal2html.inline.mode}.
 <!--%%==========================================================================
 mal2html.inline.mode
 Process Mallard elements in inline mode.
-:Revision:version="1.0" date="2010-06-03" status="final"
+:Revision:version="3.8" date="2012-11-13" status="final"
 
 This mode is applied to elements in inline context. It is be called by certain
 block elements and inline elements to process child content. Certain elements
-may appear in both block an inline mode, and the processing expectations for
+may appear in both block and inline mode, and the processing expectations for
 those elements is different depending on context.
 
 Implementations of this mode should handle ubiquitous linking, text directionality,
diff --git a/xslt/mallard/html/mal2html-math.xsl b/xslt/mallard/html/mal2html-math.xsl
new file mode 100644
index 0000000..c83a1d1
--- /dev/null
+++ b/xslt/mallard/html/mal2html-math.xsl
@@ -0,0 +1,135 @@
+<?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
+<!--
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free
+Software Foundation; either version 2 of the License, or (at your option) any
+later version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT
+ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this program; see the file COPYING.LGPL.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+-->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
+                xmlns:mal="http://projectmallard.org/1.0/";
+                xmlns:math="http://www.w3.org/1998/Math/MathML";
+                xmlns:xlink="http://www.w3.org/1999/xlink";
+                xmlns="http://www.w3.org/1999/xhtml";
+                exclude-result-prefixes="mal math xlink"
+                version="1.0">
+
+<!--!!==========================================================================
+Mallard to HTML - MathML
+Handle embedded MathML.
+:Revision: version="3.8" date="2012-11-13" status="final"
+
+This stylesheet matches embedded MathML in %{mal2html.block.mode} and
+%{mal2html.inline.mode} and processes it in %{mal2html.math.mode}. The
+matched templates for the #{math:math} element automatically set the
+#{display} attribute based on whether the element is in block or inline
+context.
+-->
+
+
+<xsl:variable name="math.namespace">
+  <xsl:choose>
+    <xsl:when test="$html.namespace = 'http://www.w3.org/1999/xhtml'">
+      <xsl:text>http://www.w3.org/1998/Math/MathML</xsl:text>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:text></xsl:text>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:variable>
+
+
+<!--%%==========================================================================
+mal2html.math.mode
+Output MathML and handle Mallard extension.
+:Revision: version="3.8" date="2012-11-13" status="final"
+
+This mode is used for processing MathML embedded into Mallard documents. For
+most types of MathML content, it simply copies the input directly. It checks
+for Mallard linking using the #{mal:xref} attribute and transforms this to a
+MathML #{href} attribute. It also converts #{xlink:href} attributes from
+MathML 2 to #{href} attributes for MathML 3.
+-->
+<xsl:template mode="mal2html.math.mode" match="math:*">
+  <xsl:element name="{local-name(.)}" namespace="{$math.namespace}">
+    <xsl:for-each select="@*[name(.) != 'href']">
+      <xsl:copy-of select="."/>
+    </xsl:for-each>
+    <xsl:choose>
+      <xsl:when test="@mal:xref">
+        <xsl:attribute name="href">
+          <xsl:call-template name="mal.link.target">
+            <xsl:with-param name="node" select="."/>
+            <xsl:with-param name="xref" select="@mal:xref"/>
+          </xsl:call-template>
+        </xsl:attribute>
+      </xsl:when>
+      <xsl:when test="@href">
+        <xsl:copy-of select="@href"/>
+      </xsl:when>
+      <xsl:when test="@xlink:href">
+        <xsl:attribute name="href">
+          <xsl:value-of select="@xlink:href"/>
+        </xsl:attribute>
+      </xsl:when>
+    </xsl:choose>
+    <xsl:apply-templates mode="mal2html.math.mode"/>
+  </xsl:element>
+</xsl:template>
+
+<xsl:template mode="mal2html.math.mode" match="text()">
+  <xsl:value-of select="."/>
+</xsl:template>
+
+<xsl:template mode="mal2html.block.mode" match="math:math">
+  <xsl:variable name="if"><xsl:call-template name="mal.if.test"/></xsl:variable><xsl:if test="$if != ''">
+  <div>
+    <xsl:call-template name="html.lang.attrs"/>
+    <xsl:attribute name="class">
+      <xsl:text>math</xsl:text>
+      <xsl:if test="$if != 'true'">
+        <xsl:text> if-if </xsl:text>
+        <xsl:value-of select="$if"/>
+      </xsl:if>
+    </xsl:attribute>
+    <xsl:element name="math" namespace="{$math.namespace}">
+      <xsl:for-each select="@*[name(.) != 'display']
+                              [not(starts-with(namespace-uri(.), 'http://projectmallard.org/'))]">
+        <xsl:copy-of select="."/>
+      </xsl:for-each>
+      <xsl:attribute name="display">
+        <xsl:value-of select="'block'"/>
+      </xsl:attribute>
+      <xsl:apply-templates mode="mal2html.math.mode"/>
+    </xsl:element>
+  </div>
+</xsl:if>
+</xsl:template>
+
+<xsl:template mode="mal2html.inline.mode" match="math:math">
+  <span class="math">
+    <xsl:call-template name="html.lang.attrs"/>
+    <xsl:element name="math" namespace="{$math.namespace}">
+      <xsl:for-each select="@*[name(.) != 'display']
+                              [not(starts-with(namespace-uri(.), 'http://projectmallard.org/'))]">
+        <xsl:copy-of select="."/>
+      </xsl:for-each>
+      <xsl:attribute name="display">
+        <xsl:value-of select="'inline'"/>
+      </xsl:attribute>
+      <xsl:apply-templates mode="mal2html.math.mode"/>
+    </xsl:element>
+  </span>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/xslt/mallard/html/mal2html.xsl b/xslt/mallard/html/mal2html.xsl
index 0da6249..198c738 100644
--- a/xslt/mallard/html/mal2html.xsl
+++ b/xslt/mallard/html/mal2html.xsl
@@ -18,7 +18,8 @@ Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                 xmlns:html="http://www.w3.org/1999/xhtml";
-                exclude-result-prefixes="html"
+                xmlns:math="http://www.w3.org/1998/Math/MathML";
+                exclude-result-prefixes="html math"
                 version="1.0">
 
 <!--!!==========================================================================
@@ -38,5 +39,6 @@ sets @{html.xhtml} to #{false} and @{mal.if.target} to #{'target:html'}.
 <xsl:include href="mal2xhtml.xsl" pass="true"><?pass?></xsl:include>
 
 <xsl:namespace-alias stylesheet-prefix="html" result-prefix="#default"/>
+<xsl:namespace-alias stylesheet-prefix="math" result-prefix="#default"/>
 
 </xsl:stylesheet>
diff --git a/xslt/mallard/html/mal2xhtml.xsl b/xslt/mallard/html/mal2xhtml.xsl
index 4d0c87b..4cebca0 100644
--- a/xslt/mallard/html/mal2xhtml.xsl
+++ b/xslt/mallard/html/mal2xhtml.xsl
@@ -45,12 +45,6 @@ and @{ttml.features}.
 <xsl:import href="../common/mal-if.xsl"/>
 <xsl:import href="../common/mal-link.xsl"/>
 
-<xsl:param name="mal.if.target" select="'target:html target:xhtml'"/>
-<xsl:param name="mal.if.features" select="'
-mallard:1.0
-'"/>
-<xsl:param name="mal.if.maybe" select="'target:mobile'"/>
-<xsl:param name="mal.link.extension" select="$html.extension"/>
 <xsl:param name="ttml.features" select="'
 http://www.w3.org/ns/ttml/feature/#content
 http://www.w3.org/ns/ttml/feature/#core
@@ -62,6 +56,12 @@ http://www.w3.org/ns/ttml/feature/#structure
 http://www.w3.org/ns/ttml/feature/#time-offset
 http://www.w3.org/ns/ttml/feature/#timing
 '"/>
+<xsl:param name="mal.if.target" select="'target:html target:xhtml'"/>
+<xsl:param name="mal.if.features" select="concat('
+mallard:1.0
+', $ttml.features)"/>
+<xsl:param name="mal.if.maybe" select="'target:mobile'"/>
+<xsl:param name="mal.link.extension" select="$html.extension"/>
 
 <xsl:include href="mal2html-api.xsl"/>
 <xsl:include href="mal2html-block.xsl"/>
@@ -70,6 +70,7 @@ http://www.w3.org/ns/ttml/feature/#timing
 <xsl:include href="mal2html-inline.xsl"/>
 <xsl:include href="mal2html-links.xsl"/>
 <xsl:include href="mal2html-list.xsl"/>
+<xsl:include href="mal2html-math.xsl"/>
 <xsl:include href="mal2html-media.xsl"/>
 <xsl:include href="mal2html-page.xsl"/>
 <xsl:include href="mal2html-svg.xsl"/>



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