]> Lady’s Gitweb - LesML/commitdiff
Support inline comments
authorLady <redacted>
Sun, 27 Apr 2025 04:26:14 +0000 (00:26 -0400)
committerLady <redacted>
Sun, 27 Apr 2025 04:28:08 +0000 (00:28 -0400)
Comments work different from other inlines and have their own
processing rules. “Empty” comments are useful primarily to break up
spans of text into discrete text nodes.

README.markdown
parser.xslt

index 6c972944045260665bf39c07dd03b97ed9163ff2..327f253c5d3c63fdb24c0c14ba3e1607a4d43b1e 100644 (file)
@@ -188,6 +188,11 @@ The remaining characters in a paragraph form its contents.
 Markup within paragraphs is delimited with·out exception by pairs of
   characters, with the following precedence :⁠—
 
+- The characters `⌦` and `⌫` indicate inline comments.
+  A single character `⌧` may be used to indicate an “empty” comment
+    (consisting of `U+034F COMBINING GRAPHEME JOINER` for X·M·L
+    compatibility).
+
 - The characters `{🔗` and `>}` indicate a hyperlink to a U·R·L
     (`<html:a>`).
   The hyperlink must contain at least one `<`; the content before the
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">
-                       <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>
@@ -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>
+       <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'"/>
This page took 0.214749 seconds and 4 git commands to generate.