3 SPDX-FileCopyrightText: 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ 💄📝 Les·M·L ∷ parser.xslt
9 © 2024–2025 Lady [@ Ladys Computer]
11 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
12 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/>.
15 <!ENTITY section-break "*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~">
16 <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ')">
17 <!ENTITY unsigiled-text "substring($text, 3, string-length($text)-2)">
18 <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
21 xmlns="http://www.w3.org/1999/XSL/Transform"
22 xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
23 xmlns:exsl="http://exslt.org/common"
24 xmlns:exslset="http://exslt.org/sets"
25 xmlns:exslstr="http://exslt.org/strings"
26 xmlns:html="http://www.w3.org/1999/xhtml"
27 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
28 exclude-result-prefixes="LesML"
29 extension-element-prefixes="exsl exslstr"
32 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
33 <template name="LesML:split">
34 <param name="source"/>
35 <param name="separator" select="'
'"/>
37 <when test="contains($source, $separator)">
39 <value-of select="substring-before($source, $separator)"/>
41 <call-template name="LesML:split">
42 <with-param name="source" select="substring-after($source, $separator)"/>
43 <with-param name="separator" select="$separator"/>
48 <value-of select="$source"/>
53 <template name="LesML:break-and-unescape">
54 <param name="source"/>
55 <variable name="broken-fragment">
56 <call-template name="LesML:split">
57 <with-param name="source" select="$source"/>
58 <with-param name="separator" select="'
'"/>
61 <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
62 <for-each select="$broken">
63 <call-template name="LesML:unescape">
64 <with-param name="source" select="string()"/>
66 <if test="position()!=count($broken)">
67 <element name="br" namespace="&xhtml;"/>
71 <template name="LesML:unescape">
72 <param name="source"/>
74 <when test="contains($source, '{U+')">
75 <variable name="after" select="substring-after($source, '{U+')"/>
77 <when test="contains($after, '}')">
78 <variable name="inner" select="substring-before($after, '}')"/>
79 <variable name="components">
80 <call-template name="LesML:split">
81 <with-param name="source" select="$inner"/>
82 <with-param name="separator" select="'.'"/>
85 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
86 <value-of select="substring-before($source, '{U+')"/>
88 <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
90 <value-of select="$inner"/>
92 <call-template name="LesML:unescape">
93 <with-param name="source" select="substring-after($after, '}')"/>
97 <for-each select="$component-nodes">
98 <text disable-output-escaping="yes">&#x</text>
99 <value-of select="."/>
102 <call-template name="LesML:unescape">
103 <with-param name="source" select="substring-after($after, '}')"/>
109 <value-of select="substring-before($source, '{U+')"/>
111 <call-template name="LesML:unescape">
112 <with-param name="source" select="$after"/>
118 <value-of select="$source"/>
122 <template name="LesML:id-and-contents">
123 <param name="source"/>
125 <when test="starts-with($source, '¶')">
127 <when test="contains($source, ' ')">
128 <variable name="id" select="substring-before(substring-after($source, '¶'), ' ')"/>
130 <attribute name="id">
131 <value-of select="$id"/>
134 <value-of select="substring-after($source, ' ')"/>
137 <attribute name="id">
138 <value-of select="substring-after($source, '¶')"/>
144 <value-of select="$source"/>
148 <template name="LesML:parse">
149 <param name="lines" select="/.."/>
150 <param name="parent-params" select="/.."/>
151 <variable name="first-line" select="$lines[1]"/>
152 <variable name="shebang">
153 <if test="starts-with($first-line, '#!lesml')">
154 <value-of select="$first-line"/>
157 <variable name="params-string">
159 <when test="starts-with($shebang, '#!lesml@')">
160 <value-of select="substring-after($shebang, '$')"/>
163 <value-of select="substring-after($shebang, '#!lesml')"/>
167 <variable name="params-fragment">
169 <when test="$shebang!=''">
171 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
177 <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
181 <for-each select="exslstr:tokenize($params-string)">
183 <when test="contains(., '=')">
186 <value-of select="substring-before(., '=')"/>
189 <value-of select="substring-after(., '=')"/>
196 <value-of select="."/>
205 <when test="$parent-params">
206 <copy-of select="$parent-params"/>
213 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
214 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
215 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
216 <variable name="doclines" select="exslset:leading($noshebang, $docsep)"/>
217 <if test="starts-with($first-line, '##') and $first-line!='##'">
219 <value-of select="substring-after($first-line, '##')"/>
222 <if test="$shebang!='' or $doclines[normalize-space()!='']">
223 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
224 <element name="article" namespace="&xhtml;">
225 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
226 <attribute name="lang">
227 <value-of select="following-sibling::html:dd"/>
229 <attribute name="xml:lang">
230 <value-of select="following-sibling::html:dd"/>
233 <for-each select="$params/html:div/html:dt[string()='profile']">
234 <attribute name="data-lesml-profile">
235 <value-of select="following-sibling::html:dd"/>
238 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
239 <element name="footer" namespace="&xhtml;">
240 <attribute name="class">
243 <for-each select="$record-separators">
244 <variable name="position" select="position()"/>
245 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
246 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)"/>
248 <element name="dl" namespace="&xhtml;">
249 <for-each select="$fields">
251 <when test="starts-with(., ' ') and exslset:leading($fields, .)"/>
253 <variable name="next" select="exslset:intersection(following-sibling::*[not(starts-with(., ' '))][1], $fields)"/>
254 <element name="div" namespace="&xhtml;">
255 <element name="dt" namespace="&xhtml;">
256 <value-of select="normalize-space(substring-before(., ':'))"/>
258 <element name="dd" namespace="&xhtml;">
259 <variable name="firstline">
261 <when test="contains(., ':')">
262 <value-of select="normalize-space(substring-after(., ':'))"/>
265 <value-of select="normalize-space(.)"/>
270 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
271 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
274 <value-of select="$firstline"/>
277 <for-each select="exslset:intersection(following-sibling::*[starts-with(., ' ')], exslset:leading($fields, $next))">
278 <variable name="nextline" select="normalize-space(.)"/>
280 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
281 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
284 <value-of select="$nextline"/>
297 <value-of select="substring-after(., '%%')"/>
303 <element name="div" namespace="&xhtml;">
304 <attribute name="class">
307 <call-template name="LesML:paragraphize">
308 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
314 <call-template name="LesML:parse">
315 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
316 <with-param name="parent-params" select="$params"/>
320 <template name="LesML:paragraphize">
321 <param name="lines" select="/.."/>
322 <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
323 <variable name="blocked">
324 <for-each select="$last-lines">
325 <variable name="position" select="position()"/>
326 <variable name="prev-last" select="$last-lines[($position)-1]"/>
327 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
328 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '	'))])"/>
329 <variable name="preformatted" select="not($linespans[not(starts-with(normalize-space(), '|'))])"/>
330 <variable name="text">
331 <for-each select="$linespans">
333 <when test="$preformatted">
334 <value-of select="substring-after(., '|')"/>
337 <value-of select="normalize-space()"/>
340 <if test="position()!=count($linespans)">
342 <when test="$preformatted">
352 <if test="string($text)!=''">
353 <variable name="par">
355 <when test="$preformatted">
356 <element name="pre" namespace="&xhtml;">
357 <call-template name="LesML:id-and-contents">
358 <with-param name="source" select="$text"/>
362 <when test="starts-with($text, '⁌') and &sigiled-text;">
363 <element name="h1" namespace="&xhtml;">
364 <call-template name="LesML:id-and-contents">
365 <with-param name="source" select="&unsigiled-text;"/>
369 <when test="starts-with($text, '§') and &sigiled-text;">
370 <element name="h2" namespace="&xhtml;">
371 <call-template name="LesML:id-and-contents">
372 <with-param name="source" select="&unsigiled-text;"/>
376 <when test="starts-with($text, '❦') and &sigiled-text;">
377 <element name="h3" namespace="&xhtml;">
378 <call-template name="LesML:id-and-contents">
379 <with-param name="source" select="&unsigiled-text;"/>
383 <when test="starts-with($text, '✠') and &sigiled-text;">
384 <element name="h4" namespace="&xhtml;">
385 <call-template name="LesML:id-and-contents">
386 <with-param name="source" select="&unsigiled-text;"/>
390 <when test="starts-with($text, '•') and &sigiled-text;">
391 <element name="li" namespace="&xhtml;">
392 <attribute name="class">
393 <text>unordered</text>
395 <attribute name="data-level">
398 <element name="p" namespace="&xhtml;">
399 <call-template name="LesML:id-and-contents">
400 <with-param name="source" select="&unsigiled-text;"/>
405 <when test="starts-with($text, '🔢') and &sigiled-text;">
406 <element name="li" namespace="&xhtml;">
407 <attribute name="class">
410 <attribute name="data-level">
413 <element name="p" namespace="&xhtml;">
414 <call-template name="LesML:id-and-contents">
415 <with-param name="source" select="&unsigiled-text;"/>
420 <when test="starts-with($text, '◦') and &sigiled-text;">
421 <element name="li" namespace="&xhtml;">
422 <attribute name="class">
423 <text>unordered</text>
425 <attribute name="data-level">
428 <element name="p" namespace="&xhtml;">
429 <call-template name="LesML:id-and-contents">
430 <with-param name="source" select="&unsigiled-text;"/>
435 <when test="starts-with($text, '🔠') and &sigiled-text;">
436 <element name="li" namespace="&xhtml;">
437 <attribute name="class">
440 <attribute name="data-level">
443 <element name="p" namespace="&xhtml;">
444 <call-template name="LesML:id-and-contents">
445 <with-param name="source" select="&unsigiled-text;"/>
450 <when test="starts-with($text, '▪') and &sigiled-text;">
451 <element name="li" namespace="&xhtml;">
452 <attribute name="class">
453 <text>unordered</text>
455 <attribute name="data-level">
458 <element name="p" namespace="&xhtml;">
459 <call-template name="LesML:id-and-contents">
460 <with-param name="source" select="&unsigiled-text;"/>
465 <when test="starts-with($text, '🔡') and &sigiled-text;">
466 <element name="li" namespace="&xhtml;">
467 <attribute name="class">
470 <attribute name="data-level">
473 <element name="p" namespace="&xhtml;">
474 <call-template name="LesML:id-and-contents">
475 <with-param name="source" select="&unsigiled-text;"/>
480 <when test="starts-with($text, '⁃') and &sigiled-text;">
481 <element name="li" namespace="&xhtml;">
482 <attribute name="class">
483 <text>unordered</text>
485 <attribute name="data-level">
488 <element name="p" namespace="&xhtml;">
489 <call-template name="LesML:id-and-contents">
490 <with-param name="source" select="&unsigiled-text;"/>
495 <when test="starts-with($text, '🔣') and &sigiled-text;">
496 <element name="li" namespace="&xhtml;">
497 <attribute name="class">
500 <attribute name="data-level">
503 <element name="p" namespace="&xhtml;">
504 <call-template name="LesML:id-and-contents">
505 <with-param name="source" select="&unsigiled-text;"/>
510 <when test="starts-with($text, '🛈') and &sigiled-text;">
511 <element name="div" namespace="&xhtml;">
512 <attribute name="role">
515 <attribute name="class">
518 <element name="p" namespace="&xhtml;">
519 <call-template name="LesML:id-and-contents">
520 <with-param name="source" select="&unsigiled-text;"/>
525 <when test="starts-with($text, '⯑') and &sigiled-text;">
526 <element name="div" namespace="&xhtml;">
527 <attribute name="role">
530 <attribute name="class">
533 <element name="p" namespace="&xhtml;">
534 <call-template name="LesML:id-and-contents">
535 <with-param name="source" select="&unsigiled-text;"/>
540 <when test="starts-with($text, '⚠︎') and &sigiled-text;">
541 <element name="div" namespace="&xhtml;">
542 <attribute name="role">
545 <attribute name="class">
548 <element name="p" namespace="&xhtml;">
549 <call-template name="LesML:id-and-contents">
550 <with-param name="source" select="&unsigiled-text;"/>
555 <when test="starts-with($text, '※') and &sigiled-text;">
556 <element name="div" namespace="&xhtml;">
557 <attribute name="role">
560 <attribute name="class">
563 <element name="p" namespace="&xhtml;">
564 <call-template name="LesML:id-and-contents">
565 <with-param name="source" select="&unsigiled-text;"/>
570 <when test="starts-with($text, '☡') and &sigiled-text;">
571 <element name="div" namespace="&xhtml;">
572 <attribute name="role">
575 <attribute name="class">
578 <element name="p" namespace="&xhtml;">
579 <call-template name="LesML:id-and-contents">
580 <with-param name="source" select="&unsigiled-text;"/>
585 <when test="starts-with($text, '⋯') and &sigiled-text;">
586 <element name="div" namespace="&xhtml;">
587 <attribute name="class">
588 <text>continuation</text>
590 <element name="p" namespace="&xhtml;">
591 <call-template name="LesML:id-and-contents">
592 <with-param name="source" select="&unsigiled-text;"/>
597 <when test="starts-with($text, '#') and &sigiled-text;">
599 <value-of select="&unsigiled-text;"/>
603 <element name="p" namespace="&xhtml;">
604 <call-template name="LesML:id-and-contents">
605 <with-param name="source" select="$text"/>
612 <when test="translate(string($text), '§ion-break; ', '')=''">
613 <element name="hr" namespace="&xhtml;"/>
615 <when test="$quoted">
616 <element name="blockquote" namespace="&xhtml;">
617 <copy-of select="$par"/>
621 <copy-of select="$par"/>
627 <variable name="inlined">
628 <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
630 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
632 <template match="html:script[@type='text/lesml']">
633 <variable name="lines-fragment">
634 <call-template name="LesML:split">
635 <with-param name="source">
636 <for-each select=".//text()">
637 <value-of select="."/>
642 <call-template name="LesML:parse">
643 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
646 <template match="html:blockquote" mode="LesML:finalize-tree">
647 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
648 <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
649 <variable name="contents">
650 <copy-of select="node()"/>
651 <for-each select="exslset:leading(following-sibling::node(), $notquote)">
652 <copy-of select="node()"/>
655 <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
656 <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()]"/>
658 <when test="starts-with($laststarttext, '— ')">
659 <variable name="caption">
660 <copy-of select="$laststarttext/preceding-sibling::node()"/>
661 <value-of select="substring-after($laststarttext, '— ')"/>
662 <copy-of select="$laststarttext/following-sibling::node()"/>
664 <element name="figure" namespace="&xhtml;">
666 <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
668 <element name="figcaption" namespace="&xhtml;">
669 <for-each select="$content-nodes[last()]">
671 <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
679 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
685 <template match="html:div" mode="LesML:finalize-tree">
686 <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)]">
687 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
689 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
690 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
691 <apply-templates select="node()" mode="LesML:finalize-tree"/>
696 <template match="html:li" mode="LesML:finalize-tree">
697 <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)]">
698 <apply-templates select="." mode="LesML:finalize-list"/>
701 <template match="html:li" mode="LesML:finalize-list">
702 <param name="parent-level" select="0"/>
703 <variable name="current-class" select="string(@class)"/>
704 <variable name="current-level" select="number(@data-level)"/>
705 <variable name="wrapper">
707 <when test="@class='ordered'">
715 <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]"/>
716 <element name="{$wrapper}" namespace="&xhtml;">
717 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @data-level=$current-level]">
718 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
720 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
721 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
722 <apply-templates select="node()" mode="LesML:finalize-tree"/>
724 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
725 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
726 <with-param name="parent-level" select="$current-level"/>
732 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
733 <apply-templates select="$notinlist" mode="LesML:finalize-list">
734 <with-param name="parent-level" select="$parent-level"/>
738 <template match="processing-instruction()[local-name()='LesML-Link-Escape']" mode="LesML:finalize-tree">
741 <template match="text()" mode="LesML:finalize-tree">
742 <call-template name="LesML:break-and-unescape">
743 <with-param name="source" select="string(.)"/>
746 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
748 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
751 <template match="node()" mode="LesML:inline">
752 <param name="element-name"/>
753 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
754 <param name="start-sigil"/>
755 <param name="end-sigil"/>
757 <param name="langtag-supported" select="false()"/>
759 <when test="self::*">
760 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
761 <variable name="has-start-node" select="$end-node/preceding-sibling::text()[contains(., $start-sigil)] or string-length(substring-after($end-node, $start-sigil))>string-length(substring-after($end-node, $end-sigil))"/>
763 <when test="$end-node and $has-start-node">
764 <variable name="preceding">
765 <copy-of select="$end-node/preceding-sibling::node()"/>
766 <value-of select="substring-before($end-node, $end-sigil)"/>
768 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
769 <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
770 <variable name="maybe-langtag">
771 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
772 <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
775 <variable name="langtag">
776 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
777 <value-of select="$maybe-langtag"/>
780 <variable name="start-tokens-fragment">
781 <call-template name="LesML:split">
782 <with-param name="source" select="string($start-node)"/>
783 <with-param name="separator" select="$start-sigil"/>
786 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
787 <variable name="wrapped">
789 <copy-of select="@*"/>
790 <copy-of select="$start-node/preceding-sibling::node()"/>
791 <for-each select="$start-tokens[position()!=last()]">
792 <value-of select="."/>
793 <if test="position()!=last()">
794 <value-of select="$start-sigil"/>
797 <element name="{$element-name}" namespace="{$element-namespace}">
798 <if test="string($role)!=''">
799 <attribute name="role">
800 <value-of select="$role"/>
803 <if test="string($langtag)!=''">
804 <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
805 <attribute name="lang">
806 <value-of select="$langtag"/>
809 <attribute name="xml:lang">
810 <value-of select="$langtag"/>
813 <value-of select="$start-tokens[last()]"/>
814 <copy-of select="$start-node/following-sibling::node()"/>
817 <when test="string($langtag)!=''">
818 <value-of select="substring-after($restoftext, '$')"/>
821 <value-of select="$restoftext"/>
824 <copy-of select="$end-node/following-sibling::node()"/>
827 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
828 <with-param name="element-name" select="$element-name"/>
829 <with-param name="element-namespace" select="$element-namespace"/>
830 <with-param name="start-sigil" select="$start-sigil"/>
831 <with-param name="end-sigil" select="$end-sigil"/>
832 <with-param name="role" select="$role"/>
833 <with-param name="langtag-supported" select="$langtag-supported"/>
838 <copy-of select="@*"/>
839 <apply-templates select="node()" mode="LesML:inline">
840 <with-param name="element-name" select="$element-name"/>
841 <with-param name="element-namespace" select="$element-namespace"/>
842 <with-param name="start-sigil" select="$start-sigil"/>
843 <with-param name="end-sigil" select="$end-sigil"/>
844 <with-param name="role" select="$role"/>
845 <with-param name="langtag-supported" select="$langtag-supported"/>
852 <copy-of select="."/>
856 <template match="node()" mode="LesML:linkify">
857 <variable name="result">
859 <when test="self::*">
860 <variable name="end-node" select="text()[contains(., '>}')][1]"/>
861 <variable name="has-start-node" select="$end-node/preceding-sibling::text()[contains(., '{🔗') and not(following-sibling::*)] or string-length(substring-after($end-node, '{🔗'))>string-length(substring-after($end-node, '>}'))"/>
863 <when test="$end-node and $has-start-node">
864 <variable name="preceding">
865 <copy-of select="$end-node/preceding-sibling::node()"/>
866 <value-of select="substring-before($end-node, '>}')"/>
868 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., '{🔗') and not(following-sibling::*)][last()]"/>
869 <variable name="start-tokens-fragment">
870 <call-template name="LesML:split">
871 <with-param name="source" select="string($start-node)"/>
872 <with-param name="separator" select="'{🔗'"/>
875 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
876 <variable name="hyperlink">
877 <value-of select="$start-tokens[last()]"/>
878 <for-each select="$start-node/following-sibling::node()">
880 <when test="self::text()">
881 <value-of select="."/>
883 <when test="self::processing-instruction()[local-name()='LesML-Link-Escape']">
890 <when test="contains($hyperlink, '<')">
891 <variable name="ltcomponents-fragment">
892 <call-template name="LesML:split">
893 <with-param name="source" select="$hyperlink"/>
894 <with-param name="separator" select="'<'"/>
897 <variable name="ltcomponents" select="exsl:node-set($ltcomponents-fragment)/*"/>
898 <variable name="wrapped">
900 <copy-of select="@*"/>
901 <copy-of select="$start-node/preceding-sibling::node()"/>
902 <for-each select="$start-tokens[position()!=last()]">
903 <value-of select="."/>
904 <if test="position()!=last()">
908 <element name="a" namespace="&xhtml;">
909 <attribute name="href">
910 <value-of select="$ltcomponents[last()]"/>
913 <when test="count($ltcomponents)>2 or normalize-space($ltcomponents[1])!=''">
914 <for-each select="$ltcomponents[position()!=last()]">
915 <value-of select="."/>
916 <if test="position()!=last()">
922 <value-of select="$ltcomponents[last()]"/>
926 <value-of select="substring-after($end-node, '>}')"/>
927 <copy-of select="$end-node/following-sibling::node()"/>
930 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:linkify"/>
933 <variable name="escaped">
935 <copy-of select="@*"/>
936 <copy-of select="$start-node/preceding-sibling::node()"/>
937 <for-each select="$start-tokens[position()!=last()]">
938 <value-of select="."/>
939 <if test="position()!=last()">
944 <processing-instruction name="LesML-Link-Escape"/>
945 <copy-of select="$hyperlink"/>
947 <value-of select="substring-after($end-node, '>}')"/>
948 <copy-of select="$end-node/following-sibling::node()"/>
951 <apply-templates select="exsl:node-set($escaped)/*" mode="LesML:linkify"/>
957 <copy-of select="@*"/>
958 <apply-templates select="node()" mode="LesML:linkify"/>
964 <copy-of select="."/>
968 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
970 <template match="node()" mode="LesML:strikethrough">
971 <variable name="result">
972 <apply-templates select="." mode="LesML:inline">
973 <with-param name="element-name" select="'s'"/>
974 <with-param name="element-namespace" select="'&xhtml;'"/>
975 <with-param name="start-sigil" select="'⸠'"/>
976 <with-param name="end-sigil" select="'⸡'"/>
979 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
981 <template match="node()" mode="LesML:underline">
982 <variable name="result">
983 <apply-templates select="." mode="LesML:inline">
984 <with-param name="element-name" select="'u'"/>
985 <with-param name="element-namespace" select="'&xhtml;'"/>
986 <with-param name="start-sigil" select="'⸤'"/>
987 <with-param name="end-sigil" select="'⸥'"/>
990 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
992 <template match="node()" mode="LesML:noted">
993 <variable name="result">
994 <apply-templates select="." mode="LesML:inline">
995 <with-param name="element-name" select="'small'"/>
996 <with-param name="element-namespace" select="'&xhtml;'"/>
997 <with-param name="start-sigil" select="'⟦'"/>
998 <with-param name="end-sigil" select="'⟧'"/>
999 <with-param name="role" select="'note'"/>
1002 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
1004 <template match="node()" mode="LesML:parenthetical">
1005 <variable name="result">
1006 <apply-templates select="." mode="LesML:inline">
1007 <with-param name="element-name" select="'small'"/>
1008 <with-param name="element-namespace" select="'&xhtml;'"/>
1009 <with-param name="start-sigil" select="'⸨'"/>
1010 <with-param name="end-sigil" select="'⸩'"/>
1013 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
1015 <template match="node()" mode="LesML:code">
1016 <variable name="result">
1017 <apply-templates select="." mode="LesML:inline">
1018 <with-param name="element-name" select="'code'"/>
1019 <with-param name="element-namespace" select="'&xhtml;'"/>
1020 <with-param name="start-sigil" select="'`'"/>
1021 <with-param name="end-sigil" select="'´'"/>
1024 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
1026 <template match="node()" mode="LesML:titled">
1027 <variable name="result">
1028 <apply-templates select="." mode="LesML:inline">
1029 <with-param name="element-name" select="'cite'"/>
1030 <with-param name="element-namespace" select="'&xhtml;'"/>
1031 <with-param name="start-sigil" select="'⟪'"/>
1032 <with-param name="end-sigil" select="'⟫'"/>
1035 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
1037 <template match="node()" mode="LesML:offset">
1038 <variable name="result">
1039 <apply-templates select="." mode="LesML:inline">
1040 <with-param name="element-name" select="'i'"/>
1041 <with-param name="element-namespace" select="'&xhtml;'"/>
1042 <with-param name="start-sigil" select="'⟨'"/>
1043 <with-param name="end-sigil" select="'⟩'"/>
1044 <with-param name="langtag-supported" select="true()"/>
1047 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
1049 <template match="node()" mode="LesML:bolded">
1050 <variable name="result">
1051 <apply-templates select="." mode="LesML:inline">
1052 <with-param name="element-name" select="'b'"/>
1053 <with-param name="element-namespace" select="'&xhtml;'"/>
1054 <with-param name="start-sigil" select="'⦃'"/>
1055 <with-param name="end-sigil" select="'⦄'"/>
1058 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
1060 <template match="node()" mode="LesML:important">
1061 <variable name="result">
1062 <apply-templates select="." mode="LesML:inline">
1063 <with-param name="element-name" select="'strong'"/>
1064 <with-param name="element-namespace" select="'&xhtml;'"/>
1065 <with-param name="start-sigil" select="'☞'"/>
1066 <with-param name="end-sigil" select="'☜'"/>
1069 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
1071 <template match="node()" mode="LesML:emphasized">
1072 <apply-templates select="." mode="LesML:inline">
1073 <with-param name="element-name" select="'em'"/>
1074 <with-param name="element-namespace" select="'&xhtml;'"/>
1075 <with-param name="start-sigil" select="'⹐'"/>
1076 <with-param name="end-sigil" select="'⹑'"/>