]> Lady’s Gitweb - LesML/blobdiff - parser.xslt
Properly escape all comments
[LesML] / parser.xslt
index f6b38231a9d7d7f0aac4e5739595ed2342fb3aa1..186e3896328a4d76f7259bb1a2f60815a1df3234 100644 (file)
@@ -14,8 +14,8 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 <!DOCTYPE transform [
        <!ENTITY LesML "urn:fdc:ladys.computer:20240512:LesML">
        <!ENTITY section-break "*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~">
-       <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ')">
-       <!ENTITY unsigiled-text "substring($text, 3, string-length($text)-2)">
+       <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ' or substring($text, 2, 1)='¶')">
+       <!ENTITY unsigiled-text "concat(translate(substring($text, 2, 1), ' ', ''), substring($text, 3, string-length($text)-2))">
        <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
 ]>
 <transform
@@ -121,31 +121,96 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </otherwise>
                </choose>
        </template>
+       <template name="LesML:comment-out">
+               <param name="source"/>
+               <variable name="comment-split-fragment">
+                       <call-template name="LesML:split">
+                               <with-param name="source" select="$source"/>
+                               <with-param name="separator" select="'--'"/>
+                       </call-template>
+               </variable>
+               <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>
+       </template>
        <template name="LesML:id-and-contents">
                <param name="source"/>
-               <choose>
-                       <when test="starts-with($source, '¶')">
+               <variable name="id-and-lang">
+                       <if test="starts-with($source, '¶')">
                                <choose>
                                        <when test="contains($source, ' ')">
-                                               <variable name="id" select="substring-before(substring-after($source, '¶'), ' ')"/>
-                                               <if test="$id!=''">
-                                                       <attribute name="id">
-                                                               <value-of select="$id"/>
-                                                       </attribute>
-                                               </if>
-                                               <value-of select="substring-after($source, ' ')"/>
+                                               <value-of select="substring-before(substring-after($source, '¶'), ' ')"/>
                                        </when>
                                        <otherwise>
-                                               <attribute name="id">
-                                                       <value-of select="substring-after($source, '¶')"/>
-                                               </attribute>
+                                               <value-of select="substring-after($source, '¶')"/>
                                        </otherwise>
                                </choose>
-                       </when>
-                       <otherwise>
-                               <value-of select="$source"/>
-                       </otherwise>
-               </choose>
+                       </if>
+               </variable>
+               <variable name="restoftext">
+                       <choose>
+                               <when test="starts-with($source, '¶') and contains($source, ' ')">
+                                       <value-of select="substring-after($source, ' ')"/>
+                               </when>
+                               <when test="starts-with($source, '¶')"/>
+                               <otherwise>
+                                       <value-of select="$source"/>
+                               </otherwise>
+                       </choose>
+               </variable>
+               <variable name="maybe-langtag">
+                       <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
+                               <variable name="split-tag-fragment">
+                                       <call-template name="LesML:split">
+                                               <with-param name="source" select="substring($id-and-lang, 2, string-length($id-and-lang)-2)"/>
+                                               <with-param name="separator" select="'@'"/>
+                                       </call-template>
+                               </variable>
+                               <value-of select="exsl:node-set($split-tag-fragment)/*[last()]"/>
+                       </if>
+               </variable>
+               <variable name="langtag">
+                       <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
+                               <value-of select="$maybe-langtag"/>
+                       </if>
+               </variable>
+               <variable name="id">
+                       <choose>
+                               <when test="string($langtag)!=''">
+                                       <value-of select="substring($id-and-lang, 1, string-length($id-and-lang)-(string-length($langtag)+2))"/>
+                               </when>
+                               <otherwise>
+                                       <value-of select="$id-and-lang"/>
+                               </otherwise>
+                       </choose>
+               </variable>
+               <if test="string($id)!=''">
+                       <attribute name="id">
+                               <value-of select="$id"/>
+                       </attribute>
+               </if>
+               <if test="string($langtag)!=''">
+                       <attribute name="lang">
+                               <value-of select="$langtag"/>
+                       </attribute>
+                       <attribute name="xml:lang">
+                               <value-of select="$langtag"/>
+                       </attribute>
+               </if>
+               <value-of select="$restoftext"/>
        </template>
        <template name="LesML:parse">
                <param name="lines" select="/.."/>
@@ -217,9 +282,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
                <variable name="doclines" select="exslset:leading($noshebang, $docsep)"/>
                <if test="starts-with($first-line, '##') and $first-line!='##'">
-                       <comment>
-                               <value-of select="substring-after($first-line, '##')"/>
-                       </comment>
+                       <call-template name="LesML:comment-out">
+                               <with-param name="source" select="substring-after($first-line, '##')"/>
+                       </call-template>
                </if>
                <if test="$doclines[normalize-space()!='']">
                        <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
@@ -295,9 +360,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </element>
                                                        </if>
                                                        <if test=".!='%%'">
-                                                               <comment>
-                                                                       <value-of select="substring-after(., '%%')"/>
-                                                               </comment>
+                                                               <call-template name="LesML:comment-out">
+                                                                       <with-param name="source" select="substring-after(., '%%')"/>
+                                                               </call-template>
                                                        </if>
                                                </for-each>
                                        </element>
@@ -597,9 +662,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </element>
                                                        </when>
                                                        <when test="starts-with($text, '#') and &sigiled-text;">
-                                                               <comment>
-                                                                       <value-of select="&unsigiled-text;"/>
-                                                               </comment>
+                                                               <call-template name="LesML:comment-out">
+                                                                       <with-param name="source" select="&unsigiled-text;"/>
+                                                               </call-template>
                                                        </when>
                                                        <otherwise>
                                                                <element name="p" namespace="&xhtml;">
@@ -799,12 +864,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </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, '⌫')"/>
@@ -818,22 +877,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                <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>
+                                                               <call-template name="LesML:comment-out">
+                                                                       <with-param name="source" select="string($comment)"/>
+                                                               </call-template>
                                                                <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
                                                        </copy>
                                                </when>
@@ -855,9 +901,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                        <for-each select="exsl:node-set($split-fragment)/node()">
                                                <value-of select="."/>
                                                <if test="position()!=last()">
-                                                       <comment>
-                                                               <text>&#x034F;</text>
-                                                       </comment>
+                                                       <call-template name="LesML:comment-out"/>
                                                </if>
                                        </for-each>
                                </when>
@@ -875,7 +919,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                <param name="end-sigil"/>
                <param name="class"/>
                <param name="role"/>
-               <param name="langtag-supported" select="false()"/>
                <choose>
                        <when test="self::*">
                                <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
@@ -887,17 +930,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                        <value-of select="substring-before($end-node, $end-sigil)"/>
                                                </variable>
                                                <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
-                                               <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
-                                               <variable name="maybe-langtag">
-                                                       <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
-                                                               <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
-                                                       </if>
-                                               </variable>
-                                               <variable name="langtag">
-                                                       <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
-                                                               <value-of select="$maybe-langtag"/>
-                                                       </if>
-                                               </variable>
                                                <variable name="start-tokens-fragment">
                                                        <call-template name="LesML:split">
                                                                <with-param name="source" select="string($start-node)"/>
@@ -926,27 +958,10 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                                        <value-of select="$class"/>
                                                                                </attribute>
                                                                        </if>
-                                                                       <if test="string($langtag)!=''">
-                                                                               <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
-                                                                                       <attribute name="lang">
-                                                                                               <value-of select="$langtag"/>
-                                                                                       </attribute>
-                                                                               </if>
-                                                                               <attribute name="xml:lang">
-                                                                                       <value-of select="$langtag"/>
-                                                                               </attribute>
-                                                                       </if>
                                                                        <value-of select="$start-tokens[last()]"/>
                                                                        <copy-of select="$start-node/following-sibling::node()"/>
                                                                </element>
-                                                               <choose>
-                                                                       <when test="string($langtag)!=''">
-                                                                               <value-of select="substring-after($restoftext, '$')"/>
-                                                                       </when>
-                                                                       <otherwise>
-                                                                               <value-of select="$restoftext"/>
-                                                                       </otherwise>
-                                                               </choose>
+                                                               <value-of select="substring-after($end-node, $end-sigil)"/>
                                                                <copy-of select="$end-node/following-sibling::node()"/>
                                                        </copy>
                                                </variable>
@@ -956,7 +971,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                        <with-param name="start-sigil" select="$start-sigil"/>
                                                        <with-param name="end-sigil" select="$end-sigil"/>
                                                        <with-param name="role" select="$role"/>
-                                                       <with-param name="langtag-supported" select="$langtag-supported"/>
                                                </apply-templates>
                                        </when>
                                        <otherwise>
@@ -968,7 +982,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                <with-param name="start-sigil" select="$start-sigil"/>
                                                                <with-param name="end-sigil" select="$end-sigil"/>
                                                                <with-param name="role" select="$role"/>
-                                                               <with-param name="langtag-supported" select="$langtag-supported"/>
                                                        </apply-templates>
                                                </copy>
                                        </otherwise>
@@ -1330,7 +1343,6 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="element-namespace" select="'&xhtml;'"/>
                                <with-param name="start-sigil" select="'⟨'"/>
                                <with-param name="end-sigil" select="'⟩'"/>
-                               <with-param name="langtag-supported" select="true()"/>
                        </apply-templates>
                </variable>
                <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
This page took 0.041498 seconds and 4 git commands to generate.