]> Lady’s Gitweb - LesML/commitdiff
Support preformatted text
authorLady <redacted>
Sat, 14 Dec 2024 02:09:02 +0000 (21:09 -0500)
committerLady <redacted>
Tue, 31 Mar 2026 02:02:07 +0000 (22:02 -0400)
README.markdown
parser.xslt

index 9679683035bb010084193643a71f209a497fdc3b5f8570217b03ebe3ab09d594..160c8c3726301bdd8323c64ca2afdbafbbb6216e6cb041814f1680f01132671e 100644 (file)
@@ -103,12 +103,19 @@ Non·empty paragraphs are classified as follows :⁠—
   There is only one level of paragraph quoting; quoted paragraphs may
     not be quoted again.
 
   There is only one level of paragraph quoting; quoted paragraphs may
     not be quoted again.
 
+- If every line in the paragraph begins with zero or more white·space
+    characters followed by `|`, it is a “preformatted” paragraph and
+    white·space is not collapsed (`<html:pre>`).
+  A paragraph may be both quoted and preformatted.
+
 - Otherwise, the paragraph is unquoted.
 
 After this classification, each quoted or unquoted paragraph is further
   classified by type based on its first character (which is must be
    followed by white·space, or else the only thing on the line) :⁠—
 
 - Otherwise, the paragraph is unquoted.
 
 After this classification, each quoted or unquoted paragraph is further
   classified by type based on its first character (which is must be
    followed by white·space, or else the only thing on the line) :⁠—
 
+- If the paragraph is preformatted, it is an ordinary paragraph.
+
 - If the paragraph begins with `⁌`, it is a chapter heading
     (`<html:h1>`).
 
 - If the paragraph begins with `⁌`, it is a chapter heading
     (`<html:h1>`).
 
@@ -231,6 +238,8 @@ Once the tree is built as above, it is remediated into its final form
 - Successive list items of the same level and class are joined into
     a single list.
 
 - Successive list items of the same level and class are joined into
     a single list.
 
+- Linebreaks in preformatted paragraphs are replaced with `<html:br>`.
+
 Finally, any character can be escaped by instead providing its Unicode
   codepoint in the form `<U+NNNN>`, where `NNNN` is one or more
   hexadecimal digits.
 Finally, any character can be escaped by instead providing its Unicode
   codepoint in the form `<U+NNNN>`, where `NNNN` is one or more
   hexadecimal digits.
index 845c3ba8455ad5a4a710258f79e1b04d2523202b9f150f854f88fb8e237547d0..867745222932b0e5114cb099ea2688917b831d3c05024fb22251938617fcfc86 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>
@@ -300,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">
@@ -520,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.231728 seconds and 4 git commands to generate.