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)=' ' or substring($text, 2, 1)='¶')">
18 <!ENTITY unsigiled-text "concat(translate(substring($text, 2, 1), ' ', ''), 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 <param name="LESML_SECTION_BREAK_CHARS" select="'*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'"/>
36 <template name="LesML:split">
37 <param name="source"/>
38 <param name="separator" select="'
'"/>
40 <when test="contains($source, $separator)">
42 <value-of select="substring-before($source, $separator)"/>
44 <call-template name="LesML:split">
45 <with-param name="source" select="substring-after($source, $separator)"/>
46 <with-param name="separator" select="$separator"/>
51 <value-of select="$source"/>
56 <template name="LesML:break-and-unescape">
57 <param name="source"/>
58 <variable name="broken-fragment">
59 <call-template name="LesML:split">
60 <with-param name="source" select="$source"/>
61 <with-param name="separator" select="'
'"/>
64 <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
65 <for-each select="$broken">
66 <call-template name="LesML:unescape">
67 <with-param name="source" select="string()"/>
69 <if test="position()!=count($broken)">
70 <element name="br" namespace="&xhtml;"/>
74 <template name="LesML:unescape">
75 <param name="source"/>
77 <when test="contains($source, '{U+')">
78 <variable name="after" select="substring-after($source, '{U+')"/>
80 <when test="contains($after, '}')">
81 <variable name="inner" select="substring-before($after, '}')"/>
82 <variable name="components">
83 <call-template name="LesML:split">
84 <with-param name="source" select="$inner"/>
85 <with-param name="separator" select="'.'"/>
88 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
89 <value-of select="substring-before($source, '{U+')"/>
91 <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
93 <value-of select="$inner"/>
95 <call-template name="LesML:unescape">
96 <with-param name="source" select="substring-after($after, '}')"/>
100 <for-each select="$component-nodes">
101 <text disable-output-escaping="yes">&#x</text>
102 <value-of select="."/>
105 <call-template name="LesML:unescape">
106 <with-param name="source" select="substring-after($after, '}')"/>
112 <value-of select="substring-before($source, '{U+')"/>
114 <call-template name="LesML:unescape">
115 <with-param name="source" select="$after"/>
121 <value-of select="$source"/>
125 <template name="LesML:comment-out">
126 <param name="source"/>
127 <variable name="comment-split-fragment">
128 <call-template name="LesML:split">
129 <with-param name="source" select="$source"/>
130 <with-param name="separator" select="'--'"/>
134 <for-each select="exsl:node-set($comment-split-fragment)/*">
135 <if test="string()='' or starts-with(., '‐')">
136 <text>͏</text>
138 <value-of select="."/>
139 <if test="substring(., string-length(.), 1)='‐'">
140 <text>͏</text>
143 <when test="position()!=last()">
144 <text>-͏-</text>
150 <template name="LesML:id-and-contents">
151 <param name="source"/>
152 <variable name="id-and-lang">
153 <if test="starts-with($source, '¶')">
155 <when test="contains($source, ' ')">
156 <value-of select="substring-before(substring-after($source, '¶'), ' ')"/>
159 <value-of select="substring-after($source, '¶')"/>
164 <variable name="restoftext">
166 <when test="starts-with($source, '¶') and contains($source, ' ')">
167 <value-of select="substring-after($source, ' ')"/>
169 <when test="starts-with($source, '¶')"/>
171 <value-of select="$source"/>
175 <variable name="maybe-langtag">
176 <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
177 <variable name="split-tag-fragment">
178 <call-template name="LesML:split">
179 <with-param name="source" select="substring($id-and-lang, 2, string-length($id-and-lang)-2)"/>
180 <with-param name="separator" select="'@'"/>
183 <value-of select="exsl:node-set($split-tag-fragment)/*[last()]"/>
186 <variable name="langtag">
187 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
188 <value-of select="$maybe-langtag"/>
193 <when test="string($langtag)!=''">
194 <value-of select="substring($id-and-lang, 1, string-length($id-and-lang)-(string-length($langtag)+2))"/>
197 <value-of select="$id-and-lang"/>
201 <if test="string($id)!=''">
202 <attribute name="id">
203 <value-of select="$id"/>
206 <if test="string($langtag)!=''">
207 <attribute name="lang">
208 <value-of select="$langtag"/>
210 <attribute name="xml:lang">
211 <value-of select="$langtag"/>
214 <value-of select="$restoftext"/>
216 <template name="LesML:parse">
217 <param name="lines" select="/.."/>
218 <param name="parent-params" select="/.."/>
219 <variable name="first-line" select="$lines[1]"/>
220 <variable name="shebang">
221 <if test="starts-with($first-line, '#!lesml')">
222 <value-of select="$first-line"/>
225 <variable name="params-string">
227 <when test="starts-with($shebang, '#!lesml@')">
228 <value-of select="substring-after($shebang, '$')"/>
231 <value-of select="substring-after($shebang, '#!lesml')"/>
235 <variable name="params-fragment">
237 <when test="$shebang!=''">
239 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
245 <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
249 <for-each select="exslstr:tokenize($params-string)">
251 <when test="contains(., '=')">
254 <value-of select="substring-before(., '=')"/>
257 <value-of select="substring-after(., '=')"/>
264 <value-of select="."/>
273 <when test="$parent-params">
274 <copy-of select="$parent-params"/>
281 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
282 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
283 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
284 <variable name="doclines" select="exslset:leading($noshebang, $docsep)"/>
285 <if test="starts-with($first-line, '##') and $first-line!='##'">
286 <call-template name="LesML:comment-out">
287 <with-param name="source" select="substring-after($first-line, '##')"/>
290 <if test="$doclines[normalize-space()!='']">
291 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
292 <element name="article" namespace="&xhtml;">
293 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
294 <attribute name="lang">
295 <value-of select="following-sibling::html:dd"/>
297 <attribute name="xml:lang">
298 <value-of select="following-sibling::html:dd"/>
301 <for-each select="$params/html:div/html:dt[string()='profile']">
302 <attribute name="data-lesml-profile">
303 <value-of select="following-sibling::html:dd"/>
306 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
307 <element name="footer" namespace="&xhtml;">
308 <attribute name="class">
311 <for-each select="$record-separators">
312 <variable name="position" select="position()"/>
313 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
314 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)"/>
316 <element name="dl" namespace="&xhtml;">
317 <for-each select="$fields">
319 <when test="starts-with(., ' ') and exslset:leading($fields, .)"/>
321 <variable name="next" select="exslset:intersection(following-sibling::*[not(starts-with(., ' '))][1], $fields)"/>
322 <element name="div" namespace="&xhtml;">
323 <element name="dt" namespace="&xhtml;">
324 <value-of select="normalize-space(substring-before(., ':'))"/>
326 <element name="dd" namespace="&xhtml;">
327 <variable name="firstline">
329 <when test="contains(., ':')">
330 <value-of select="normalize-space(substring-after(., ':'))"/>
333 <value-of select="normalize-space(.)"/>
338 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
339 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
342 <value-of select="$firstline"/>
345 <for-each select="exslset:intersection(following-sibling::*[starts-with(., ' ')], exslset:leading($fields, $next))">
346 <variable name="nextline" select="normalize-space(.)"/>
348 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
349 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
352 <value-of select="$nextline"/>
364 <call-template name="LesML:comment-out">
365 <with-param name="source" select="substring-after(., '%%')"/>
371 <element name="div" namespace="&xhtml;">
372 <attribute name="class">
375 <call-template name="LesML:paragraphize">
376 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
382 <call-template name="LesML:parse">
383 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
384 <with-param name="parent-params" select="$params"/>
388 <template name="LesML:block">
389 <param name="lines" select="/.."/>
390 <variable name="last-lines" select="$lines[normalize-space()!='' and (normalize-space(following-sibling::*[1])='' or position()=last())]"/>
391 <for-each select="$last-lines">
392 <variable name="position" select="position()"/>
393 <variable name="prev-last" select="$last-lines[($position)-1]"/>
394 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
395 <variable name="prefix" select="substring(translate(., ' 	', ''), 1, 1)"/>
396 <variable name="all-prefixed" select="not($linespans[not(starts-with(translate(., ' 	', ''), $prefix))])"/>
397 <variable name="quoted" select="$all-prefixed and $prefix='»'"/>
398 <variable name="bracketed" select="$all-prefixed and $prefix=']'"/>
400 <when test="count($linespans)=1 and translate(., concat($LESML_SECTION_BREAK_CHARS, ' 	'), '')=''">
401 <element name="hr" namespace="&xhtml;"/>
403 <when test="$quoted or $bracketed">
404 <variable name="innerlines-fragment">
405 <for-each select="$linespans">
406 <variable name="inner">
407 <value-of select="substring-after(., $prefix)"/>
411 <when test="starts-with($inner, ' ') or starts-with($inner, '	')">
412 <value-of select="substring($inner, 1+count(exslstr:tokenize($inner, '')[normalize-space()='' and not(preceding-sibling::*[normalize-space()!=''])]))"/>
415 <value-of select="$inner"/>
421 <variable name="blocked-fragment">
422 <call-template name="LesML:block">
423 <with-param name="lines" select="exsl:node-set($innerlines-fragment)/*"/>
426 <variable name="innerpars" select="exsl:node-set($blocked-fragment)/node()"/>
428 <when test="$quoted and $innerpars[position()=last() and self::html:footer]">
429 <element name="figure" namespace="&xhtml;">
430 <element name="blockquote" namespace="&xhtml;">
431 <copy-of select="$innerpars[position()!=last()]"/>
433 <element name="figcaption" namespace="&xhtml;">
434 <copy-of select="$innerpars[last()]/node()"/>
438 <when test="$quoted">
439 <element name="blockquote" namespace="&xhtml;">
440 <copy-of select="$innerpars"/>
443 <when test="$bracketed">
444 <element name="footer" namespace="&xhtml;">
445 <copy-of select="$innerpars"/>
451 <variable name="preformatted" select="$all-prefixed and $prefix='|'"/>
452 <variable name="text">
453 <for-each select="$linespans">
455 <when test="$preformatted">
456 <value-of select="substring-after(., '|')"/>
459 <value-of select="normalize-space()"/>
462 <if test="position()!=count($linespans)">
464 <when test="$preformatted">
475 <when test="$preformatted">
476 <element name="pre" namespace="&xhtml;">
477 <call-template name="LesML:id-and-contents">
478 <with-param name="source" select="$text"/>
482 <when test="string($text)=''"/>
483 <when test="starts-with($text, '⁌') and &sigiled-text;">
484 <element name="h1" namespace="&xhtml;">
485 <call-template name="LesML:id-and-contents">
486 <with-param name="source" select="&unsigiled-text;"/>
490 <when test="starts-with($text, '§') and &sigiled-text;">
491 <element name="h2" namespace="&xhtml;">
492 <call-template name="LesML:id-and-contents">
493 <with-param name="source" select="&unsigiled-text;"/>
497 <when test="starts-with($text, '❦') and &sigiled-text;">
498 <element name="h3" namespace="&xhtml;">
499 <call-template name="LesML:id-and-contents">
500 <with-param name="source" select="&unsigiled-text;"/>
504 <when test="starts-with($text, '✠') and &sigiled-text;">
505 <element name="h4" namespace="&xhtml;">
506 <call-template name="LesML:id-and-contents">
507 <with-param name="source" select="&unsigiled-text;"/>
511 <when test="starts-with($text, '•') and &sigiled-text;">
512 <element name="li" namespace="&xhtml;">
513 <attribute name="class">
514 <text>unordered</text>
516 <attribute name="data-level">
519 <element name="p" namespace="&xhtml;">
520 <call-template name="LesML:id-and-contents">
521 <with-param name="source" select="&unsigiled-text;"/>
526 <when test="starts-with($text, '🔢') and &sigiled-text;">
527 <element name="li" namespace="&xhtml;">
528 <attribute name="class">
531 <attribute name="data-level">
534 <element name="p" namespace="&xhtml;">
535 <call-template name="LesML:id-and-contents">
536 <with-param name="source" select="&unsigiled-text;"/>
541 <when test="starts-with($text, '◦') and &sigiled-text;">
542 <element name="li" namespace="&xhtml;">
543 <attribute name="class">
544 <text>unordered</text>
546 <attribute name="data-level">
549 <element name="p" namespace="&xhtml;">
550 <call-template name="LesML:id-and-contents">
551 <with-param name="source" select="&unsigiled-text;"/>
556 <when test="starts-with($text, '🔠') and &sigiled-text;">
557 <element name="li" namespace="&xhtml;">
558 <attribute name="class">
561 <attribute name="data-level">
564 <element name="p" namespace="&xhtml;">
565 <call-template name="LesML:id-and-contents">
566 <with-param name="source" select="&unsigiled-text;"/>
571 <when test="starts-with($text, '▪') and &sigiled-text;">
572 <element name="li" namespace="&xhtml;">
573 <attribute name="class">
574 <text>unordered</text>
576 <attribute name="data-level">
579 <element name="p" namespace="&xhtml;">
580 <call-template name="LesML:id-and-contents">
581 <with-param name="source" select="&unsigiled-text;"/>
586 <when test="starts-with($text, '🔡') and &sigiled-text;">
587 <element name="li" namespace="&xhtml;">
588 <attribute name="class">
591 <attribute name="data-level">
594 <element name="p" namespace="&xhtml;">
595 <call-template name="LesML:id-and-contents">
596 <with-param name="source" select="&unsigiled-text;"/>
601 <when test="starts-with($text, '⁃') and &sigiled-text;">
602 <element name="li" namespace="&xhtml;">
603 <attribute name="class">
604 <text>unordered</text>
606 <attribute name="data-level">
609 <element name="p" namespace="&xhtml;">
610 <call-template name="LesML:id-and-contents">
611 <with-param name="source" select="&unsigiled-text;"/>
616 <when test="starts-with($text, '🔣') and &sigiled-text;">
617 <element name="li" namespace="&xhtml;">
618 <attribute name="class">
621 <attribute name="data-level">
624 <element name="p" namespace="&xhtml;">
625 <call-template name="LesML:id-and-contents">
626 <with-param name="source" select="&unsigiled-text;"/>
631 <when test="starts-with($text, '🛈') and &sigiled-text;">
632 <element name="div" namespace="&xhtml;">
633 <attribute name="role">
636 <attribute name="class">
639 <element name="p" namespace="&xhtml;">
640 <call-template name="LesML:id-and-contents">
641 <with-param name="source" select="&unsigiled-text;"/>
646 <when test="starts-with($text, '⯑') and &sigiled-text;">
647 <element name="div" namespace="&xhtml;">
648 <attribute name="role">
651 <attribute name="class">
654 <element name="p" namespace="&xhtml;">
655 <call-template name="LesML:id-and-contents">
656 <with-param name="source" select="&unsigiled-text;"/>
661 <when test="starts-with($text, '⚠︎') and &sigiled-text;">
662 <element name="div" namespace="&xhtml;">
663 <attribute name="role">
666 <attribute name="class">
669 <element name="p" namespace="&xhtml;">
670 <call-template name="LesML:id-and-contents">
671 <with-param name="source" select="&unsigiled-text;"/>
676 <when test="starts-with($text, '※') and &sigiled-text;">
677 <element name="div" namespace="&xhtml;">
678 <attribute name="role">
681 <attribute name="class">
684 <element name="p" namespace="&xhtml;">
685 <call-template name="LesML:id-and-contents">
686 <with-param name="source" select="&unsigiled-text;"/>
691 <when test="starts-with($text, '☡') and &sigiled-text;">
692 <element name="div" namespace="&xhtml;">
693 <attribute name="role">
696 <attribute name="class">
699 <element name="p" namespace="&xhtml;">
700 <call-template name="LesML:id-and-contents">
701 <with-param name="source" select="&unsigiled-text;"/>
706 <when test="starts-with($text, '⋯') and &sigiled-text;">
707 <element name="div" namespace="&xhtml;">
708 <attribute name="class">
709 <text>continuation</text>
711 <element name="p" namespace="&xhtml;">
712 <call-template name="LesML:id-and-contents">
713 <with-param name="source" select="&unsigiled-text;"/>
718 <when test="starts-with($text, '#') and &sigiled-text;">
719 <call-template name="LesML:comment-out">
720 <with-param name="source" select="&unsigiled-text;"/>
724 <element name="p" namespace="&xhtml;">
725 <call-template name="LesML:id-and-contents">
726 <with-param name="source" select="$text"/>
735 <template name="LesML:paragraphize">
736 <param name="lines" select="/.."/>
737 <variable name="blocked-fragment">
738 <call-template name="LesML:block">
739 <with-param name="lines" select="$lines"/>
742 <variable name="inlined-fragment">
743 <apply-templates select="exsl:node-set($blocked-fragment)/node()" mode="LesML:comment"/>
745 <apply-templates select="exsl:node-set($inlined-fragment)/node()" mode="LesML:finalize-tree"/>
747 <template match="html:script[@type='text/lesml']">
748 <variable name="lines-fragment">
749 <call-template name="LesML:split">
750 <with-param name="source">
751 <for-each select=".//text()">
752 <value-of select="."/>
757 <element name="div" namespace="&xhtml;">
758 <call-template name="LesML:parse">
759 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
763 <template match="node()" mode="LesML:finalize-attributes">
764 <variable name="notattr" select="following-sibling::node()[not(self::text() and translate(., ' 	', '')='' or self::LesML:attribute)]"/>
765 <for-each select="(.|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
766 <copy-of select="."/>
767 <if test="local-name()='lang' and namespace-uri()=''">
768 <attribute name="xml:lang">
769 <value-of select="."/>
774 <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"/>
775 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize-tree" priority="1">
776 <element name="span" namespace="&xhtml;">
777 <apply-templates select="." mode="LesML:finalize-attributes"/>
778 <if test="self::text()">
779 <call-template name="LesML:break-and-unescape">
780 <with-param name="source" select="string(.)"/>
785 <template match="html:div" mode="LesML:finalize-tree">
786 <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)]">
787 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
789 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
790 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
791 <apply-templates select="node()" mode="LesML:finalize-tree"/>
796 <template match="html:li" mode="LesML:finalize-tree">
797 <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)]">
798 <apply-templates select="." mode="LesML:finalize-list"/>
801 <template match="html:li" mode="LesML:finalize-list">
802 <param name="parent-level" select="0"/>
803 <variable name="current-class" select="string(@class)"/>
804 <variable name="current-level" select="number(@data-level)"/>
805 <variable name="wrapper">
807 <when test="@class='ordered'">
815 <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]"/>
816 <element name="{$wrapper}" namespace="&xhtml;">
817 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @data-level=$current-level]">
818 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
820 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
821 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
822 <apply-templates select="node()" mode="LesML:finalize-tree"/>
824 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
825 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
826 <with-param name="parent-level" select="$current-level"/>
832 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
833 <apply-templates select="$notinlist" mode="LesML:finalize-list">
834 <with-param name="parent-level" select="$parent-level"/>
838 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finalize-tree">
839 <value-of select="."/>
841 <template match="text()" mode="LesML:finalize-tree">
842 <call-template name="LesML:break-and-unescape">
843 <with-param name="source" select="string(.)"/>
846 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
848 <apply-templates select="." mode="LesML:finalize-attributes"/>
849 <apply-templates select="node()" mode="LesML:finalize-tree"/>
852 <template match="node()" mode="LesML:comment">
853 <variable name="result">
855 <when test="self::*">
856 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
857 <variable name="after-start">
858 <if test="$start-node">
859 <value-of select="substring-after($start-node, '⌦')"/>
862 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
864 <when test="$start-node and $has-end-node">
865 <variable name="following">
866 <value-of select="$after-start"/>
867 <copy-of select="$start-node/following-sibling::node()"/>
869 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
870 <variable name="comment">
871 <for-each select="$end-node/preceding-sibling::node()">
872 <value-of select="."/>
874 <value-of select="substring-before($end-node, '⌫')"/>
876 <variable name="rest-fragment">
877 <element name="span" namespace="&xhtml;">
878 <value-of select="substring-after($end-node, '⌫')"/>
879 <copy-of select="$end-node/following-sibling::node()"/>
882 <variable name="commented-rest-fragment">
883 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment"/>
886 <copy-of select="@*"/>
887 <copy-of select="$start-node/preceding-sibling::node()"/>
888 <copy-of select="substring-before($start-node, '⌦')"/>
889 <call-template name="LesML:comment-out">
890 <with-param name="source" select="string($comment)"/>
892 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
897 <copy-of select="@*"/>
898 <apply-templates select="node()" mode="LesML:comment"/>
903 <when test="self::text()[contains(., '⌧')]">
904 <variable name="split-fragment">
905 <call-template name="LesML:split">
906 <with-param name="source" select="string()"/>
907 <with-param name="separator" select="'⌧'"/>
910 <for-each select="exsl:node-set($split-fragment)/node()">
911 <value-of select="."/>
912 <if test="position()!=last()">
913 <call-template name="LesML:comment-out"/>
918 <copy-of select="."/>
922 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:attrify"/>
924 <template match="node()" mode="LesML:inline">
925 <param name="element-name"/>
926 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
927 <param name="start-sigil"/>
928 <param name="end-sigil"/>
929 <param name="class"/>
932 <when test="self::*">
933 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
934 <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))"/>
936 <when test="$end-node and $has-start-node">
937 <variable name="preceding">
938 <copy-of select="$end-node/preceding-sibling::node()"/>
939 <value-of select="substring-before($end-node, $end-sigil)"/>
941 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
942 <variable name="start-tokens-fragment">
943 <call-template name="LesML:split">
944 <with-param name="source" select="string($start-node)"/>
945 <with-param name="separator" select="$start-sigil"/>
948 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
949 <variable name="wrapped">
951 <copy-of select="@*"/>
952 <copy-of select="$start-node/preceding-sibling::node()"/>
953 <for-each select="$start-tokens[position()!=last()]">
954 <value-of select="."/>
955 <if test="position()!=last()">
956 <value-of select="$start-sigil"/>
959 <element name="{$element-name}" namespace="{$element-namespace}">
960 <if test="string($role)!=''">
961 <attribute name="role">
962 <value-of select="$role"/>
965 <if test="string($class)!=''">
966 <attribute name="class">
967 <value-of select="$class"/>
970 <value-of select="$start-tokens[last()]"/>
971 <copy-of select="$start-node/following-sibling::node()"/>
973 <value-of select="substring-after($end-node, $end-sigil)"/>
974 <copy-of select="$end-node/following-sibling::node()"/>
977 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
978 <with-param name="element-name" select="$element-name"/>
979 <with-param name="element-namespace" select="$element-namespace"/>
980 <with-param name="start-sigil" select="$start-sigil"/>
981 <with-param name="end-sigil" select="$end-sigil"/>
982 <with-param name="role" select="$role"/>
987 <copy-of select="@*"/>
988 <apply-templates select="node()" mode="LesML:inline">
989 <with-param name="element-name" select="$element-name"/>
990 <with-param name="element-namespace" select="$element-namespace"/>
991 <with-param name="start-sigil" select="$start-sigil"/>
992 <with-param name="end-sigil" select="$end-sigil"/>
993 <with-param name="role" select="$role"/>
1000 <copy-of select="."/>
1004 <template match="*" mode="LesML:partition">
1005 <param name="start-sigil"/>
1006 <param name="end-sigil"/>
1007 <param name="separator"/>
1008 <param name="ncname-keys" select="false()"/>
1009 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1010 <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))"/>
1012 <when test="$end-node and $has-start-node">
1013 <variable name="preceding">
1014 <copy-of select="$end-node/preceding-sibling::node()"/>
1015 <value-of select="substring-before($end-node, $end-sigil)"/>
1017 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil) and not(following-sibling::*)][last()]"/>
1018 <variable name="start-tokens-fragment">
1019 <call-template name="LesML:split">
1020 <with-param name="source" select="string($start-node)"/>
1021 <with-param name="separator" select="$start-sigil"/>
1024 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
1025 <variable name="innards">
1026 <value-of select="$start-tokens[last()]"/>
1027 <for-each select="$start-node/following-sibling::node()">
1028 <value-of select="."/>
1032 <when test="contains($innards, $separator)">
1033 <variable name="keyval-fragment">
1034 <call-template name="LesML:split">
1035 <with-param name="source" select="$innards"/>
1036 <with-param name="separator" select="$separator"/>
1039 <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
1040 <variable name="key">
1042 <when test="$ncname-keys">
1043 <value-of select="$keyval[1]"/>
1046 <for-each select="$keyval[position()!=last()]">
1047 <value-of select="."/>
1048 <if test="position()!=last()">
1049 <value-of select="$separator"/>
1055 <variable name="value">
1057 <when test="$ncname-keys">
1058 <for-each select="$keyval[position()!=1]">
1059 <value-of select="."/>
1060 <if test="position()!=last()">
1061 <value-of select="$separator"/>
1066 <value-of select="$keyval[last()]"/>
1071 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key), ' /([,*', '')=string($key) and exsldyn:evaluate(concat('not(self::html:', $key, ')'))]">
1072 <element name="span" namespace="&xhtml;">
1073 <copy-of select="$start-node/preceding-sibling::node()"/>
1074 <for-each select="$start-tokens[position()!=last()]">
1075 <value-of select="."/>
1076 <if test="position()!=last()">
1077 <value-of select="$start-sigil"/>
1081 <element name="span" namespace="&xhtml;">
1082 <value-of select="$key"/>
1084 <element name="span" namespace="&xhtml;">
1085 <value-of select="$value"/>
1087 <element name="span" namespace="&xhtml;">
1088 <value-of select="substring-after($end-node, $end-sigil)"/>
1089 <copy-of select="$end-node/following-sibling::node()"/>
1093 <element name="span" namespace="&xhtml;">
1094 <copy-of select="$start-node/preceding-sibling::node()"/>
1095 <for-each select="$start-tokens[position()!=last()]">
1096 <value-of select="."/>
1097 <if test="position()!=last()">
1098 <value-of select="$start-sigil"/>
1101 <processing-instruction name="LesML-Token-Escape">
1102 <value-of select="$start-sigil"/>
1103 </processing-instruction>
1104 <value-of select="$start-tokens[last()]"/>
1105 <value-of select="$start-node/following-sibling::node()"/>
1106 <value-of select="$end-sigil"/>
1107 <value-of select="substring-after($end-node, $end-sigil)"/>
1108 <copy-of select="$end-node/following-sibling::node()"/>
1114 <element name="span" namespace="&xhtml;">
1115 <copy-of select="$start-node/preceding-sibling::node()"/>
1116 <for-each select="$start-tokens[position()!=last()]">
1117 <value-of select="."/>
1118 <if test="position()!=last()">
1119 <value-of select="$start-sigil"/>
1122 <processing-instruction name="LesML-Token-Escape">
1123 <value-of select="$start-sigil"/>
1124 </processing-instruction>
1125 <value-of select="$start-tokens[last()]"/>
1126 <value-of select="$start-node/following-sibling::node()"/>
1127 <value-of select="$end-sigil"/>
1128 <value-of select="substring-after($end-node, $end-sigil)"/>
1129 <copy-of select="$end-node/following-sibling::node()"/>
1134 <when test="$end-node">
1135 <element name="span" namespace="&xhtml;">
1136 <copy-of select="$end-node/preceding-sibling::node()"/>
1137 <value-of select="substring-before($end-node, $end-sigil)"/>
1138 <processing-instruction name="LesML-Token-Escape">
1139 <value-of select="$end-sigil"/>
1140 </processing-instruction>
1141 <value-of select="substring-after($end-node, $end-sigil)"/>
1142 <copy-of select="$end-node/following-sibling::node()"/>
1146 <processing-instruction name="LesML-All-Done"/>
1150 <template match="node()" mode="LesML:attrify">
1151 <variable name="result">
1153 <when test="self::*">
1154 <variable name="partitioned-fragment">
1155 <apply-templates mode="LesML:partition" select=".">
1156 <with-param name="start-sigil" select="'{@'"/>
1157 <with-param name="end-sigil" select="'"}'"/>
1158 <with-param name="separator" select="'="'"/>
1159 <with-param name="ncname-keys" select="true()"/>
1162 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1164 <when test="count($partitioned)>1">
1165 <variable name="processed">
1167 <copy-of select="@*"/>
1168 <copy-of select="$partitioned[1]/node()"/>
1169 <element name="LesML:attribute" namespace="&LesML;">
1170 <attribute name="{$partitioned[2]}">
1171 <value-of select="$partitioned[3]"/>
1174 <copy-of select="$partitioned[4]/node()"/>
1177 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1179 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1181 <copy-of select="@*"/>
1182 <apply-templates select="node()" mode="LesML:attrify"/>
1186 <variable name="processed">
1188 <copy-of select="@*"/>
1189 <copy-of select="$partitioned/node()"/>
1192 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1197 <copy-of select="."/>
1201 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify"/>
1203 <template match="node()" mode="LesML:linkify">
1204 <variable name="result">
1206 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1208 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1211 <when test="self::*">
1212 <variable name="partitioned-fragment">
1213 <apply-templates mode="LesML:partition" select=".">
1214 <with-param name="start-sigil" select="'{🔗'"/>
1215 <with-param name="end-sigil" select="'>}'"/>
1216 <with-param name="separator" select="'<'"/>
1219 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1221 <when test="count($partitioned)>1">
1222 <variable name="processed">
1224 <copy-of select="@*"/>
1225 <copy-of select="$partitioned[1]/node()"/>
1226 <element name="a" namespace="&xhtml;">
1227 <attribute name="href">
1228 <value-of select="$partitioned[3]"/>
1230 <processing-instruction name="LesML-All-Done"/>
1232 <when test="string($partitioned[2])=''">
1233 <value-of select="$partitioned[3]"/>
1236 <value-of select="$partitioned[2]"/>
1240 <copy-of select="$partitioned[4]/node()"/>
1243 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1245 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1247 <copy-of select="@*"/>
1248 <apply-templates select="node()" mode="LesML:linkify"/>
1252 <variable name="processed">
1254 <copy-of select="@*"/>
1255 <copy-of select="$partitioned/node()"/>
1258 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1263 <copy-of select="."/>
1267 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
1269 <template match="node()" mode="LesML:strikethrough">
1270 <variable name="result">
1271 <apply-templates select="." mode="LesML:inline">
1272 <with-param name="element-name" select="'s'"/>
1273 <with-param name="element-namespace" select="'&xhtml;'"/>
1274 <with-param name="start-sigil" select="'⸠'"/>
1275 <with-param name="end-sigil" select="'⸡'"/>
1278 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
1280 <template match="node()" mode="LesML:underline">
1281 <variable name="result">
1282 <apply-templates select="." mode="LesML:inline">
1283 <with-param name="element-name" select="'u'"/>
1284 <with-param name="element-namespace" select="'&xhtml;'"/>
1285 <with-param name="start-sigil" select="'⸤'"/>
1286 <with-param name="end-sigil" select="'⸥'"/>
1289 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
1291 <template match="node()" mode="LesML:noted">
1292 <variable name="result">
1293 <apply-templates select="." mode="LesML:inline">
1294 <with-param name="element-name" select="'small'"/>
1295 <with-param name="element-namespace" select="'&xhtml;'"/>
1296 <with-param name="start-sigil" select="'⟦'"/>
1297 <with-param name="end-sigil" select="'⟧'"/>
1298 <with-param name="role" select="'note'"/>
1301 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
1303 <template match="node()" mode="LesML:parenthetical">
1304 <variable name="result">
1305 <apply-templates select="." mode="LesML:inline">
1306 <with-param name="element-name" select="'small'"/>
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:code"/>
1314 <template match="node()" mode="LesML:code">
1315 <variable name="result">
1316 <apply-templates select="." mode="LesML:inline">
1317 <with-param name="element-name" select="'code'"/>
1318 <with-param name="element-namespace" select="'&xhtml;'"/>
1319 <with-param name="start-sigil" select="'`'"/>
1320 <with-param name="end-sigil" select="'´'"/>
1323 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
1325 <template match="node()" mode="LesML:titled">
1326 <variable name="result">
1327 <apply-templates select="." mode="LesML:inline">
1328 <with-param name="element-name" select="'cite'"/>
1329 <with-param name="element-namespace" select="'&xhtml;'"/>
1330 <with-param name="start-sigil" select="'⟪'"/>
1331 <with-param name="end-sigil" select="'⟫'"/>
1334 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named"/>
1336 <template match="node()" mode="LesML:named">
1337 <variable name="result">
1338 <apply-templates select="." mode="LesML:inline">
1339 <with-param name="element-name" select="'u'"/>
1340 <with-param name="element-namespace" select="'&xhtml;'"/>
1341 <with-param name="start-sigil" select="'⸶'"/>
1342 <with-param name="end-sigil" select="'⸷'"/>
1343 <with-param name="class" select="'name'"/>
1346 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
1348 <template match="node()" mode="LesML:offset">
1349 <variable name="result">
1350 <apply-templates select="." mode="LesML:inline">
1351 <with-param name="element-name" select="'i'"/>
1352 <with-param name="element-namespace" select="'&xhtml;'"/>
1353 <with-param name="start-sigil" select="'⟨'"/>
1354 <with-param name="end-sigil" select="'⟩'"/>
1357 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
1359 <template match="node()" mode="LesML:bolded">
1360 <variable name="result">
1361 <apply-templates select="." mode="LesML:inline">
1362 <with-param name="element-name" select="'b'"/>
1363 <with-param name="element-namespace" select="'&xhtml;'"/>
1364 <with-param name="start-sigil" select="'⦃'"/>
1365 <with-param name="end-sigil" select="'⦄'"/>
1368 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
1370 <template match="node()" mode="LesML:important">
1371 <variable name="result">
1372 <apply-templates select="." mode="LesML:inline">
1373 <with-param name="element-name" select="'strong'"/>
1374 <with-param name="element-namespace" select="'&xhtml;'"/>
1375 <with-param name="start-sigil" select="'☞'"/>
1376 <with-param name="end-sigil" select="'☜'"/>
1379 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
1381 <template match="node()" mode="LesML:emphasized">
1382 <apply-templates select="." mode="LesML:inline">
1383 <with-param name="element-name" select="'em'"/>
1384 <with-param name="element-namespace" select="'&xhtml;'"/>
1385 <with-param name="start-sigil" select="'⹐'"/>
1386 <with-param name="end-sigil" select="'⹑'"/>