]> Lady’s Gitweb - LesML/blobdiff - parser.xslt
Support preformatted text
[LesML] / parser.xslt
index d11dfe6ebfb263129928ec028ef274cf6875044e..fbfa6241bb654b233b22e0f1fd0a5e1f4bd0adc3 100644 (file)
@@ -48,6 +48,24 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </otherwise>
                </choose>
        </template>
                        </otherwise>
                </choose>
        </template>
+       <template name="LesML:break-and-unescape">
+               <param name="source"/>
+               <variable name="broken-fragment">
+                       <call-template name="LesML:split">
+                               <with-param name="source" select="$source"/>
+                               <with-param name="separator" select="'&#xA;'"/>
+                       </call-template>
+               </variable>
+               <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
+               <for-each select="$broken">
+                       <call-template name="LesML:unescape">
+                               <with-param name="source" select="string()"/>
+                       </call-template>
+                       <if test="position()!=count($broken)">
+                               <html:br/>
+                       </if>
+               </for-each>
+       </template>
        <template name="LesML:unescape">
                <param name="source"/>
                <choose>
        <template name="LesML:unescape">
                <param name="source"/>
                <choose>
@@ -105,9 +123,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        <when test="starts-with($source, '¶')">
                                <choose>
                                        <when test="contains($source, ' ')">
                        <when test="starts-with($source, '¶')">
                                <choose>
                                        <when test="contains($source, ' ')">
-                                               <attribute name="id">
-                                                       <value-of select="substring-before(substring-after($source, '¶'), ' ')"/>
-                                               </attribute>
+                                               <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, ' ')"/>
                                        </when>
                                        <otherwise>
                                                <value-of select="substring-after($source, ' ')"/>
                                        </when>
                                        <otherwise>
@@ -297,17 +318,39 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <variable name="prev-last" select="$last-lines[($position)-1]"/>
                                <variable name="linespans" select="$lines[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-last) or preceding-sibling::*[generate-id()=generate-id($prev-last)]) and normalize-space()!='']|."/>
                                <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '&#x9;'))])"/>
                                <variable name="prev-last" select="$last-lines[($position)-1]"/>
                                <variable name="linespans" select="$lines[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-last) or preceding-sibling::*[generate-id()=generate-id($prev-last)]) and normalize-space()!='']|."/>
                                <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '&#x9;'))])"/>
+                               <variable name="preformatted" select="not($linespans[not(starts-with(normalize-space(), '|'))])"/>
                                <variable name="text">
                                        <for-each select="$linespans">
                                <variable name="text">
                                        <for-each select="$linespans">
-                                               <value-of select="normalize-space()"/>
+                                               <choose>
+                                                       <when test="$preformatted">
+                                                               <value-of select="substring-after(., '|')"/>
+                                                       </when>
+                                                       <otherwise>
+                                                               <value-of select="normalize-space()"/>
+                                                       </otherwise>
+                                               </choose>
                                                <if test="position()!=count($linespans)">
                                                <if test="position()!=count($linespans)">
-                                                       <text> </text>
+                                                       <choose>
+                                                               <when test="$preformatted">
+                                                                       <text>&#xA;</text>
+                                                               </when>
+                                                               <otherwise>
+                                                                       <text> </text>
+                                                               </otherwise>
+                                                       </choose>
                                                </if>
                                        </for-each>
                                </variable>
                                <if test="string($text)!=''">
                                        <variable name="par">
                                                <choose>
                                                </if>
                                        </for-each>
                                </variable>
                                <if test="string($text)!=''">
                                        <variable name="par">
                                                <choose>
+                                                       <when test="$preformatted">
+                                                               <html:pre>
+                                                                       <call-template name="LesML:id-and-contents">
+                                                                               <with-param name="source" select="$text"/>
+                                                                       </call-template>
+                                                               </html:pre>
+                                                       </when>
                                                        <when test="starts-with($text, '⁌') and &sigiled-text;">
                                                                <html:h1>
                                                                        <call-template name="LesML:id-and-contents">
                                                        <when test="starts-with($text, '⁌') and &sigiled-text;">
                                                                <html:h1>
                                                                        <call-template name="LesML:id-and-contents">
@@ -517,7 +560,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                </copy>
        </template>
        <template match="text()" mode="LesML:finalize-tree">
                </copy>
        </template>
        <template match="text()" mode="LesML:finalize-tree">
-               <call-template name="LesML:unescape">
+               <call-template name="LesML:break-and-unescape">
                        <with-param name="source" select="string(.)"/>
                </call-template>
        </template>
                        <with-param name="source" select="string(.)"/>
                </call-template>
        </template>
This page took 0.026068 seconds and 4 git commands to generate.