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="$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:comment"/>
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 <element name="div" namespace="&xhtml;">
643 <call-template name="LesML:parse">
644 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
648 <template match="html:blockquote" mode="LesML:finalize-tree">
649 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
650 <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
651 <variable name="contents">
652 <copy-of select="node()"/>
653 <for-each select="exslset:leading(following-sibling::node(), $notquote)">
654 <copy-of select="node()"/>
657 <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
658 <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()]"/>
660 <when test="starts-with($laststarttext, '— ')">
661 <variable name="caption">
662 <copy-of select="$laststarttext/preceding-sibling::node()"/>
663 <value-of select="substring-after($laststarttext, '— ')"/>
664 <copy-of select="$laststarttext/following-sibling::node()"/>
666 <element name="figure" namespace="&xhtml;">
668 <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
670 <element name="figcaption" namespace="&xhtml;">
671 <for-each select="$content-nodes[last()]">
673 <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
681 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
687 <template match="html:div" mode="LesML:finalize-tree">
688 <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)]">
689 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
691 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
692 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
693 <apply-templates select="node()" mode="LesML:finalize-tree"/>
698 <template match="html:li" mode="LesML:finalize-tree">
699 <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)]">
700 <apply-templates select="." mode="LesML:finalize-list"/>
703 <template match="html:li" mode="LesML:finalize-list">
704 <param name="parent-level" select="0"/>
705 <variable name="current-class" select="string(@class)"/>
706 <variable name="current-level" select="number(@data-level)"/>
707 <variable name="wrapper">
709 <when test="@class='ordered'">
717 <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]"/>
718 <element name="{$wrapper}" namespace="&xhtml;">
719 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @data-level=$current-level]">
720 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
722 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
723 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
724 <apply-templates select="node()" mode="LesML:finalize-tree"/>
726 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
727 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
728 <with-param name="parent-level" select="$current-level"/>
734 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
735 <apply-templates select="$notinlist" mode="LesML:finalize-list">
736 <with-param name="parent-level" select="$parent-level"/>
740 <template match="processing-instruction()[local-name()='LesML-Link-Escape']" mode="LesML:finalize-tree">
743 <template match="text()" mode="LesML:finalize-tree">
744 <call-template name="LesML:break-and-unescape">
745 <with-param name="source" select="string(.)"/>
748 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
750 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
753 <template match="node()" mode="LesML:comment">
754 <variable name="result">
756 <when test="self::*">
757 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
758 <variable name="after-start">
759 <if test="$start-node">
760 <value-of select="substring-after($start-node, '⌦')"/>
763 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
765 <when test="$start-node and $has-end-node">
766 <variable name="following">
767 <value-of select="$after-start"/>
768 <copy-of select="$start-node/following-sibling::node()"/>
770 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
771 <variable name="comment">
772 <for-each select="$end-node/preceding-sibling::node()">
773 <value-of select="."/>
775 <value-of select="substring-before($end-node, '⌫')"/>
777 <variable name="comment-split-fragment">
778 <call-template name="LesML:split">
779 <with-param name="source" select="string($comment)"/>
780 <with-param name="separator" select="'--'"/>
783 <variable name="rest-fragment">
784 <element name="span" namespace="&xhtml;">
785 <value-of select="substring-after($end-node, '⌫')"/>
786 <copy-of select="$end-node/following-sibling::node()"/>
789 <variable name="commented-rest-fragment">
790 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment"/>
793 <copy-of select="@*"/>
794 <copy-of select="$start-node/preceding-sibling::node()"/>
795 <copy-of select="substring-before($start-node, '⌦')"/>
797 <for-each select="exsl:node-set($comment-split-fragment)/*">
798 <if test="string()='' or starts-with(., '‐')">
799 <text>͏</text>
801 <value-of select="."/>
802 <if test="substring(., string-length(.), 1)='‐'">
803 <text>͏</text>
806 <when test="position()!=last()">
807 <text>-͏-</text>
812 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
817 <copy-of select="@*"/>
818 <apply-templates select="node()" mode="LesML:comment"/>
823 <when test="self::text()[contains(., '⌧')]">
824 <variable name="split-fragment">
825 <call-template name="LesML:split">
826 <with-param name="source" select="string()"/>
827 <with-param name="separator" select="'⌧'"/>
830 <for-each select="exsl:node-set($split-fragment)/node()">
831 <value-of select="."/>
832 <if test="position()!=last()">
834 <text>͏</text>
840 <copy-of select="."/>
844 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify"/>
846 <template match="node()" mode="LesML:inline">
847 <param name="element-name"/>
848 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
849 <param name="start-sigil"/>
850 <param name="end-sigil"/>
851 <param name="class"/>
853 <param name="langtag-supported" select="false()"/>
855 <when test="self::*">
856 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
857 <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))"/>
859 <when test="$end-node and $has-start-node">
860 <variable name="preceding">
861 <copy-of select="$end-node/preceding-sibling::node()"/>
862 <value-of select="substring-before($end-node, $end-sigil)"/>
864 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
865 <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
866 <variable name="maybe-langtag">
867 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
868 <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
871 <variable name="langtag">
872 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
873 <value-of select="$maybe-langtag"/>
876 <variable name="start-tokens-fragment">
877 <call-template name="LesML:split">
878 <with-param name="source" select="string($start-node)"/>
879 <with-param name="separator" select="$start-sigil"/>
882 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
883 <variable name="wrapped">
885 <copy-of select="@*"/>
886 <copy-of select="$start-node/preceding-sibling::node()"/>
887 <for-each select="$start-tokens[position()!=last()]">
888 <value-of select="."/>
889 <if test="position()!=last()">
890 <value-of select="$start-sigil"/>
893 <element name="{$element-name}" namespace="{$element-namespace}">
894 <if test="string($role)!=''">
895 <attribute name="role">
896 <value-of select="$role"/>
899 <if test="string($class)!=''">
900 <attribute name="class">
901 <value-of select="$class"/>
904 <if test="string($langtag)!=''">
905 <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
906 <attribute name="lang">
907 <value-of select="$langtag"/>
910 <attribute name="xml:lang">
911 <value-of select="$langtag"/>
914 <value-of select="$start-tokens[last()]"/>
915 <copy-of select="$start-node/following-sibling::node()"/>
918 <when test="string($langtag)!=''">
919 <value-of select="substring-after($restoftext, '$')"/>
922 <value-of select="$restoftext"/>
925 <copy-of select="$end-node/following-sibling::node()"/>
928 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
929 <with-param name="element-name" select="$element-name"/>
930 <with-param name="element-namespace" select="$element-namespace"/>
931 <with-param name="start-sigil" select="$start-sigil"/>
932 <with-param name="end-sigil" select="$end-sigil"/>
933 <with-param name="role" select="$role"/>
934 <with-param name="langtag-supported" select="$langtag-supported"/>
939 <copy-of select="@*"/>
940 <apply-templates select="node()" mode="LesML:inline">
941 <with-param name="element-name" select="$element-name"/>
942 <with-param name="element-namespace" select="$element-namespace"/>
943 <with-param name="start-sigil" select="$start-sigil"/>
944 <with-param name="end-sigil" select="$end-sigil"/>
945 <with-param name="role" select="$role"/>
946 <with-param name="langtag-supported" select="$langtag-supported"/>
953 <copy-of select="."/>
957 <template match="node()" mode="LesML:linkify">
958 <variable name="result">
960 <when test="self::*">
961 <variable name="end-node" select="text()[contains(., '>}')][1]"/>
962 <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, '>}'))"/>
964 <when test="$end-node and $has-start-node">
965 <variable name="preceding">
966 <copy-of select="$end-node/preceding-sibling::node()"/>
967 <value-of select="substring-before($end-node, '>}')"/>
969 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., '{🔗') and not(following-sibling::*)][last()]"/>
970 <variable name="start-tokens-fragment">
971 <call-template name="LesML:split">
972 <with-param name="source" select="string($start-node)"/>
973 <with-param name="separator" select="'{🔗'"/>
976 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
977 <variable name="hyperlink">
978 <value-of select="$start-tokens[last()]"/>
979 <for-each select="$start-node/following-sibling::node()">
981 <when test="self::text()">
982 <value-of select="."/>
984 <when test="self::processing-instruction()[local-name()='LesML-Link-Escape']">
991 <when test="contains($hyperlink, '<')">
992 <variable name="ltcomponents-fragment">
993 <call-template name="LesML:split">
994 <with-param name="source" select="$hyperlink"/>
995 <with-param name="separator" select="'<'"/>
998 <variable name="ltcomponents" select="exsl:node-set($ltcomponents-fragment)/*"/>
999 <variable name="wrapped">
1001 <copy-of select="@*"/>
1002 <copy-of select="$start-node/preceding-sibling::node()"/>
1003 <for-each select="$start-tokens[position()!=last()]">
1004 <value-of select="."/>
1005 <if test="position()!=last()">
1009 <element name="a" namespace="&xhtml;">
1010 <attribute name="href">
1011 <value-of select="$ltcomponents[last()]"/>
1014 <when test="count($ltcomponents)>2 or normalize-space($ltcomponents[1])!=''">
1015 <for-each select="$ltcomponents[position()!=last()]">
1016 <value-of select="."/>
1017 <if test="position()!=last()">
1023 <value-of select="$ltcomponents[last()]"/>
1027 <value-of select="substring-after($end-node, '>}')"/>
1028 <copy-of select="$end-node/following-sibling::node()"/>
1031 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:linkify"/>
1034 <variable name="escaped">
1036 <copy-of select="@*"/>
1037 <copy-of select="$start-node/preceding-sibling::node()"/>
1038 <for-each select="$start-tokens[position()!=last()]">
1039 <value-of select="."/>
1040 <if test="position()!=last()">
1045 <processing-instruction name="LesML-Link-Escape"/>
1046 <copy-of select="$hyperlink"/>
1048 <value-of select="substring-after($end-node, '>}')"/>
1049 <copy-of select="$end-node/following-sibling::node()"/>
1052 <apply-templates select="exsl:node-set($escaped)/*" mode="LesML:linkify"/>
1058 <copy-of select="@*"/>
1059 <apply-templates select="node()" mode="LesML:linkify"/>
1065 <copy-of select="."/>
1069 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
1071 <template match="node()" mode="LesML:strikethrough">
1072 <variable name="result">
1073 <apply-templates select="." mode="LesML:inline">
1074 <with-param name="element-name" select="'s'"/>
1075 <with-param name="element-namespace" select="'&xhtml;'"/>
1076 <with-param name="start-sigil" select="'⸠'"/>
1077 <with-param name="end-sigil" select="'⸡'"/>
1080 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
1082 <template match="node()" mode="LesML:underline">
1083 <variable name="result">
1084 <apply-templates select="." mode="LesML:inline">
1085 <with-param name="element-name" select="'u'"/>
1086 <with-param name="element-namespace" select="'&xhtml;'"/>
1087 <with-param name="start-sigil" select="'⸤'"/>
1088 <with-param name="end-sigil" select="'⸥'"/>
1091 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
1093 <template match="node()" mode="LesML:noted">
1094 <variable name="result">
1095 <apply-templates select="." mode="LesML:inline">
1096 <with-param name="element-name" select="'small'"/>
1097 <with-param name="element-namespace" select="'&xhtml;'"/>
1098 <with-param name="start-sigil" select="'⟦'"/>
1099 <with-param name="end-sigil" select="'⟧'"/>
1100 <with-param name="role" select="'note'"/>
1103 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
1105 <template match="node()" mode="LesML:parenthetical">
1106 <variable name="result">
1107 <apply-templates select="." mode="LesML:inline">
1108 <with-param name="element-name" select="'small'"/>
1109 <with-param name="element-namespace" select="'&xhtml;'"/>
1110 <with-param name="start-sigil" select="'⸨'"/>
1111 <with-param name="end-sigil" select="'⸩'"/>
1114 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
1116 <template match="node()" mode="LesML:code">
1117 <variable name="result">
1118 <apply-templates select="." mode="LesML:inline">
1119 <with-param name="element-name" select="'code'"/>
1120 <with-param name="element-namespace" select="'&xhtml;'"/>
1121 <with-param name="start-sigil" select="'`'"/>
1122 <with-param name="end-sigil" select="'´'"/>
1125 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
1127 <template match="node()" mode="LesML:titled">
1128 <variable name="result">
1129 <apply-templates select="." mode="LesML:inline">
1130 <with-param name="element-name" select="'cite'"/>
1131 <with-param name="element-namespace" select="'&xhtml;'"/>
1132 <with-param name="start-sigil" select="'⟪'"/>
1133 <with-param name="end-sigil" select="'⟫'"/>
1136 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named"/>
1138 <template match="node()" mode="LesML:named">
1139 <variable name="result">
1140 <apply-templates select="." mode="LesML:inline">
1141 <with-param name="element-name" select="'u'"/>
1142 <with-param name="element-namespace" select="'&xhtml;'"/>
1143 <with-param name="start-sigil" select="'⸶'"/>
1144 <with-param name="end-sigil" select="'⸷'"/>
1145 <with-param name="class" select="'name'"/>
1148 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
1150 <template match="node()" mode="LesML:offset">
1151 <variable name="result">
1152 <apply-templates select="." mode="LesML:inline">
1153 <with-param name="element-name" select="'i'"/>
1154 <with-param name="element-namespace" select="'&xhtml;'"/>
1155 <with-param name="start-sigil" select="'⟨'"/>
1156 <with-param name="end-sigil" select="'⟩'"/>
1157 <with-param name="langtag-supported" select="true()"/>
1160 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
1162 <template match="node()" mode="LesML:bolded">
1163 <variable name="result">
1164 <apply-templates select="." mode="LesML:inline">
1165 <with-param name="element-name" select="'b'"/>
1166 <with-param name="element-namespace" select="'&xhtml;'"/>
1167 <with-param name="start-sigil" select="'⦃'"/>
1168 <with-param name="end-sigil" select="'⦄'"/>
1171 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
1173 <template match="node()" mode="LesML:important">
1174 <variable name="result">
1175 <apply-templates select="." mode="LesML:inline">
1176 <with-param name="element-name" select="'strong'"/>
1177 <with-param name="element-namespace" select="'&xhtml;'"/>
1178 <with-param name="start-sigil" select="'☞'"/>
1179 <with-param name="end-sigil" select="'☜'"/>
1182 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
1184 <template match="node()" mode="LesML:emphasized">
1185 <apply-templates select="." mode="LesML:inline">
1186 <with-param name="element-name" select="'em'"/>
1187 <with-param name="element-namespace" select="'&xhtml;'"/>
1188 <with-param name="start-sigil" select="'⹐'"/>
1189 <with-param name="end-sigil" select="'⹑'"/>