]> Lady’s Gitweb - LesML/blobdiff - parser.xslt
Drop langtags on offset text but support on paras
[LesML] / parser.xslt
index f6b38231a9d7d7f0aac4e5739595ed2342fb3aa1..8f80c393e9ffefabfb2ee42991439ee830e9d6e6 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
@@ -123,29 +123,69 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
        </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="/.."/>
@@ -875,7 +915,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 +926,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 +954,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 +967,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 +978,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 +1339,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.059878 seconds and 4 git commands to generate.