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 LesML "urn:fdc:ladys.computer:20240512:LesML">
16 <!ENTITY section-break "*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~">
17 <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ')">
18 <!ENTITY unsigiled-text "substring($text, 3, string-length($text)-2)">
19 <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
22 xmlns="http://www.w3.org/1999/XSL/Transform"
23 xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
24 xmlns:exsl="http://exslt.org/common"
25 xmlns:exsldyn="http://exslt.org/dynamic"
26 xmlns:exslset="http://exslt.org/sets"
27 xmlns:exslstr="http://exslt.org/strings"
28 xmlns:html="http://www.w3.org/1999/xhtml"
29 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
30 exclude-result-prefixes="LesML"
31 extension-element-prefixes="exsl exsldyn exslset exslstr"
34 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
35 <template name="LesML:split">
36 <param name="source"/>
37 <param name="separator" select="'
'"/>
39 <when test="contains($source, $separator)">
41 <value-of select="substring-before($source, $separator)"/>
43 <call-template name="LesML:split">
44 <with-param name="source" select="substring-after($source, $separator)"/>
45 <with-param name="separator" select="$separator"/>
50 <value-of select="$source"/>
55 <template name="LesML:break-and-unescape">
56 <param name="source"/>
57 <variable name="broken-fragment">
58 <call-template name="LesML:split">
59 <with-param name="source" select="$source"/>
60 <with-param name="separator" select="'
'"/>
63 <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
64 <for-each select="$broken">
65 <call-template name="LesML:unescape">
66 <with-param name="source" select="string()"/>
68 <if test="position()!=count($broken)">
69 <element name="br" namespace="&xhtml;"/>
73 <template name="LesML:unescape">
74 <param name="source"/>
76 <when test="contains($source, '{U+')">
77 <variable name="after" select="substring-after($source, '{U+')"/>
79 <when test="contains($after, '}')">
80 <variable name="inner" select="substring-before($after, '}')"/>
81 <variable name="components">
82 <call-template name="LesML:split">
83 <with-param name="source" select="$inner"/>
84 <with-param name="separator" select="'.'"/>
87 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
88 <value-of select="substring-before($source, '{U+')"/>
90 <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
92 <value-of select="$inner"/>
94 <call-template name="LesML:unescape">
95 <with-param name="source" select="substring-after($after, '}')"/>
99 <for-each select="$component-nodes">
100 <text disable-output-escaping="yes">&#x</text>
101 <value-of select="."/>
104 <call-template name="LesML:unescape">
105 <with-param name="source" select="substring-after($after, '}')"/>
111 <value-of select="substring-before($source, '{U+')"/>
113 <call-template name="LesML:unescape">
114 <with-param name="source" select="$after"/>
120 <value-of select="$source"/>
124 <template name="LesML:id-and-contents">
125 <param name="source"/>
127 <when test="starts-with($source, '¶')">
129 <when test="contains($source, ' ')">
130 <variable name="id" select="substring-before(substring-after($source, '¶'), ' ')"/>
132 <attribute name="id">
133 <value-of select="$id"/>
136 <value-of select="substring-after($source, ' ')"/>
139 <attribute name="id">
140 <value-of select="substring-after($source, '¶')"/>
146 <value-of select="$source"/>
150 <template name="LesML:parse">
151 <param name="lines" select="/.."/>
152 <param name="parent-params" select="/.."/>
153 <variable name="first-line" select="$lines[1]"/>
154 <variable name="shebang">
155 <if test="starts-with($first-line, '#!lesml')">
156 <value-of select="$first-line"/>
159 <variable name="params-string">
161 <when test="starts-with($shebang, '#!lesml@')">
162 <value-of select="substring-after($shebang, '$')"/>
165 <value-of select="substring-after($shebang, '#!lesml')"/>
169 <variable name="params-fragment">
171 <when test="$shebang!=''">
173 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
179 <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
183 <for-each select="exslstr:tokenize($params-string)">
185 <when test="contains(., '=')">
188 <value-of select="substring-before(., '=')"/>
191 <value-of select="substring-after(., '=')"/>
198 <value-of select="."/>
207 <when test="$parent-params">
208 <copy-of select="$parent-params"/>
215 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
216 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
217 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
218 <variable name="doclines" select="exslset:leading($noshebang, $docsep)"/>
219 <if test="starts-with($first-line, '##') and $first-line!='##'">
221 <value-of select="substring-after($first-line, '##')"/>
224 <if test="$doclines[normalize-space()!='']">
225 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
226 <element name="article" namespace="&xhtml;">
227 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
228 <attribute name="lang">
229 <value-of select="following-sibling::html:dd"/>
231 <attribute name="xml:lang">
232 <value-of select="following-sibling::html:dd"/>
235 <for-each select="$params/html:div/html:dt[string()='profile']">
236 <attribute name="data-lesml-profile">
237 <value-of select="following-sibling::html:dd"/>
240 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
241 <element name="footer" namespace="&xhtml;">
242 <attribute name="class">
245 <for-each select="$record-separators">
246 <variable name="position" select="position()"/>
247 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
248 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)"/>
250 <element name="dl" namespace="&xhtml;">
251 <for-each select="$fields">
253 <when test="starts-with(., ' ') and exslset:leading($fields, .)"/>
255 <variable name="next" select="exslset:intersection(following-sibling::*[not(starts-with(., ' '))][1], $fields)"/>
256 <element name="div" namespace="&xhtml;">
257 <element name="dt" namespace="&xhtml;">
258 <value-of select="normalize-space(substring-before(., ':'))"/>
260 <element name="dd" namespace="&xhtml;">
261 <variable name="firstline">
263 <when test="contains(., ':')">
264 <value-of select="normalize-space(substring-after(., ':'))"/>
267 <value-of select="normalize-space(.)"/>
272 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
273 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
276 <value-of select="$firstline"/>
279 <for-each select="exslset:intersection(following-sibling::*[starts-with(., ' ')], exslset:leading($fields, $next))">
280 <variable name="nextline" select="normalize-space(.)"/>
282 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
283 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
286 <value-of select="$nextline"/>
299 <value-of select="substring-after(., '%%')"/>
305 <element name="div" namespace="&xhtml;">
306 <attribute name="class">
309 <call-template name="LesML:paragraphize">
310 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
316 <call-template name="LesML:parse">
317 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
318 <with-param name="parent-params" select="$params"/>
322 <template name="LesML:paragraphize">
323 <param name="lines" select="/.."/>
324 <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
325 <variable name="blocked">
326 <for-each select="$last-lines">
327 <variable name="position" select="position()"/>
328 <variable name="prev-last" select="$last-lines[($position)-1]"/>
329 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
330 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '	'))])"/>
331 <variable name="preformatted" select="not($linespans[not(starts-with(normalize-space(), '|'))])"/>
332 <variable name="text">
333 <for-each select="$linespans">
335 <when test="$preformatted">
336 <value-of select="substring-after(., '|')"/>
339 <value-of select="normalize-space()"/>
342 <if test="position()!=count($linespans)">
344 <when test="$preformatted">
354 <if test="string($text)!=''">
355 <variable name="par">
357 <when test="$preformatted">
358 <element name="pre" namespace="&xhtml;">
359 <call-template name="LesML:id-and-contents">
360 <with-param name="source" select="$text"/>
364 <when test="starts-with($text, '⁌') and &sigiled-text;">
365 <element name="h1" namespace="&xhtml;">
366 <call-template name="LesML:id-and-contents">
367 <with-param name="source" select="&unsigiled-text;"/>
371 <when test="starts-with($text, '§') and &sigiled-text;">
372 <element name="h2" namespace="&xhtml;">
373 <call-template name="LesML:id-and-contents">
374 <with-param name="source" select="&unsigiled-text;"/>
378 <when test="starts-with($text, '❦') and &sigiled-text;">
379 <element name="h3" namespace="&xhtml;">
380 <call-template name="LesML:id-and-contents">
381 <with-param name="source" select="&unsigiled-text;"/>
385 <when test="starts-with($text, '✠') and &sigiled-text;">
386 <element name="h4" namespace="&xhtml;">
387 <call-template name="LesML:id-and-contents">
388 <with-param name="source" select="&unsigiled-text;"/>
392 <when test="starts-with($text, '•') and &sigiled-text;">
393 <element name="li" namespace="&xhtml;">
394 <attribute name="class">
395 <text>unordered</text>
397 <attribute name="data-level">
400 <element name="p" namespace="&xhtml;">
401 <call-template name="LesML:id-and-contents">
402 <with-param name="source" select="&unsigiled-text;"/>
407 <when test="starts-with($text, '🔢') and &sigiled-text;">
408 <element name="li" namespace="&xhtml;">
409 <attribute name="class">
412 <attribute name="data-level">
415 <element name="p" namespace="&xhtml;">
416 <call-template name="LesML:id-and-contents">
417 <with-param name="source" select="&unsigiled-text;"/>
422 <when test="starts-with($text, '◦') and &sigiled-text;">
423 <element name="li" namespace="&xhtml;">
424 <attribute name="class">
425 <text>unordered</text>
427 <attribute name="data-level">
430 <element name="p" namespace="&xhtml;">
431 <call-template name="LesML:id-and-contents">
432 <with-param name="source" select="&unsigiled-text;"/>
437 <when test="starts-with($text, '🔠') and &sigiled-text;">
438 <element name="li" namespace="&xhtml;">
439 <attribute name="class">
442 <attribute name="data-level">
445 <element name="p" namespace="&xhtml;">
446 <call-template name="LesML:id-and-contents">
447 <with-param name="source" select="&unsigiled-text;"/>
452 <when test="starts-with($text, '▪') and &sigiled-text;">
453 <element name="li" namespace="&xhtml;">
454 <attribute name="class">
455 <text>unordered</text>
457 <attribute name="data-level">
460 <element name="p" namespace="&xhtml;">
461 <call-template name="LesML:id-and-contents">
462 <with-param name="source" select="&unsigiled-text;"/>
467 <when test="starts-with($text, '🔡') and &sigiled-text;">
468 <element name="li" namespace="&xhtml;">
469 <attribute name="class">
472 <attribute name="data-level">
475 <element name="p" namespace="&xhtml;">
476 <call-template name="LesML:id-and-contents">
477 <with-param name="source" select="&unsigiled-text;"/>
482 <when test="starts-with($text, '⁃') and &sigiled-text;">
483 <element name="li" namespace="&xhtml;">
484 <attribute name="class">
485 <text>unordered</text>
487 <attribute name="data-level">
490 <element name="p" namespace="&xhtml;">
491 <call-template name="LesML:id-and-contents">
492 <with-param name="source" select="&unsigiled-text;"/>
497 <when test="starts-with($text, '🔣') and &sigiled-text;">
498 <element name="li" namespace="&xhtml;">
499 <attribute name="class">
502 <attribute name="data-level">
505 <element name="p" namespace="&xhtml;">
506 <call-template name="LesML:id-and-contents">
507 <with-param name="source" select="&unsigiled-text;"/>
512 <when test="starts-with($text, '🛈') and &sigiled-text;">
513 <element name="div" namespace="&xhtml;">
514 <attribute name="role">
517 <attribute name="class">
520 <element name="p" namespace="&xhtml;">
521 <call-template name="LesML:id-and-contents">
522 <with-param name="source" select="&unsigiled-text;"/>
527 <when test="starts-with($text, '⯑') and &sigiled-text;">
528 <element name="div" namespace="&xhtml;">
529 <attribute name="role">
532 <attribute name="class">
535 <element name="p" namespace="&xhtml;">
536 <call-template name="LesML:id-and-contents">
537 <with-param name="source" select="&unsigiled-text;"/>
542 <when test="starts-with($text, '⚠︎') and &sigiled-text;">
543 <element name="div" namespace="&xhtml;">
544 <attribute name="role">
547 <attribute name="class">
550 <element name="p" namespace="&xhtml;">
551 <call-template name="LesML:id-and-contents">
552 <with-param name="source" select="&unsigiled-text;"/>
557 <when test="starts-with($text, '※') and &sigiled-text;">
558 <element name="div" namespace="&xhtml;">
559 <attribute name="role">
562 <attribute name="class">
565 <element name="p" namespace="&xhtml;">
566 <call-template name="LesML:id-and-contents">
567 <with-param name="source" select="&unsigiled-text;"/>
572 <when test="starts-with($text, '☡') and &sigiled-text;">
573 <element name="div" namespace="&xhtml;">
574 <attribute name="role">
577 <attribute name="class">
580 <element name="p" namespace="&xhtml;">
581 <call-template name="LesML:id-and-contents">
582 <with-param name="source" select="&unsigiled-text;"/>
587 <when test="starts-with($text, '⋯') and &sigiled-text;">
588 <element name="div" namespace="&xhtml;">
589 <attribute name="class">
590 <text>continuation</text>
592 <element name="p" namespace="&xhtml;">
593 <call-template name="LesML:id-and-contents">
594 <with-param name="source" select="&unsigiled-text;"/>
599 <when test="starts-with($text, '#') and &sigiled-text;">
601 <value-of select="&unsigiled-text;"/>
605 <element name="p" namespace="&xhtml;">
606 <call-template name="LesML:id-and-contents">
607 <with-param name="source" select="$text"/>
614 <when test="translate(string($text), '§ion-break; ', '')=''">
615 <element name="hr" namespace="&xhtml;"/>
617 <when test="$quoted">
618 <element name="blockquote" namespace="&xhtml;">
619 <copy-of select="$par"/>
623 <copy-of select="$par"/>
629 <variable name="inlined">
630 <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:comment"/>
632 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
634 <template match="html:script[@type='text/lesml']">
635 <variable name="lines-fragment">
636 <call-template name="LesML:split">
637 <with-param name="source">
638 <for-each select=".//text()">
639 <value-of select="."/>
644 <element name="div" namespace="&xhtml;">
645 <call-template name="LesML:parse">
646 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
650 <template match="node()" mode="LesML:finalize-attributes">
651 <variable name="notattr" select="following-sibling::node()[not(self::text() and translate(., ' 	', '')='' or self::LesML:attribute)]"/>
652 <for-each select="(.|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
653 <copy-of select="."/>
654 <if test="local-name()='lang' and namespace-uri()=''">
655 <attribute name="xml:lang">
656 <value-of select="."/>
661 <template match="LesML:attribute[preceding-sibling::node()[position()=1 and (self::text() or self::*)]]|text()[preceding-sibling::node()[position()=1 and self::*] and following-sibling::node()[position()=1 and self::LesML:attribute] and translate(., ' 	', '')='']" mode="LesML:finalize-tree" priority="2"/>
662 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize-tree" priority="1">
663 <element name="span" namespace="&xhtml;">
664 <apply-templates select="." mode="LesML:finalize-attributes"/>
665 <if test="self::text()">
666 <call-template name="LesML:break-and-unescape">
667 <with-param name="source" select="string(.)"/>
672 <template match="html:blockquote" mode="LesML:finalize-tree">
673 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
674 <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
675 <variable name="contents">
676 <copy-of select="node()"/>
677 <for-each select="exslset:leading(following-sibling::node(), $notquote)">
678 <copy-of select="node()"/>
681 <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
682 <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()]"/>
684 <when test="starts-with($laststarttext, '— ')">
685 <variable name="caption">
686 <copy-of select="$laststarttext/preceding-sibling::node()"/>
687 <value-of select="substring-after($laststarttext, '— ')"/>
688 <copy-of select="$laststarttext/following-sibling::node()"/>
690 <element name="figure" namespace="&xhtml;">
692 <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
694 <element name="figcaption" namespace="&xhtml;">
695 <for-each select="$content-nodes[last()]">
697 <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
705 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
711 <template match="html:div" mode="LesML:finalize-tree">
712 <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)]">
713 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
715 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
716 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
717 <apply-templates select="node()" mode="LesML:finalize-tree"/>
722 <template match="html:li" mode="LesML:finalize-tree">
723 <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)]">
724 <apply-templates select="." mode="LesML:finalize-list"/>
727 <template match="html:li" mode="LesML:finalize-list">
728 <param name="parent-level" select="0"/>
729 <variable name="current-class" select="string(@class)"/>
730 <variable name="current-level" select="number(@data-level)"/>
731 <variable name="wrapper">
733 <when test="@class='ordered'">
741 <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]"/>
742 <element name="{$wrapper}" namespace="&xhtml;">
743 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @data-level=$current-level]">
744 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
746 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
747 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
748 <apply-templates select="node()" mode="LesML:finalize-tree"/>
750 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
751 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
752 <with-param name="parent-level" select="$current-level"/>
758 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
759 <apply-templates select="$notinlist" mode="LesML:finalize-list">
760 <with-param name="parent-level" select="$parent-level"/>
764 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finalize-tree">
765 <value-of select="."/>
767 <template match="text()" mode="LesML:finalize-tree">
768 <call-template name="LesML:break-and-unescape">
769 <with-param name="source" select="string(.)"/>
772 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
774 <apply-templates select="." mode="LesML:finalize-attributes"/>
775 <apply-templates select="node()" mode="LesML:finalize-tree"/>
778 <template match="node()" mode="LesML:comment">
779 <variable name="result">
781 <when test="self::*">
782 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
783 <variable name="after-start">
784 <if test="$start-node">
785 <value-of select="substring-after($start-node, '⌦')"/>
788 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
790 <when test="$start-node and $has-end-node">
791 <variable name="following">
792 <value-of select="$after-start"/>
793 <copy-of select="$start-node/following-sibling::node()"/>
795 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
796 <variable name="comment">
797 <for-each select="$end-node/preceding-sibling::node()">
798 <value-of select="."/>
800 <value-of select="substring-before($end-node, '⌫')"/>
802 <variable name="comment-split-fragment">
803 <call-template name="LesML:split">
804 <with-param name="source" select="string($comment)"/>
805 <with-param name="separator" select="'--'"/>
808 <variable name="rest-fragment">
809 <element name="span" namespace="&xhtml;">
810 <value-of select="substring-after($end-node, '⌫')"/>
811 <copy-of select="$end-node/following-sibling::node()"/>
814 <variable name="commented-rest-fragment">
815 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment"/>
818 <copy-of select="@*"/>
819 <copy-of select="$start-node/preceding-sibling::node()"/>
820 <copy-of select="substring-before($start-node, '⌦')"/>
822 <for-each select="exsl:node-set($comment-split-fragment)/*">
823 <if test="string()='' or starts-with(., '‐')">
824 <text>͏</text>
826 <value-of select="."/>
827 <if test="substring(., string-length(.), 1)='‐'">
828 <text>͏</text>
831 <when test="position()!=last()">
832 <text>-͏-</text>
837 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
842 <copy-of select="@*"/>
843 <apply-templates select="node()" mode="LesML:comment"/>
848 <when test="self::text()[contains(., '⌧')]">
849 <variable name="split-fragment">
850 <call-template name="LesML:split">
851 <with-param name="source" select="string()"/>
852 <with-param name="separator" select="'⌧'"/>
855 <for-each select="exsl:node-set($split-fragment)/node()">
856 <value-of select="."/>
857 <if test="position()!=last()">
859 <text>͏</text>
865 <copy-of select="."/>
869 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:attrify"/>
871 <template match="node()" mode="LesML:inline">
872 <param name="element-name"/>
873 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
874 <param name="start-sigil"/>
875 <param name="end-sigil"/>
876 <param name="class"/>
878 <param name="langtag-supported" select="false()"/>
880 <when test="self::*">
881 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
882 <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))"/>
884 <when test="$end-node and $has-start-node">
885 <variable name="preceding">
886 <copy-of select="$end-node/preceding-sibling::node()"/>
887 <value-of select="substring-before($end-node, $end-sigil)"/>
889 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
890 <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
891 <variable name="maybe-langtag">
892 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
893 <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
896 <variable name="langtag">
897 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
898 <value-of select="$maybe-langtag"/>
901 <variable name="start-tokens-fragment">
902 <call-template name="LesML:split">
903 <with-param name="source" select="string($start-node)"/>
904 <with-param name="separator" select="$start-sigil"/>
907 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
908 <variable name="wrapped">
910 <copy-of select="@*"/>
911 <copy-of select="$start-node/preceding-sibling::node()"/>
912 <for-each select="$start-tokens[position()!=last()]">
913 <value-of select="."/>
914 <if test="position()!=last()">
915 <value-of select="$start-sigil"/>
918 <element name="{$element-name}" namespace="{$element-namespace}">
919 <if test="string($role)!=''">
920 <attribute name="role">
921 <value-of select="$role"/>
924 <if test="string($class)!=''">
925 <attribute name="class">
926 <value-of select="$class"/>
929 <if test="string($langtag)!=''">
930 <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
931 <attribute name="lang">
932 <value-of select="$langtag"/>
935 <attribute name="xml:lang">
936 <value-of select="$langtag"/>
939 <value-of select="$start-tokens[last()]"/>
940 <copy-of select="$start-node/following-sibling::node()"/>
943 <when test="string($langtag)!=''">
944 <value-of select="substring-after($restoftext, '$')"/>
947 <value-of select="$restoftext"/>
950 <copy-of select="$end-node/following-sibling::node()"/>
953 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
954 <with-param name="element-name" select="$element-name"/>
955 <with-param name="element-namespace" select="$element-namespace"/>
956 <with-param name="start-sigil" select="$start-sigil"/>
957 <with-param name="end-sigil" select="$end-sigil"/>
958 <with-param name="role" select="$role"/>
959 <with-param name="langtag-supported" select="$langtag-supported"/>
964 <copy-of select="@*"/>
965 <apply-templates select="node()" mode="LesML:inline">
966 <with-param name="element-name" select="$element-name"/>
967 <with-param name="element-namespace" select="$element-namespace"/>
968 <with-param name="start-sigil" select="$start-sigil"/>
969 <with-param name="end-sigil" select="$end-sigil"/>
970 <with-param name="role" select="$role"/>
971 <with-param name="langtag-supported" select="$langtag-supported"/>
978 <copy-of select="."/>
982 <template match="*" mode="LesML:partition">
983 <param name="start-sigil"/>
984 <param name="end-sigil"/>
985 <param name="separator"/>
986 <param name="ncname-keys" select="false()"/>
987 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
988 <variable name="has-start-node" select="$end-node/preceding-sibling::text()[contains(., $start-sigil) and not(following-sibling::* or following-sibling::comment())] or string-length(substring-after($end-node, $start-sigil))>string-length(substring-after($end-node, $end-sigil))"/>
990 <when test="$end-node and $has-start-node">
991 <variable name="preceding">
992 <copy-of select="$end-node/preceding-sibling::node()"/>
993 <value-of select="substring-before($end-node, $end-sigil)"/>
995 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil) and not(following-sibling::*)][last()]"/>
996 <variable name="start-tokens-fragment">
997 <call-template name="LesML:split">
998 <with-param name="source" select="string($start-node)"/>
999 <with-param name="separator" select="$start-sigil"/>
1002 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
1003 <variable name="innards">
1004 <value-of select="$start-tokens[last()]"/>
1005 <for-each select="$start-node/following-sibling::node()">
1006 <value-of select="."/>
1010 <when test="contains($innards, $separator)">
1011 <variable name="keyval-fragment">
1012 <call-template name="LesML:split">
1013 <with-param name="source" select="$innards"/>
1014 <with-param name="separator" select="$separator"/>
1017 <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
1018 <variable name="key">
1020 <when test="$ncname-keys">
1021 <value-of select="$keyval[1]"/>
1024 <for-each select="$keyval[position()!=last()]">
1025 <value-of select="."/>
1026 <if test="position()!=last()">
1027 <value-of select="$separator"/>
1033 <variable name="value">
1035 <when test="$ncname-keys">
1036 <for-each select="$keyval[position()!=1]">
1037 <value-of select="."/>
1038 <if test="position()!=last()">
1039 <value-of select="$separator"/>
1044 <value-of select="$keyval[last()]"/>
1049 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key), ' /([,*', '')=string($key) and exsldyn:evaluate(concat('not(self::html:', $key, ')'))]">
1050 <element name="span" namespace="&xhtml;">
1051 <copy-of select="$start-node/preceding-sibling::node()"/>
1052 <for-each select="$start-tokens[position()!=last()]">
1053 <value-of select="."/>
1054 <if test="position()!=last()">
1055 <value-of select="$start-sigil"/>
1059 <element name="span" namespace="&xhtml;">
1060 <value-of select="$key"/>
1062 <element name="span" namespace="&xhtml;">
1063 <value-of select="$value"/>
1065 <element name="span" namespace="&xhtml;">
1066 <value-of select="substring-after($end-node, $end-sigil)"/>
1067 <copy-of select="$end-node/following-sibling::node()"/>
1071 <element name="span" namespace="&xhtml;">
1072 <copy-of select="$start-node/preceding-sibling::node()"/>
1073 <for-each select="$start-tokens[position()!=last()]">
1074 <value-of select="."/>
1075 <if test="position()!=last()">
1076 <value-of select="$start-sigil"/>
1079 <processing-instruction name="LesML-Token-Escape">
1080 <value-of select="$start-sigil"/>
1081 </processing-instruction>
1082 <value-of select="$start-tokens[last()]"/>
1083 <value-of select="$start-node/following-sibling::node()"/>
1084 <value-of select="$end-sigil"/>
1085 <value-of select="substring-after($end-node, $end-sigil)"/>
1086 <copy-of select="$end-node/following-sibling::node()"/>
1092 <element name="span" namespace="&xhtml;">
1093 <copy-of select="$start-node/preceding-sibling::node()"/>
1094 <for-each select="$start-tokens[position()!=last()]">
1095 <value-of select="."/>
1096 <if test="position()!=last()">
1097 <value-of select="$start-sigil"/>
1100 <processing-instruction name="LesML-Token-Escape">
1101 <value-of select="$start-sigil"/>
1102 </processing-instruction>
1103 <value-of select="$start-tokens[last()]"/>
1104 <value-of select="$start-node/following-sibling::node()"/>
1105 <value-of select="$end-sigil"/>
1106 <value-of select="substring-after($end-node, $end-sigil)"/>
1107 <copy-of select="$end-node/following-sibling::node()"/>
1112 <when test="$end-node">
1113 <element name="span" namespace="&xhtml;">
1114 <copy-of select="$end-node/preceding-sibling::node()"/>
1115 <value-of select="substring-before($end-node, $end-sigil)"/>
1116 <processing-instruction name="LesML-Token-Escape">
1117 <value-of select="$end-sigil"/>
1118 </processing-instruction>
1119 <value-of select="substring-after($end-node, $end-sigil)"/>
1120 <copy-of select="$end-node/following-sibling::node()"/>
1124 <processing-instruction name="LesML-All-Done"/>
1128 <template match="node()" mode="LesML:attrify">
1129 <variable name="result">
1131 <when test="self::*">
1132 <variable name="partitioned-fragment">
1133 <apply-templates mode="LesML:partition" select=".">
1134 <with-param name="start-sigil" select="'{@'"/>
1135 <with-param name="end-sigil" select="'"}'"/>
1136 <with-param name="separator" select="'="'"/>
1137 <with-param name="ncname-keys" select="true()"/>
1140 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1142 <when test="count($partitioned)>1">
1143 <variable name="processed">
1145 <copy-of select="@*"/>
1146 <copy-of select="$partitioned[1]/node()"/>
1147 <element name="LesML:attribute" namespace="&LesML;">
1148 <attribute name="{$partitioned[2]}">
1149 <value-of select="$partitioned[3]"/>
1152 <copy-of select="$partitioned[4]/node()"/>
1155 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1157 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1159 <copy-of select="@*"/>
1160 <apply-templates select="node()" mode="LesML:attrify"/>
1164 <variable name="processed">
1166 <copy-of select="@*"/>
1167 <copy-of select="$partitioned/node()"/>
1170 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1175 <copy-of select="."/>
1179 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify"/>
1181 <template match="node()" mode="LesML:linkify">
1182 <variable name="result">
1184 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1186 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1189 <when test="self::*">
1190 <variable name="partitioned-fragment">
1191 <apply-templates mode="LesML:partition" select=".">
1192 <with-param name="start-sigil" select="'{🔗'"/>
1193 <with-param name="end-sigil" select="'>}'"/>
1194 <with-param name="separator" select="'<'"/>
1197 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1199 <when test="count($partitioned)>1">
1200 <variable name="processed">
1202 <copy-of select="@*"/>
1203 <copy-of select="$partitioned[1]/node()"/>
1204 <element name="a" namespace="&xhtml;">
1205 <attribute name="href">
1206 <value-of select="$partitioned[3]"/>
1208 <processing-instruction name="LesML-All-Done"/>
1210 <when test="string($partitioned[2])=''">
1211 <value-of select="$partitioned[3]"/>
1214 <value-of select="$partitioned[2]"/>
1218 <copy-of select="$partitioned[4]/node()"/>
1221 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1223 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1225 <copy-of select="@*"/>
1226 <apply-templates select="node()" mode="LesML:linkify"/>
1230 <variable name="processed">
1232 <copy-of select="@*"/>
1233 <copy-of select="$partitioned/node()"/>
1236 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1241 <copy-of select="."/>
1245 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
1247 <template match="node()" mode="LesML:strikethrough">
1248 <variable name="result">
1249 <apply-templates select="." mode="LesML:inline">
1250 <with-param name="element-name" select="'s'"/>
1251 <with-param name="element-namespace" select="'&xhtml;'"/>
1252 <with-param name="start-sigil" select="'⸠'"/>
1253 <with-param name="end-sigil" select="'⸡'"/>
1256 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
1258 <template match="node()" mode="LesML:underline">
1259 <variable name="result">
1260 <apply-templates select="." mode="LesML:inline">
1261 <with-param name="element-name" select="'u'"/>
1262 <with-param name="element-namespace" select="'&xhtml;'"/>
1263 <with-param name="start-sigil" select="'⸤'"/>
1264 <with-param name="end-sigil" select="'⸥'"/>
1267 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
1269 <template match="node()" mode="LesML:noted">
1270 <variable name="result">
1271 <apply-templates select="." mode="LesML:inline">
1272 <with-param name="element-name" select="'small'"/>
1273 <with-param name="element-namespace" select="'&xhtml;'"/>
1274 <with-param name="start-sigil" select="'⟦'"/>
1275 <with-param name="end-sigil" select="'⟧'"/>
1276 <with-param name="role" select="'note'"/>
1279 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
1281 <template match="node()" mode="LesML:parenthetical">
1282 <variable name="result">
1283 <apply-templates select="." mode="LesML:inline">
1284 <with-param name="element-name" select="'small'"/>
1285 <with-param name="element-namespace" select="'&xhtml;'"/>
1286 <with-param name="start-sigil" select="'⸨'"/>
1287 <with-param name="end-sigil" select="'⸩'"/>
1290 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
1292 <template match="node()" mode="LesML:code">
1293 <variable name="result">
1294 <apply-templates select="." mode="LesML:inline">
1295 <with-param name="element-name" select="'code'"/>
1296 <with-param name="element-namespace" select="'&xhtml;'"/>
1297 <with-param name="start-sigil" select="'`'"/>
1298 <with-param name="end-sigil" select="'´'"/>
1301 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
1303 <template match="node()" mode="LesML:titled">
1304 <variable name="result">
1305 <apply-templates select="." mode="LesML:inline">
1306 <with-param name="element-name" select="'cite'"/>
1307 <with-param name="element-namespace" select="'&xhtml;'"/>
1308 <with-param name="start-sigil" select="'⟪'"/>
1309 <with-param name="end-sigil" select="'⟫'"/>
1312 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named"/>
1314 <template match="node()" mode="LesML:named">
1315 <variable name="result">
1316 <apply-templates select="." mode="LesML:inline">
1317 <with-param name="element-name" select="'u'"/>
1318 <with-param name="element-namespace" select="'&xhtml;'"/>
1319 <with-param name="start-sigil" select="'⸶'"/>
1320 <with-param name="end-sigil" select="'⸷'"/>
1321 <with-param name="class" select="'name'"/>
1324 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
1326 <template match="node()" mode="LesML:offset">
1327 <variable name="result">
1328 <apply-templates select="." mode="LesML:inline">
1329 <with-param name="element-name" select="'i'"/>
1330 <with-param name="element-namespace" select="'&xhtml;'"/>
1331 <with-param name="start-sigil" select="'⟨'"/>
1332 <with-param name="end-sigil" select="'⟩'"/>
1333 <with-param name="langtag-supported" select="true()"/>
1336 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
1338 <template match="node()" mode="LesML:bolded">
1339 <variable name="result">
1340 <apply-templates select="." mode="LesML:inline">
1341 <with-param name="element-name" select="'b'"/>
1342 <with-param name="element-namespace" select="'&xhtml;'"/>
1343 <with-param name="start-sigil" select="'⦃'"/>
1344 <with-param name="end-sigil" select="'⦄'"/>
1347 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
1349 <template match="node()" mode="LesML:important">
1350 <variable name="result">
1351 <apply-templates select="." mode="LesML:inline">
1352 <with-param name="element-name" select="'strong'"/>
1353 <with-param name="element-namespace" select="'&xhtml;'"/>
1354 <with-param name="start-sigil" select="'☞'"/>
1355 <with-param name="end-sigil" select="'☜'"/>
1358 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
1360 <template match="node()" mode="LesML:emphasized">
1361 <apply-templates select="." mode="LesML:inline">
1362 <with-param name="element-name" select="'em'"/>
1363 <with-param name="element-namespace" select="'&xhtml;'"/>
1364 <with-param name="start-sigil" select="'⹐'"/>
1365 <with-param name="end-sigil" select="'⹑'"/>