+<?xml version="1.0"?>
+<!--
+SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
+SPDX-License-Identifier: MPL-2.0
+-->
+<!--
+⁌ 💄📝 Les·M·L ∷ parser.xslt
+
+© 2024 Lady [@ Lady’s Computer]
+
+This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
+If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
+-->
+<transform
+ xmlns="http://www.w3.org/1999/XSL/Transform"
+ xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:exslstr="http://exslt.org/strings"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
+ exclude-result-prefixes="LesML"
+ extension-element-prefixes="exsl exslstr"
+ version="1.0"
+>
+ <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
+ <template name="LesML:split">
+ <param name="source"/>
+ <param name="separator" select="'
'"/>
+ <choose>
+ <when test="contains($source, $separator)">
+ <html:span>
+ <value-of select="substring-before($source, $separator)"/>
+ </html:span>
+ <call-template name="LesML:split">
+ <with-param name="source" select="substring-after($source, $separator)"/>
+ <with-param name="separator" select="$separator"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <html:span>
+ <value-of select="$source"/>
+ </html:span>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="LesML:unescape">
+ <param name="source"/>
+ <choose>
+ <when test="contains($source, '<U+')">
+ <variable name="after" select="substring-after($source, '<U+')"/>
+ <choose>
+ <when test="contains($after, '>')">
+ <variable name="inner" select="substring-before($after, '>')"/>
+ <variable name="components">
+ <call-template name="LesML:split">
+ <with-param name="source" select="$inner"/>
+ <with-param name="separator" select="'.'"/>
+ </call-template>
+ </variable>
+ <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
+ <choose>
+ <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
+ <value-of select="substring-before($source, '<U+')"/>
+ <text><U+</text>
+ <value-of select="$inner"/>
+ <text>></text>
+ <call-template name="LesML:unescape">
+ <with-param name="source" select="substring-after($after, '>')"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <for-each select="$component-nodes">
+ <text disable-output-escaping="yes">&#x</text>
+ <value-of select="."/>
+ <text>;</text>
+ </for-each>
+ <call-template name="LesML:unescape">
+ <with-param name="source" select="substring-after($after, '>')"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </when>
+ <otherwise>
+ <value-of select="substring-before($source, '<U+')"/>
+ <text><U+</text>
+ <call-template name="LesML:unescape">
+ <with-param name="source" select="$after"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </when>
+ <otherwise>
+ <value-of select="$source"/>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="LesML:id-and-contents">
+ <param name="source"/>
+ <choose>
+ <when test="starts-with($source, '¶')">
+ <choose>
+ <when test="contains($source, ' ')">
+ <attribute name="id">
+ <value-of select="substring-before(substring-after($source, '¶'), ' ')"/>
+ </attribute>
+ <value-of select="substring-after($source, ' ')"/>
+ </when>
+ <otherwise>
+ <attribute name="id">
+ <value-of select="substring-after($source, '¶')"/>
+ </attribute>
+ </otherwise>
+ </choose>
+ </when>
+ <otherwise>
+ <value-of select="$source"/>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="LesML:parse">
+ <param name="source"/>
+ <variable name="noshebang">
+ <text>
</text>
+ <choose>
+ <when test="starts-with($source, '#!')">
+ <value-of select="substring-after($source, '
')"/>
+ </when>
+ <otherwise>
+ <value-of select="$source"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <variable name="records">
+ <call-template name="LesML:split">
+ <with-param name="source" select="$noshebang"/>
+ <with-param name="separator" select="'
%%'"/>
+ </call-template>
+ </variable>
+ <variable name="record-nodes" select="exsl:node-set($records)/*"/>
+ <html:article>
+ <if test="count($record-nodes)>1">
+ <html:footer class="head">
+ <for-each select="$record-nodes[not(position()=last() or normalize-space(.)='')]">
+ <variable name="fields" select="exslstr:tokenize(., '
')"/>
+ <html:dl>
+ <for-each select="$fields">
+ <choose>
+ <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
+ <otherwise>
+ <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
+ <html:div>
+ <html:dt>
+ <value-of select="normalize-space(substring-before(., ':'))"/>
+ </html:dt>
+ <html:dd>
+ <variable name="firstline">
+ <choose>
+ <when test="contains(., ':')">
+ <value-of select="normalize-space(substring-after(., ':'))"/>
+ </when>
+ <otherwise>
+ <value-of select="normalize-space(.)"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <choose>
+ <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+ <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
+ </when>
+ <otherwise>
+ <value-of select="$firstline"/>
+ </otherwise>
+ </choose>
+ <for-each select="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
+ <variable name="nextline" select="normalize-space(.)"/>
+ <choose>
+ <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
+ <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
+ </when>
+ <otherwise>
+ <value-of select="$nextline"/>
+ </otherwise>
+ </choose>
+ </for-each>
+ </html:dd>
+ </html:div>
+ </otherwise>
+ </choose>
+ </for-each>
+ </html:dl>
+ </for-each>
+ </html:footer>
+ </if>
+ <html:div class="body">
+ <call-template name="LesML:paragraphize">
+ <with-param name="source" select="string($record-nodes[last()])"/>
+ </call-template>
+ </html:div>
+ </html:article>
+ </template>
+ <template name="LesML:paragraphize">
+ <param name="source"/>
+ <variable name="paragraphs">
+ <call-template name="LesML:split">
+ <with-param name="source" select="$source"/>
+ <with-param name="separator" select="'

'"/>
+ </call-template>
+ </variable>
+ <variable name="blocked">
+ <for-each select="exsl:node-set($paragraphs)/*">
+ <variable name="lines">
+ <call-template name="LesML:split">
+ <with-param name="source" select="string()"/>
+ </call-template>
+ </variable>
+ <variable name="linespans" select="exsl:node-set($lines)/*"/>
+ <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '	'))])"/>
+ <variable name="text">
+ <for-each select="$linespans">
+ <if test="normalize-space()!=''">
+ <value-of select="normalize-space()"/>
+ <if test="following-sibling::*[normalize-space()!='']">
+ <text> </text>
+ </if>
+ </if>
+ </for-each>
+ </variable>
+ <if test="string($text)!=''">
+ <variable name="par">
+ <choose>
+ <when test="starts-with($text, '⁌ ')">
+ <html:h1>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '⁌ ')"/>
+ </call-template>
+ </html:h1>
+ </when>
+ <when test="starts-with($text, '§ ')">
+ <html:h2>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '§ ')"/>
+ </call-template>
+ </html:h2>
+ </when>
+ <when test="starts-with($text, '✠ ')">
+ <html:h3>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '✠ ')"/>
+ </call-template>
+ </html:h3>
+ </when>
+ <when test="starts-with($text, '❦ ')">
+ <html:h4>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '❦ ')"/>
+ </call-template>
+ </html:h4>
+ </when>
+ <when test="starts-with($text, '• ')">
+ <html:li class="unordered" data-level="1">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '• ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '🔢 ')">
+ <html:li class="ordered" data-level="1">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '🔢 ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '◦ ')">
+ <html:li class="unordered" data-level="2">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '◦ ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '🔠 ')">
+ <html:li class="ordered" data-level="2">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '🔠 ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '‣ ')">
+ <html:li class="unordered" data-level="3">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '‣ ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '🔡 ')">
+ <html:li class="ordered" data-level="3">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '🔡 ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '⁃ ')">
+ <html:li class="unordered" data-level="4">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '⁃ ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '🔣 ')">
+ <html:li class="ordered" data-level="4">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '🔣 ')"/>
+ </call-template>
+ </html:p>
+ </html:li>
+ </when>
+ <when test="starts-with($text, '🛈 ')">
+ <html:div role="note" class="info">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '🛈 ')"/>
+ </call-template>
+ </html:p>
+ </html:div>
+ </when>
+ <when test="starts-with($text, '⯑ ')">
+ <html:div role="note" class="query">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '⯑ ')"/>
+ </call-template>
+ </html:p>
+ </html:div>
+ </when>
+ <when test="starts-with($text, '⚠︎ ')">
+ <html:div role="note" class="warn">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '⚠︎ ')"/>
+ </call-template>
+ </html:p>
+ </html:div>
+ </when>
+ <when test="starts-with($text, '※ ')">
+ <html:div role="note" class="note">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '※ ')"/>
+ </call-template>
+ </html:p>
+ </html:div>
+ </when>
+ <when test="starts-with($text, '☡ ')">
+ <html:div role="note" class="caution">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '☡ ')"/>
+ </call-template>
+ </html:p>
+ </html:div>
+ </when>
+ <when test="starts-with($text, '⋯ ')">
+ <html:div class="continuation">
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="substring-after($text, '⋯ ')"/>
+ </call-template>
+ </html:p>
+ </html:div>
+ </when>
+ <otherwise>
+ <html:p>
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="$text"/>
+ </call-template>
+ </html:p>
+ </otherwise>
+ </choose>
+ </variable>
+ <choose>
+ <when test="translate(string($text), '#*-=_~⁂─━┄┅┈┉╌╍═╴╶╸╺☙❧ ', '')=''">
+ <html:hr/>
+ </when>
+ <when test="$quoted">
+ <html:blockquote>
+ <copy-of select="$par"/>
+ </html:blockquote>
+ </when>
+ <otherwise>
+ <copy-of select="$par"/>
+ </otherwise>
+ </choose>
+ </if>
+ </for-each>
+ </variable>
+ <variable name="inlined">
+ <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
+ </variable>
+ <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
+ </template>
+ <template match="html:script[@type='text/lesml']">
+ <variable name="source">
+ <for-each select=".//text()">
+ <value-of select="."/>
+ </for-each>
+ </variable>
+ <call-template name="LesML:parse">
+ <with-param name="source" select="string($source)"/>
+ </call-template>
+ </template>
+ <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ </copy>
+ </template>
+ <template match="text()" mode="LesML:finalize-tree">
+ <call-template name="LesML:unescape">
+ <with-param name="source" select="string(.)"/>
+ </call-template>
+ </template>
+ <template match="html:blockquote" mode="LesML:finalize-tree">
+ <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
+ <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
+ <variable name="contents">
+ <copy-of select="node()"/>
+ <for-each select="following-sibling::node()[not($notquote) or following-sibling::node()[generate-id()=generate-id($notquote)]]">
+ <copy-of select="node()"/>
+ </for-each>
+ </variable>
+ <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
+ <variable name="laststarttext" select="$content-nodes[last()]/self::html:p[not(@class) and not(@role)]/node()[self::text() or self::*][position()=1 and self::text()]"/>
+ <choose>
+ <when test="starts-with($laststarttext, '— ')">
+ <variable name="caption">
+ <copy-of select="$laststarttext/preceding-sibling::node()"/>
+ <value-of select="substring-after($laststarttext, '— ')"/>
+ <copy-of select="$laststarttext/following-sibling::node()"/>
+ </variable>
+ <html:figure>
+ <copy>
+ <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
+ </copy>
+ <html:figcaption>
+ <for-each select="$content-nodes[last()]">
+ <copy>
+ <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
+ </copy>
+ </for-each>
+ </html:figcaption>
+ </html:figure>
+ </when>
+ <otherwise>
+ <copy>
+ <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
+ </copy>
+ </otherwise>
+ </choose>
+ </if>
+ </template>
+ <template match="html:div" mode="LesML:finalize-tree">
+ <if test="not(@class='continuation') or not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:div or self::html:li)]">
+ <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </for-each>
+ </copy>
+ </if>
+ </template>
+ <template match="html:li" mode="LesML:finalize-tree">
+ <if test="not(preceding-sibling::node()) or preceding-sibling::node()[not(preceding-sibling::* and self::html:div and @class='continuation')][position()=1 and not(self::html:li)]">
+ <apply-templates select="." mode="LesML:finalize-list"/>
+ </if>
+ </template>
+ <template match="html:li" mode="LesML:finalize-list">
+ <param name="parent-level" select="0"/>
+ <variable name="current-class" select="string(@class)"/>
+ <variable name="current-level" select="number(@data-level)"/>
+ <variable name="wrapper">
+ <choose>
+ <when test="@class='ordered'">
+ <text>ol</text>
+ </when>
+ <otherwise>
+ <text>ul</text>
+ </otherwise>
+ </choose>
+ </variable>
+ <variable name="notinlist" select="following-sibling::node()[not(self::html:div and @class='continuation' or self::html:li and (@data-level>$current-level or @data-level=$current-level and @class=$current-class))][1]"/>
+ <element name="html:{$wrapper}" namespace="http://www.w3.org/1999/xhtml">
+ <for-each select=".|following-sibling::html:li[@data-level=$current-level and (not($notinlist) or following-sibling::node()[generate-id()=generate-id($notinlist)])]">
+ <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </for-each>
+ <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
+ <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
+ <with-param name="parent-level" select="$current-level"/>
+ </apply-templates>
+ </if>
+ </copy>
+ </for-each>
+ </element>
+ <if test="$notinlist/self::html:li[@data-level>$parent-level]">
+ <apply-templates select="$notinlist" mode="LesML:finalize-list">
+ <with-param name="parent-level" select="$parent-level"/>
+ </apply-templates>
+ </if>
+ </template>
+ <template match="node()" mode="LesML:inline">
+ <param name="element-name"/>
+ <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
+ <param name="start-sigil"/>
+ <param name="end-sigil"/>
+ <param name="role"/>
+ <param name="langtag-supported" select="false()"/>
+ <choose>
+ <when test="self::*">
+ <copy>
+ <copy-of select="@*"/>
+ <variable name="start-node" select="text()[contains(., $start-sigil)][1]"/>
+ <choose>
+ <when test="$start-node">
+ <variable name="remaining">
+ <value-of select="substring-after($start-node, $start-sigil)"/>
+ <copy-of select="$start-node/following-sibling::node()"/>
+ </variable>
+ <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., $end-sigil)][1]"/>
+ <choose>
+ <when test="$end-node">
+ <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="rest">
+ <html:div>
+ <choose>
+ <when test="string($langtag)!=''">
+ <value-of select="substring-after($restoftext, '$')"/>
+ </when>
+ <otherwise>
+ <value-of select="$restoftext"/>
+ </otherwise>
+ </choose>
+ <copy-of select="$end-node/following-sibling::node()"/>
+ </html:div>
+ </variable>
+ <variable name="processed-rest">
+ <apply-templates select="exsl:node-set($rest)/*" mode="LesML:inline">
+ <with-param name="element-name" select="$element-name"/>
+ <with-param name="element-namespace" select="$element-namespace"/>
+ <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>
+ </variable>
+ <copy-of select="$start-node/preceding-sibling::node()"/>
+ <value-of select="substring-before($start-node, $start-sigil)"/>
+ <element name="{$element-name}" namespace="{$element-namespace}">
+ <if test="string($role)!=''">
+ <attribute name="role">
+ <value-of select="$role"/>
+ </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>
+ <copy-of select="$end-node/preceding-sibling::node()"/>
+ <value-of select="substring-before($end-node, $end-sigil)"/>
+ </element>
+ <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
+ </when>
+ <otherwise>
+ <apply-templates select="node()" mode="LesML:inline">
+ <with-param name="element-name" select="$element-name"/>
+ <with-param name="element-namespace" select="$element-namespace"/>
+ <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>
+ </otherwise>
+ </choose>
+ </when>
+ <otherwise>
+ <apply-templates select="node()" mode="LesML:inline">
+ <with-param name="element-name" select="$element-name"/>
+ <with-param name="element-namespace" select="$element-namespace"/>
+ <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>
+ </otherwise>
+ </choose>
+ </copy>
+ </when>
+ <otherwise>
+ <copy-of select="."/>
+ </otherwise>
+ </choose>
+ </template>
+ <template match="node()" mode="LesML:linkify">
+ <variable name="result">
+ <choose>
+ <when test="self::*">
+ <copy>
+ <copy-of select="@*"/>
+ <variable name="start-node" select="text()[contains(., '{🔗')][1]"/>
+ <choose>
+ <when test="$start-node">
+ <variable name="remaining">
+ <value-of select="substring-after($start-node, '{🔗')"/>
+ <copy-of select="$start-node/following-sibling::node()"/>
+ </variable>
+ <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., '>}') and not(preceding-sibling::*)][1]"/>
+ <variable name="hyperlink">
+ <for-each select="$end-node/preceding-sibling::node()">
+ <value-of select="."/>
+ </for-each>
+ <value-of select="substring-before($end-node, '>}')"/>
+ </variable>
+ <choose>
+ <when test="contains($hyperlink, '<')">
+ <variable name="ltcomponents">
+ <call-template name="LesML:split">
+ <with-param name="source" select="$hyperlink"/>
+ <with-param name="separator" select="'<'"/>
+ </call-template>
+ </variable>
+ <variable name="ltcomponent-nodes" select="exsl:node-set($ltcomponents)/*"/>
+ <variable name="rest">
+ <html:div>
+ <value-of select="substring-after($end-node, '>}')"/>
+ <copy-of select="$end-node/following-sibling::node()"/>
+ </html:div>
+ </variable>
+ <variable name="processed-rest">
+ <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
+ </variable>
+ <copy-of select="$start-node/preceding-sibling::node()"/>
+ <value-of select="substring-before($start-node, '{🔗')"/>
+ <html:a href="{$ltcomponent-nodes[last()]}">
+ <choose>
+ <when test="count($ltcomponent-nodes)>2 or normalize-space($ltcomponent-nodes[1])!=''">
+ <value-of select="$ltcomponent-nodes[1]"/>
+ <for-each select="$ltcomponent-nodes[position()>1 and position()!=last()]">
+ <text><</text>
+ <value-of select="."/>
+ </for-each>
+ </when>
+ <otherwise>
+ <value-of select="$ltcomponent-nodes[last()]"/>
+ </otherwise>
+ </choose>
+ </html:a>
+ <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
+ </when>
+ <otherwise>
+ <variable name="rest">
+ <html:div>
+ <copy-of select="$remaining"/>
+ </html:div>
+ </variable>
+ <variable name="processed-rest">
+ <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
+ </variable>
+ <copy-of select="$start-node/preceding-sibling::node()"/>
+ <value-of select="substring-before($start-node, '{🔗')"/>
+ <text>{🔗</text>
+ <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
+ </otherwise>
+ </choose>
+ </when>
+ <otherwise>
+ <apply-templates select="node()" mode="LesML:linkify"/>
+ </otherwise>
+ </choose>
+ </copy>
+ </when>
+ <otherwise>
+ <copy-of select="."/>
+ </otherwise>
+ </choose>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
+ </template>
+ <template match="node()" mode="LesML:strikethrough">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:s'"/>
+ <with-param name="start-sigil" select="'⸠'"/>
+ <with-param name="end-sigil" select="'⸡'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
+ </template>
+ <template match="node()" mode="LesML:underline">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:u'"/>
+ <with-param name="start-sigil" select="'⸤'"/>
+ <with-param name="end-sigil" select="'⸥'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
+ </template>
+ <template match="node()" mode="LesML:noted">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:small'"/>
+ <with-param name="start-sigil" select="'⟦'"/>
+ <with-param name="end-sigil" select="'⟧'"/>
+ <with-param name="role" select="'note'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
+ </template>
+ <template match="node()" mode="LesML:parenthetical">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:small'"/>
+ <with-param name="start-sigil" select="'⸨'"/>
+ <with-param name="end-sigil" select="'⸩'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
+ </template>
+ <template match="node()" mode="LesML:important">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:strong'"/>
+ <with-param name="start-sigil" select="'☞'"/>
+ <with-param name="end-sigil" select="'☜'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
+ </template>
+ <template match="node()" mode="LesML:emphasized">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:em'"/>
+ <with-param name="start-sigil" select="'⹐'"/>
+ <with-param name="end-sigil" select="'⹑'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
+ </template>
+ <template match="node()" mode="LesML:titled">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:cite'"/>
+ <with-param name="start-sigil" select="'⟪'"/>
+ <with-param name="end-sigil" select="'⟫'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
+ </template>
+ <template match="node()" mode="LesML:offset">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:i'"/>
+ <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"/>
+ </template>
+ <template match="node()" mode="LesML:bolded">
+ <variable name="result">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:b'"/>
+ <with-param name="start-sigil" select="'⦃'"/>
+ <with-param name="end-sigil" select="'⦄'"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
+ </template>
+ <template match="node()" mode="LesML:code">
+ <apply-templates select="." mode="LesML:inline">
+ <with-param name="element-name" select="'html:code'"/>
+ <with-param name="start-sigil" select="'`'"/>
+ <with-param name="end-sigil" select="'´'"/>
+ </apply-templates>
+ </template>
+</transform>