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 <processing-instruction name="LesML-Continuation"/>
709 <element name="p" namespace="&xhtml;">
710 <call-template name="LesML:id-and-contents">
711 <with-param name="source" select="&unsigiled-text;"/>
716 <when test="starts-with($text, '#') and &sigiled-text;">
717 <call-template name="LesML:comment-out">
718 <with-param name="source" select="&unsigiled-text;"/>
722 <element name="p" namespace="&xhtml;">
723 <call-template name="LesML:id-and-contents">
724 <with-param name="source" select="$text"/>
733 <template name="LesML:paragraphize">
734 <param name="lines" select="/.."/>
735 <variable name="blocked-fragment">
736 <call-template name="LesML:block">
737 <with-param name="lines" select="$lines"/>
740 <variable name="inlined-fragment">
741 <apply-templates select="exsl:node-set($blocked-fragment)/node()" mode="LesML:comment"/>
743 <apply-templates select="exsl:node-set($inlined-fragment)/node()" mode="LesML:finalize-tree"/>
745 <template match="html:script[@type='text/lesml']">
746 <variable name="lines-fragment">
747 <call-template name="LesML:split">
748 <with-param name="source">
749 <for-each select=".//text()">
750 <value-of select="."/>
755 <element name="div" namespace="&xhtml;">
756 <call-template name="LesML:parse">
757 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
761 <template match="node()" mode="LesML:finalize-attributes">
762 <variable name="notattr" select="following-sibling::node()[not(self::text() and translate(., ' 	', '')='' or self::LesML:attribute)]"/>
763 <for-each select="(.|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
764 <copy-of select="."/>
765 <if test="local-name()='lang' and namespace-uri()=''">
766 <attribute name="xml:lang">
767 <value-of select="."/>
772 <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"/>
773 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize-tree" priority="1">
774 <element name="span" namespace="&xhtml;">
775 <apply-templates select="." mode="LesML:finalize-attributes"/>
776 <if test="self::text()">
777 <call-template name="LesML:break-and-unescape">
778 <with-param name="source" select="string(.)"/>
783 <template match="html:div" mode="LesML:finalize-tree">
784 <if test="not(processing-instruction()[local-name()='LesML-Continuation']) or not(preceding-sibling::node()[position()=1 and self::html:* and contains(' div li h1 h2 h3 h4 h5 h6 ', local-name())])">
785 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
787 <when test="processing-instruction()[local-name()='LesML-Continuation'] and $notcontinuation[self::html:* and contains(' h1 h2 h3 h4 h5 h6 ', local-name())]">
788 <variable name="notcontinuation2" select="$notcontinuation/following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
789 <element name="hgroup" namespace="&xhtml;">
790 <apply-templates select="node()" mode="LesML:finalize-tree"/>
791 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation2)">
793 <when test="self::html:div">
794 <apply-templates select="node()" mode="LesML:finalize-tree"/>
798 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
806 <apply-templates select="node()" mode="LesML:finalize-tree"/>
807 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
808 <apply-templates select="node()" mode="LesML:finalize-tree"/>
814 <template match="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6" mode="LesML:finalize-tree">
815 <if test="not(preceding-sibling::node()[position()=1 and self::html:div/processing-instruction()[local-name()='LesML-Continuation']]) or preceding-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][position()=1 and self::html:* and contains(' h1 h2 h3 h4 h5 h6 ', local-name())]">
817 <when test="following-sibling::node()[position()=1 and self::html:div]/processing-instruction()[local-name()='LesML-Continuation']">
818 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
819 <element name="hgroup" namespace="&xhtml;">
821 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
823 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
824 <apply-templates select="node()" mode="LesML:finalize-tree"/>
830 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
836 <template match="html:li" mode="LesML:finalize-tree">
837 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[not(preceding-sibling::* and self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][position()=1 and not(self::html:li)]">
838 <apply-templates select="." mode="LesML:finalize-list"/>
841 <template match="html:li" mode="LesML:finalize-list">
842 <param name="parent-level" select="0"/>
843 <variable name="current-class" select="string(@class)"/>
844 <variable name="current-level" select="number(@data-level)"/>
845 <variable name="wrapper">
847 <when test="@class='ordered'">
855 <variable name="notinlist" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'] or self::html:li and (@data-level>$current-level or @data-level=$current-level and @class=$current-class))][1]"/>
856 <element name="{$wrapper}" namespace="&xhtml;">
857 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @data-level=$current-level]">
858 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
860 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
861 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
862 <apply-templates select="node()" mode="LesML:finalize-tree"/>
864 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
865 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
866 <with-param name="parent-level" select="$current-level"/>
872 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
873 <apply-templates select="$notinlist" mode="LesML:finalize-list">
874 <with-param name="parent-level" select="$parent-level"/>
878 <template match="processing-instruction()[local-name()='LesML-Continuation']" mode="LesML:finalize-tree"/>
879 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finalize-tree">
880 <value-of select="."/>
882 <template match="text()" mode="LesML:finalize-tree">
883 <call-template name="LesML:break-and-unescape">
884 <with-param name="source" select="string(.)"/>
887 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
889 <apply-templates select="." mode="LesML:finalize-attributes"/>
890 <apply-templates select="node()" mode="LesML:finalize-tree"/>
893 <template match="node()" mode="LesML:comment">
894 <variable name="result">
896 <when test="self::*">
897 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
898 <variable name="after-start">
899 <if test="$start-node">
900 <value-of select="substring-after($start-node, '⌦')"/>
903 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
905 <when test="$start-node and $has-end-node">
906 <variable name="following">
907 <value-of select="$after-start"/>
908 <copy-of select="$start-node/following-sibling::node()"/>
910 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
911 <variable name="comment">
912 <for-each select="$end-node/preceding-sibling::node()">
913 <value-of select="."/>
915 <value-of select="substring-before($end-node, '⌫')"/>
917 <variable name="rest-fragment">
918 <element name="span" namespace="&xhtml;">
919 <value-of select="substring-after($end-node, '⌫')"/>
920 <copy-of select="$end-node/following-sibling::node()"/>
923 <variable name="commented-rest-fragment">
924 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment"/>
927 <copy-of select="@*"/>
928 <copy-of select="$start-node/preceding-sibling::node()"/>
929 <copy-of select="substring-before($start-node, '⌦')"/>
930 <call-template name="LesML:comment-out">
931 <with-param name="source" select="string($comment)"/>
933 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
938 <copy-of select="@*"/>
939 <apply-templates select="node()" mode="LesML:comment"/>
944 <when test="self::text()[contains(., '⌧')]">
945 <variable name="split-fragment">
946 <call-template name="LesML:split">
947 <with-param name="source" select="string()"/>
948 <with-param name="separator" select="'⌧'"/>
951 <for-each select="exsl:node-set($split-fragment)/node()">
952 <value-of select="."/>
953 <if test="position()!=last()">
954 <call-template name="LesML:comment-out"/>
959 <copy-of select="."/>
963 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:attrify"/>
965 <template match="node()" mode="LesML:inline">
966 <param name="element-name"/>
967 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
968 <param name="start-sigil"/>
969 <param name="end-sigil"/>
970 <param name="class"/>
973 <when test="self::*">
974 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
975 <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))"/>
977 <when test="$end-node and $has-start-node">
978 <variable name="preceding">
979 <copy-of select="$end-node/preceding-sibling::node()"/>
980 <value-of select="substring-before($end-node, $end-sigil)"/>
982 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
983 <variable name="start-tokens-fragment">
984 <call-template name="LesML:split">
985 <with-param name="source" select="string($start-node)"/>
986 <with-param name="separator" select="$start-sigil"/>
989 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
990 <variable name="wrapped">
992 <copy-of select="@*"/>
993 <copy-of select="$start-node/preceding-sibling::node()"/>
994 <for-each select="$start-tokens[position()!=last()]">
995 <value-of select="."/>
996 <if test="position()!=last()">
997 <value-of select="$start-sigil"/>
1000 <element name="{$element-name}" namespace="{$element-namespace}">
1001 <if test="string($role)!=''">
1002 <attribute name="role">
1003 <value-of select="$role"/>
1006 <if test="string($class)!=''">
1007 <attribute name="class">
1008 <value-of select="$class"/>
1011 <value-of select="$start-tokens[last()]"/>
1012 <copy-of select="$start-node/following-sibling::node()"/>
1014 <value-of select="substring-after($end-node, $end-sigil)"/>
1015 <copy-of select="$end-node/following-sibling::node()"/>
1018 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
1019 <with-param name="element-name" select="$element-name"/>
1020 <with-param name="element-namespace" select="$element-namespace"/>
1021 <with-param name="start-sigil" select="$start-sigil"/>
1022 <with-param name="end-sigil" select="$end-sigil"/>
1023 <with-param name="role" select="$role"/>
1028 <copy-of select="@*"/>
1029 <apply-templates select="node()" mode="LesML:inline">
1030 <with-param name="element-name" select="$element-name"/>
1031 <with-param name="element-namespace" select="$element-namespace"/>
1032 <with-param name="start-sigil" select="$start-sigil"/>
1033 <with-param name="end-sigil" select="$end-sigil"/>
1034 <with-param name="role" select="$role"/>
1041 <copy-of select="."/>
1045 <template match="*" mode="LesML:partition">
1046 <param name="start-sigil"/>
1047 <param name="end-sigil"/>
1048 <param name="separator"/>
1049 <param name="ncname-keys" select="false()"/>
1050 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1051 <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))"/>
1053 <when test="$end-node and $has-start-node">
1054 <variable name="preceding">
1055 <copy-of select="$end-node/preceding-sibling::node()"/>
1056 <value-of select="substring-before($end-node, $end-sigil)"/>
1058 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil) and not(following-sibling::*)][last()]"/>
1059 <variable name="start-tokens-fragment">
1060 <call-template name="LesML:split">
1061 <with-param name="source" select="string($start-node)"/>
1062 <with-param name="separator" select="$start-sigil"/>
1065 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
1066 <variable name="innards">
1067 <value-of select="$start-tokens[last()]"/>
1068 <for-each select="$start-node/following-sibling::node()">
1069 <value-of select="."/>
1073 <when test="contains($innards, $separator)">
1074 <variable name="keyval-fragment">
1075 <call-template name="LesML:split">
1076 <with-param name="source" select="$innards"/>
1077 <with-param name="separator" select="$separator"/>
1080 <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
1081 <variable name="key">
1083 <when test="$ncname-keys">
1084 <value-of select="$keyval[1]"/>
1087 <for-each select="$keyval[position()!=last()]">
1088 <value-of select="."/>
1089 <if test="position()!=last()">
1090 <value-of select="$separator"/>
1096 <variable name="value">
1098 <when test="$ncname-keys">
1099 <for-each select="$keyval[position()!=1]">
1100 <value-of select="."/>
1101 <if test="position()!=last()">
1102 <value-of select="$separator"/>
1107 <value-of select="$keyval[last()]"/>
1112 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key), ' /([,*', '')=string($key) and exsldyn:evaluate(concat('not(self::html:', $key, ')'))]">
1113 <element name="span" namespace="&xhtml;">
1114 <copy-of select="$start-node/preceding-sibling::node()"/>
1115 <for-each select="$start-tokens[position()!=last()]">
1116 <value-of select="."/>
1117 <if test="position()!=last()">
1118 <value-of select="$start-sigil"/>
1122 <element name="span" namespace="&xhtml;">
1123 <value-of select="$key"/>
1125 <element name="span" namespace="&xhtml;">
1126 <value-of select="$value"/>
1128 <element name="span" namespace="&xhtml;">
1129 <value-of select="substring-after($end-node, $end-sigil)"/>
1130 <copy-of select="$end-node/following-sibling::node()"/>
1134 <element name="span" namespace="&xhtml;">
1135 <copy-of select="$start-node/preceding-sibling::node()"/>
1136 <for-each select="$start-tokens[position()!=last()]">
1137 <value-of select="."/>
1138 <if test="position()!=last()">
1139 <value-of select="$start-sigil"/>
1142 <processing-instruction name="LesML-Token-Escape">
1143 <value-of select="$start-sigil"/>
1144 </processing-instruction>
1145 <value-of select="$start-tokens[last()]"/>
1146 <value-of select="$start-node/following-sibling::node()"/>
1147 <value-of select="$end-sigil"/>
1148 <value-of select="substring-after($end-node, $end-sigil)"/>
1149 <copy-of select="$end-node/following-sibling::node()"/>
1155 <element name="span" namespace="&xhtml;">
1156 <copy-of select="$start-node/preceding-sibling::node()"/>
1157 <for-each select="$start-tokens[position()!=last()]">
1158 <value-of select="."/>
1159 <if test="position()!=last()">
1160 <value-of select="$start-sigil"/>
1163 <processing-instruction name="LesML-Token-Escape">
1164 <value-of select="$start-sigil"/>
1165 </processing-instruction>
1166 <value-of select="$start-tokens[last()]"/>
1167 <value-of select="$start-node/following-sibling::node()"/>
1168 <value-of select="$end-sigil"/>
1169 <value-of select="substring-after($end-node, $end-sigil)"/>
1170 <copy-of select="$end-node/following-sibling::node()"/>
1175 <when test="$end-node">
1176 <element name="span" namespace="&xhtml;">
1177 <copy-of select="$end-node/preceding-sibling::node()"/>
1178 <value-of select="substring-before($end-node, $end-sigil)"/>
1179 <processing-instruction name="LesML-Token-Escape">
1180 <value-of select="$end-sigil"/>
1181 </processing-instruction>
1182 <value-of select="substring-after($end-node, $end-sigil)"/>
1183 <copy-of select="$end-node/following-sibling::node()"/>
1187 <processing-instruction name="LesML-All-Done"/>
1191 <template match="node()" mode="LesML:attrify">
1192 <variable name="result">
1194 <when test="self::*">
1195 <variable name="partitioned-fragment">
1196 <apply-templates mode="LesML:partition" select=".">
1197 <with-param name="start-sigil" select="'{@'"/>
1198 <with-param name="end-sigil" select="'"}'"/>
1199 <with-param name="separator" select="'="'"/>
1200 <with-param name="ncname-keys" select="true()"/>
1203 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1205 <when test="count($partitioned)>1">
1206 <variable name="processed">
1208 <copy-of select="@*"/>
1209 <copy-of select="$partitioned[1]/node()"/>
1210 <element name="LesML:attribute" namespace="&LesML;">
1211 <attribute name="{$partitioned[2]}">
1212 <value-of select="$partitioned[3]"/>
1215 <copy-of select="$partitioned[4]/node()"/>
1218 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1220 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1222 <copy-of select="@*"/>
1223 <apply-templates select="node()" mode="LesML:attrify"/>
1227 <variable name="processed">
1229 <copy-of select="@*"/>
1230 <copy-of select="$partitioned/node()"/>
1233 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1238 <copy-of select="."/>
1242 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify"/>
1244 <template match="node()" mode="LesML:linkify">
1245 <variable name="result">
1247 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1249 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1252 <when test="self::*">
1253 <variable name="partitioned-fragment">
1254 <apply-templates mode="LesML:partition" select=".">
1255 <with-param name="start-sigil" select="'{🔗'"/>
1256 <with-param name="end-sigil" select="'>}'"/>
1257 <with-param name="separator" select="'<'"/>
1260 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1262 <when test="count($partitioned)>1">
1263 <variable name="processed">
1265 <copy-of select="@*"/>
1266 <copy-of select="$partitioned[1]/node()"/>
1267 <element name="a" namespace="&xhtml;">
1268 <attribute name="href">
1269 <value-of select="$partitioned[3]"/>
1271 <processing-instruction name="LesML-All-Done"/>
1273 <when test="string($partitioned[2])=''">
1274 <value-of select="$partitioned[3]"/>
1277 <value-of select="$partitioned[2]"/>
1281 <copy-of select="$partitioned[4]/node()"/>
1284 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1286 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1288 <copy-of select="@*"/>
1289 <apply-templates select="node()" mode="LesML:linkify"/>
1293 <variable name="processed">
1295 <copy-of select="@*"/>
1296 <copy-of select="$partitioned/node()"/>
1299 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1304 <copy-of select="."/>
1308 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
1310 <template match="node()" mode="LesML:strikethrough">
1311 <variable name="result">
1312 <apply-templates select="." mode="LesML:inline">
1313 <with-param name="element-name" select="'s'"/>
1314 <with-param name="element-namespace" select="'&xhtml;'"/>
1315 <with-param name="start-sigil" select="'⸠'"/>
1316 <with-param name="end-sigil" select="'⸡'"/>
1319 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
1321 <template match="node()" mode="LesML:underline">
1322 <variable name="result">
1323 <apply-templates select="." mode="LesML:inline">
1324 <with-param name="element-name" select="'u'"/>
1325 <with-param name="element-namespace" select="'&xhtml;'"/>
1326 <with-param name="start-sigil" select="'⸤'"/>
1327 <with-param name="end-sigil" select="'⸥'"/>
1330 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
1332 <template match="node()" mode="LesML:noted">
1333 <variable name="result">
1334 <apply-templates select="." mode="LesML:inline">
1335 <with-param name="element-name" select="'small'"/>
1336 <with-param name="element-namespace" select="'&xhtml;'"/>
1337 <with-param name="start-sigil" select="'⟦'"/>
1338 <with-param name="end-sigil" select="'⟧'"/>
1339 <with-param name="role" select="'note'"/>
1342 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
1344 <template match="node()" mode="LesML:parenthetical">
1345 <variable name="result">
1346 <apply-templates select="." mode="LesML:inline">
1347 <with-param name="element-name" select="'small'"/>
1348 <with-param name="element-namespace" select="'&xhtml;'"/>
1349 <with-param name="start-sigil" select="'⸨'"/>
1350 <with-param name="end-sigil" select="'⸩'"/>
1353 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
1355 <template match="node()" mode="LesML:code">
1356 <variable name="result">
1357 <apply-templates select="." mode="LesML:inline">
1358 <with-param name="element-name" select="'code'"/>
1359 <with-param name="element-namespace" select="'&xhtml;'"/>
1360 <with-param name="start-sigil" select="'`'"/>
1361 <with-param name="end-sigil" select="'´'"/>
1364 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
1366 <template match="node()" mode="LesML:titled">
1367 <variable name="result">
1368 <apply-templates select="." mode="LesML:inline">
1369 <with-param name="element-name" select="'cite'"/>
1370 <with-param name="element-namespace" select="'&xhtml;'"/>
1371 <with-param name="start-sigil" select="'⟪'"/>
1372 <with-param name="end-sigil" select="'⟫'"/>
1375 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named"/>
1377 <template match="node()" mode="LesML:named">
1378 <variable name="result">
1379 <apply-templates select="." mode="LesML:inline">
1380 <with-param name="element-name" select="'u'"/>
1381 <with-param name="element-namespace" select="'&xhtml;'"/>
1382 <with-param name="start-sigil" select="'⸶'"/>
1383 <with-param name="end-sigil" select="'⸷'"/>
1384 <with-param name="class" select="'name'"/>
1387 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
1389 <template match="node()" mode="LesML:offset">
1390 <variable name="result">
1391 <apply-templates select="." mode="LesML:inline">
1392 <with-param name="element-name" select="'i'"/>
1393 <with-param name="element-namespace" select="'&xhtml;'"/>
1394 <with-param name="start-sigil" select="'⟨'"/>
1395 <with-param name="end-sigil" select="'⟩'"/>
1398 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
1400 <template match="node()" mode="LesML:bolded">
1401 <variable name="result">
1402 <apply-templates select="." mode="LesML:inline">
1403 <with-param name="element-name" select="'b'"/>
1404 <with-param name="element-namespace" select="'&xhtml;'"/>
1405 <with-param name="start-sigil" select="'⦃'"/>
1406 <with-param name="end-sigil" select="'⦄'"/>
1409 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
1411 <template match="node()" mode="LesML:important">
1412 <variable name="result">
1413 <apply-templates select="." mode="LesML:inline">
1414 <with-param name="element-name" select="'strong'"/>
1415 <with-param name="element-namespace" select="'&xhtml;'"/>
1416 <with-param name="start-sigil" select="'☞'"/>
1417 <with-param name="end-sigil" select="'☜'"/>
1420 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
1422 <template match="node()" mode="LesML:emphasized">
1423 <apply-templates select="." mode="LesML:inline">
1424 <with-param name="element-name" select="'em'"/>
1425 <with-param name="element-namespace" select="'&xhtml;'"/>
1426 <with-param name="start-sigil" select="'⹐'"/>
1427 <with-param name="end-sigil" select="'⹑'"/>