]> Lady’s Gitweb - LesML/commitdiff
Support inline comments
authorLady <redacted>
Sun, 27 Apr 2025 04:26:14 +0000 (00:26 -0400)
committerLady <redacted>
Tue, 31 Mar 2026 02:05:22 +0000 (22:05 -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 6b117a5a81d6581e450787b748c4dc7ce892479c6aae8b30ad44a49b91a3c78a..4c69cdce981e185b8732ef6894d9f1304abbbbcc447b8ad4fafdbf8a0bbb5cfb 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 6d58e5e0e4103e4cc8583f37e64688522041966c2d5e71c0c1df37ac3ef6bff8..0221e4cfe59419f10491c83a2c180e6baf3423ea2dbde071b39d95ca5889f5f5 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.374933 seconds and 4 git commands to generate.