]> Lady’s Gitweb - LesML/blobdiff - parser.xslt
Support inline comments
[LesML] / parser.xslt
index 7f6d153b8c1bd3bb373187ffc2b7ddaeb7ba4846..7e6f6a305701e724cabb2b3c15a231a39f0c06f6 100644 (file)
@@ -625,7 +625,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </for-each>
                </variable>
                <variable name="inlined">
                        </for-each>
                </variable>
                <variable name="inlined">
-                       <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
+                       <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:comment"/>
                </variable>
                <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
        </template>
                </variable>
                <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
        </template>
@@ -750,6 +750,99 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
                </copy>
        </template>
                        <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
                </copy>
        </template>
+       <template match="node()" mode="LesML:comment">
+               <variable name="result">
+                       <choose>
+                               <when test="self::*">
+                                       <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
+                                       <variable name="after-start">
+                                               <if test="$start-node">
+                                                       <value-of select="substring-after($start-node, '⌦')"/>
+                                               </if>
+                                       </variable>
+                                       <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
+                                       <choose>
+                                               <when test="$start-node and $has-end-node">
+                                                       <variable name="following">
+                                                               <value-of select="$after-start"/>
+                                                               <copy-of select="$start-node/following-sibling::node()"/>
+                                                       </variable>
+                                                       <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
+                                                       <variable name="comment">
+                                                               <for-each select="$end-node/preceding-sibling::node()">
+                                                                       <value-of select="."/>
+                                                               </for-each>
+                                                               <value-of select="substring-before($end-node, '⌫')"/>
+                                                       </variable>
+                                                       <variable name="comment-split-fragment">
+                                                               <call-template name="LesML:split">
+                                                                       <with-param name="source" select="string($comment)"/>
+                                                                       <with-param name="separator" select="'--'"/>
+                                                               </call-template>
+                                                       </variable>
+                                                       <variable name="rest-fragment">
+                                                               <element name="span" namespace="&xhtml;">
+                                                                       <value-of select="substring-after($end-node, '⌫')"/>
+                                                                       <copy-of select="$end-node/following-sibling::node()"/>
+                                                               </element>
+                                                       </variable>
+                                                       <variable name="commented-rest-fragment">
+                                                               <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment"/>
+                                                       </variable>
+                                                       <copy>
+                                                               <copy-of select="@*"/>
+                                                               <copy-of select="$start-node/preceding-sibling::node()"/>
+                                                               <copy-of select="substring-before($start-node, '⌦')"/>
+                                                               <comment>
+                                                                       <for-each select="exsl:node-set($comment-split-fragment)/*">
+                                                                               <if test="string()='' or starts-with(., '‐')">
+                                                                                       <text>&#x034F;</text>
+                                                                               </if>
+                                                                               <value-of select="."/>
+                                                                               <if test="substring(., string-length(.), 1)='‐'">
+                                                                                       <text>&#x034F;</text>
+                                                                               </if>
+                                                                               <choose>
+                                                                                       <when test="position()!=last()">
+                                                                                               <text>-&#x034F;-</text>
+                                                                                       </when>
+                                                                               </choose>
+                                                                       </for-each>
+                                                               </comment>
+                                                               <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
+                                                       </copy>
+                                               </when>
+                                               <otherwise>
+                                                       <copy>
+                                                               <copy-of select="@*"/>
+                                                               <apply-templates select="node()" mode="LesML:comment"/>
+                                                       </copy>
+                                               </otherwise>
+                                       </choose>
+                               </when>
+                               <when test="self::text()[contains(., '⌧')]">
+                                       <variable name="split-fragment">
+                                               <call-template name="LesML:split">
+                                                       <with-param name="source" select="string()"/>
+                                                       <with-param name="separator" select="'⌧'"/>
+                                               </call-template>
+                                       </variable>
+                                       <for-each select="exsl:node-set($split-fragment)/node()">
+                                               <value-of select="."/>
+                                               <if test="position()!=last()">
+                                                       <comment>
+                                                               <text>&#x034F;</text>
+                                                       </comment>
+                                               </if>
+                                       </for-each>
+                               </when>
+                               <otherwise>
+                                       <copy-of select="."/>
+                               </otherwise>
+                       </choose>
+               </variable>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify"/>
+       </template>
        <template match="node()" mode="LesML:inline">
                <param name="element-name"/>
                <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
        <template match="node()" mode="LesML:inline">
                <param name="element-name"/>
                <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
This page took 0.205906 seconds and 4 git commands to generate.