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 <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"/>
126 <variable name="id-and-lang">
127 <if test="starts-with($source, '¶')">
129 <when test="contains($source, ' ')">
130 <value-of select="substring-before(substring-after($source, '¶'), ' ')"/>
133 <value-of select="substring-after($source, '¶')"/>
138 <variable name="restoftext">
140 <when test="starts-with($source, '¶') and contains($source, ' ')">
141 <value-of select="substring-after($source, ' ')"/>
143 <when test="starts-with($source, '¶')"/>
145 <value-of select="$source"/>
149 <variable name="maybe-langtag">
150 <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
151 <variable name="split-tag-fragment">
152 <call-template name="LesML:split">
153 <with-param name="source" select="substring($id-and-lang, 2, string-length($id-and-lang)-2)"/>
154 <with-param name="separator" select="'@'"/>
157 <value-of select="exsl:node-set($split-tag-fragment)/*[last()]"/>
160 <variable name="langtag">
161 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
162 <value-of select="$maybe-langtag"/>
167 <when test="string($langtag)!=''">
168 <value-of select="substring($id-and-lang, 1, string-length($id-and-lang)-(string-length($langtag)+2))"/>
171 <value-of select="$id-and-lang"/>
175 <if test="string($id)!=''">
176 <attribute name="id">
177 <value-of select="$id"/>
180 <if test="string($langtag)!=''">
181 <attribute name="lang">
182 <value-of select="$langtag"/>
184 <attribute name="xml:lang">
185 <value-of select="$langtag"/>
188 <value-of select="$restoftext"/>
190 <template name="LesML:parse">
191 <param name="lines" select="/.."/>
192 <param name="parent-params" select="/.."/>
193 <variable name="first-line" select="$lines[1]"/>
194 <variable name="shebang">
195 <if test="starts-with($first-line, '#!lesml')">
196 <value-of select="$first-line"/>
199 <variable name="params-string">
201 <when test="starts-with($shebang, '#!lesml@')">
202 <value-of select="substring-after($shebang, '$')"/>
205 <value-of select="substring-after($shebang, '#!lesml')"/>
209 <variable name="params-fragment">
211 <when test="$shebang!=''">
213 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
219 <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
223 <for-each select="exslstr:tokenize($params-string)">
225 <when test="contains(., '=')">
228 <value-of select="substring-before(., '=')"/>
231 <value-of select="substring-after(., '=')"/>
238 <value-of select="."/>
247 <when test="$parent-params">
248 <copy-of select="$parent-params"/>
255 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
256 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
257 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
258 <variable name="doclines" select="exslset:leading($noshebang, $docsep)"/>
259 <if test="starts-with($first-line, '##') and $first-line!='##'">
261 <value-of select="substring-after($first-line, '##')"/>
264 <if test="$doclines[normalize-space()!='']">
265 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
266 <element name="article" namespace="&xhtml;">
267 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
268 <attribute name="lang">
269 <value-of select="following-sibling::html:dd"/>
271 <attribute name="xml:lang">
272 <value-of select="following-sibling::html:dd"/>
275 <for-each select="$params/html:div/html:dt[string()='profile']">
276 <attribute name="data-lesml-profile">
277 <value-of select="following-sibling::html:dd"/>
280 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
281 <element name="footer" namespace="&xhtml;">
282 <attribute name="class">
285 <for-each select="$record-separators">
286 <variable name="position" select="position()"/>
287 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
288 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)"/>
290 <element name="dl" namespace="&xhtml;">
291 <for-each select="$fields">
293 <when test="starts-with(., ' ') and exslset:leading($fields, .)"/>
295 <variable name="next" select="exslset:intersection(following-sibling::*[not(starts-with(., ' '))][1], $fields)"/>
296 <element name="div" namespace="&xhtml;">
297 <element name="dt" namespace="&xhtml;">
298 <value-of select="normalize-space(substring-before(., ':'))"/>
300 <element name="dd" namespace="&xhtml;">
301 <variable name="firstline">
303 <when test="contains(., ':')">
304 <value-of select="normalize-space(substring-after(., ':'))"/>
307 <value-of select="normalize-space(.)"/>
312 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
313 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
316 <value-of select="$firstline"/>
319 <for-each select="exslset:intersection(following-sibling::*[starts-with(., ' ')], exslset:leading($fields, $next))">
320 <variable name="nextline" select="normalize-space(.)"/>
322 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
323 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
326 <value-of select="$nextline"/>
339 <value-of select="substring-after(., '%%')"/>
345 <element name="div" namespace="&xhtml;">
346 <attribute name="class">
349 <call-template name="LesML:paragraphize">
350 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
356 <call-template name="LesML:parse">
357 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
358 <with-param name="parent-params" select="$params"/>
362 <template name="LesML:paragraphize">
363 <param name="lines" select="/.."/>
364 <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
365 <variable name="blocked">
366 <for-each select="$last-lines">
367 <variable name="position" select="position()"/>
368 <variable name="prev-last" select="$last-lines[($position)-1]"/>
369 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
370 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '	'))])"/>
371 <variable name="preformatted" select="not($linespans[not(starts-with(normalize-space(), '|'))])"/>
372 <variable name="text">
373 <for-each select="$linespans">
375 <when test="$preformatted">
376 <value-of select="substring-after(., '|')"/>
379 <value-of select="normalize-space()"/>
382 <if test="position()!=count($linespans)">
384 <when test="$preformatted">
394 <if test="string($text)!=''">
395 <variable name="par">
397 <when test="$preformatted">
398 <element name="pre" namespace="&xhtml;">
399 <call-template name="LesML:id-and-contents">
400 <with-param name="source" select="$text"/>
404 <when test="starts-with($text, '⁌') and &sigiled-text;">
405 <element name="h1" namespace="&xhtml;">
406 <call-template name="LesML:id-and-contents">
407 <with-param name="source" select="&unsigiled-text;"/>
411 <when test="starts-with($text, '§') and &sigiled-text;">
412 <element name="h2" namespace="&xhtml;">
413 <call-template name="LesML:id-and-contents">
414 <with-param name="source" select="&unsigiled-text;"/>
418 <when test="starts-with($text, '❦') and &sigiled-text;">
419 <element name="h3" namespace="&xhtml;">
420 <call-template name="LesML:id-and-contents">
421 <with-param name="source" select="&unsigiled-text;"/>
425 <when test="starts-with($text, '✠') and &sigiled-text;">
426 <element name="h4" namespace="&xhtml;">
427 <call-template name="LesML:id-and-contents">
428 <with-param name="source" select="&unsigiled-text;"/>
432 <when test="starts-with($text, '•') and &sigiled-text;">
433 <element name="li" namespace="&xhtml;">
434 <attribute name="class">
435 <text>unordered</text>
437 <attribute name="data-level">
440 <element name="p" namespace="&xhtml;">
441 <call-template name="LesML:id-and-contents">
442 <with-param name="source" select="&unsigiled-text;"/>
447 <when test="starts-with($text, '🔢') and &sigiled-text;">
448 <element name="li" namespace="&xhtml;">
449 <attribute name="class">
452 <attribute name="data-level">
455 <element name="p" namespace="&xhtml;">
456 <call-template name="LesML:id-and-contents">
457 <with-param name="source" select="&unsigiled-text;"/>
462 <when test="starts-with($text, '◦') and &sigiled-text;">
463 <element name="li" namespace="&xhtml;">
464 <attribute name="class">
465 <text>unordered</text>
467 <attribute name="data-level">
470 <element name="p" namespace="&xhtml;">
471 <call-template name="LesML:id-and-contents">
472 <with-param name="source" select="&unsigiled-text;"/>
477 <when test="starts-with($text, '🔠') and &sigiled-text;">
478 <element name="li" namespace="&xhtml;">
479 <attribute name="class">
482 <attribute name="data-level">
485 <element name="p" namespace="&xhtml;">
486 <call-template name="LesML:id-and-contents">
487 <with-param name="source" select="&unsigiled-text;"/>
492 <when test="starts-with($text, '▪') and &sigiled-text;">
493 <element name="li" namespace="&xhtml;">
494 <attribute name="class">
495 <text>unordered</text>
497 <attribute name="data-level">
500 <element name="p" namespace="&xhtml;">
501 <call-template name="LesML:id-and-contents">
502 <with-param name="source" select="&unsigiled-text;"/>
507 <when test="starts-with($text, '🔡') and &sigiled-text;">
508 <element name="li" namespace="&xhtml;">
509 <attribute name="class">
512 <attribute name="data-level">
515 <element name="p" namespace="&xhtml;">
516 <call-template name="LesML:id-and-contents">
517 <with-param name="source" select="&unsigiled-text;"/>
522 <when test="starts-with($text, '⁃') and &sigiled-text;">
523 <element name="li" namespace="&xhtml;">
524 <attribute name="class">
525 <text>unordered</text>
527 <attribute name="data-level">
530 <element name="p" namespace="&xhtml;">
531 <call-template name="LesML:id-and-contents">
532 <with-param name="source" select="&unsigiled-text;"/>
537 <when test="starts-with($text, '🔣') and &sigiled-text;">
538 <element name="li" namespace="&xhtml;">
539 <attribute name="class">
542 <attribute name="data-level">
545 <element name="p" namespace="&xhtml;">
546 <call-template name="LesML:id-and-contents">
547 <with-param name="source" select="&unsigiled-text;"/>
552 <when test="starts-with($text, '🛈') and &sigiled-text;">
553 <element name="div" namespace="&xhtml;">
554 <attribute name="role">
557 <attribute name="class">
560 <element name="p" namespace="&xhtml;">
561 <call-template name="LesML:id-and-contents">
562 <with-param name="source" select="&unsigiled-text;"/>
567 <when test="starts-with($text, '⯑') and &sigiled-text;">
568 <element name="div" namespace="&xhtml;">
569 <attribute name="role">
572 <attribute name="class">
575 <element name="p" namespace="&xhtml;">
576 <call-template name="LesML:id-and-contents">
577 <with-param name="source" select="&unsigiled-text;"/>
582 <when test="starts-with($text, '⚠︎') and &sigiled-text;">
583 <element name="div" namespace="&xhtml;">
584 <attribute name="role">
587 <attribute name="class">
590 <element name="p" namespace="&xhtml;">
591 <call-template name="LesML:id-and-contents">
592 <with-param name="source" select="&unsigiled-text;"/>
597 <when test="starts-with($text, '※') and &sigiled-text;">
598 <element name="div" namespace="&xhtml;">
599 <attribute name="role">
602 <attribute name="class">
605 <element name="p" namespace="&xhtml;">
606 <call-template name="LesML:id-and-contents">
607 <with-param name="source" select="&unsigiled-text;"/>
612 <when test="starts-with($text, '☡') and &sigiled-text;">
613 <element name="div" namespace="&xhtml;">
614 <attribute name="role">
617 <attribute name="class">
620 <element name="p" namespace="&xhtml;">
621 <call-template name="LesML:id-and-contents">
622 <with-param name="source" select="&unsigiled-text;"/>
627 <when test="starts-with($text, '⋯') and &sigiled-text;">
628 <element name="div" namespace="&xhtml;">
629 <attribute name="class">
630 <text>continuation</text>
632 <element name="p" namespace="&xhtml;">
633 <call-template name="LesML:id-and-contents">
634 <with-param name="source" select="&unsigiled-text;"/>
639 <when test="starts-with($text, '#') and &sigiled-text;">
641 <value-of select="&unsigiled-text;"/>
645 <element name="p" namespace="&xhtml;">
646 <call-template name="LesML:id-and-contents">
647 <with-param name="source" select="$text"/>
654 <when test="translate(string($text), '§ion-break; ', '')=''">
655 <element name="hr" namespace="&xhtml;"/>
657 <when test="$quoted">
658 <element name="blockquote" namespace="&xhtml;">
659 <copy-of select="$par"/>
663 <copy-of select="$par"/>
669 <variable name="inlined">
670 <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:comment"/>
672 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
674 <template match="html:script[@type='text/lesml']">
675 <variable name="lines-fragment">
676 <call-template name="LesML:split">
677 <with-param name="source">
678 <for-each select=".//text()">
679 <value-of select="."/>
684 <element name="div" namespace="&xhtml;">
685 <call-template name="LesML:parse">
686 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
690 <template match="node()" mode="LesML:finalize-attributes">
691 <variable name="notattr" select="following-sibling::node()[not(self::text() and translate(., ' 	', '')='' or self::LesML:attribute)]"/>
692 <for-each select="(.|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
693 <copy-of select="."/>
694 <if test="local-name()='lang' and namespace-uri()=''">
695 <attribute name="xml:lang">
696 <value-of select="."/>
701 <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"/>
702 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize-tree" priority="1">
703 <element name="span" namespace="&xhtml;">
704 <apply-templates select="." mode="LesML:finalize-attributes"/>
705 <if test="self::text()">
706 <call-template name="LesML:break-and-unescape">
707 <with-param name="source" select="string(.)"/>
712 <template match="html:blockquote" mode="LesML:finalize-tree">
713 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
714 <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
715 <variable name="contents">
716 <copy-of select="node()"/>
717 <for-each select="exslset:leading(following-sibling::node(), $notquote)">
718 <copy-of select="node()"/>
721 <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
722 <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()]"/>
724 <when test="starts-with($laststarttext, '— ')">
725 <variable name="caption">
726 <copy-of select="$laststarttext/preceding-sibling::node()"/>
727 <value-of select="substring-after($laststarttext, '— ')"/>
728 <copy-of select="$laststarttext/following-sibling::node()"/>
730 <element name="figure" namespace="&xhtml;">
732 <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
734 <element name="figcaption" namespace="&xhtml;">
735 <for-each select="$content-nodes[last()]">
737 <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
745 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
751 <template match="html:div" mode="LesML:finalize-tree">
752 <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)]">
753 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
755 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
756 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
757 <apply-templates select="node()" mode="LesML:finalize-tree"/>
762 <template match="html:li" mode="LesML:finalize-tree">
763 <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)]">
764 <apply-templates select="." mode="LesML:finalize-list"/>
767 <template match="html:li" mode="LesML:finalize-list">
768 <param name="parent-level" select="0"/>
769 <variable name="current-class" select="string(@class)"/>
770 <variable name="current-level" select="number(@data-level)"/>
771 <variable name="wrapper">
773 <when test="@class='ordered'">
781 <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]"/>
782 <element name="{$wrapper}" namespace="&xhtml;">
783 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @data-level=$current-level]">
784 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
786 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
787 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
788 <apply-templates select="node()" mode="LesML:finalize-tree"/>
790 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
791 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
792 <with-param name="parent-level" select="$current-level"/>
798 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
799 <apply-templates select="$notinlist" mode="LesML:finalize-list">
800 <with-param name="parent-level" select="$parent-level"/>
804 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finalize-tree">
805 <value-of select="."/>
807 <template match="text()" mode="LesML:finalize-tree">
808 <call-template name="LesML:break-and-unescape">
809 <with-param name="source" select="string(.)"/>
812 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
814 <apply-templates select="." mode="LesML:finalize-attributes"/>
815 <apply-templates select="node()" mode="LesML:finalize-tree"/>
818 <template match="node()" mode="LesML:comment">
819 <variable name="result">
821 <when test="self::*">
822 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
823 <variable name="after-start">
824 <if test="$start-node">
825 <value-of select="substring-after($start-node, '⌦')"/>
828 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
830 <when test="$start-node and $has-end-node">
831 <variable name="following">
832 <value-of select="$after-start"/>
833 <copy-of select="$start-node/following-sibling::node()"/>
835 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
836 <variable name="comment">
837 <for-each select="$end-node/preceding-sibling::node()">
838 <value-of select="."/>
840 <value-of select="substring-before($end-node, '⌫')"/>
842 <variable name="comment-split-fragment">
843 <call-template name="LesML:split">
844 <with-param name="source" select="string($comment)"/>
845 <with-param name="separator" select="'--'"/>
848 <variable name="rest-fragment">
849 <element name="span" namespace="&xhtml;">
850 <value-of select="substring-after($end-node, '⌫')"/>
851 <copy-of select="$end-node/following-sibling::node()"/>
854 <variable name="commented-rest-fragment">
855 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment"/>
858 <copy-of select="@*"/>
859 <copy-of select="$start-node/preceding-sibling::node()"/>
860 <copy-of select="substring-before($start-node, '⌦')"/>
862 <for-each select="exsl:node-set($comment-split-fragment)/*">
863 <if test="string()='' or starts-with(., '‐')">
864 <text>͏</text>
866 <value-of select="."/>
867 <if test="substring(., string-length(.), 1)='‐'">
868 <text>͏</text>
871 <when test="position()!=last()">
872 <text>-͏-</text>
877 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
882 <copy-of select="@*"/>
883 <apply-templates select="node()" mode="LesML:comment"/>
888 <when test="self::text()[contains(., '⌧')]">
889 <variable name="split-fragment">
890 <call-template name="LesML:split">
891 <with-param name="source" select="string()"/>
892 <with-param name="separator" select="'⌧'"/>
895 <for-each select="exsl:node-set($split-fragment)/node()">
896 <value-of select="."/>
897 <if test="position()!=last()">
899 <text>͏</text>
905 <copy-of select="."/>
909 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:attrify"/>
911 <template match="node()" mode="LesML:inline">
912 <param name="element-name"/>
913 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
914 <param name="start-sigil"/>
915 <param name="end-sigil"/>
916 <param name="class"/>
919 <when test="self::*">
920 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
921 <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))"/>
923 <when test="$end-node and $has-start-node">
924 <variable name="preceding">
925 <copy-of select="$end-node/preceding-sibling::node()"/>
926 <value-of select="substring-before($end-node, $end-sigil)"/>
928 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
929 <variable name="start-tokens-fragment">
930 <call-template name="LesML:split">
931 <with-param name="source" select="string($start-node)"/>
932 <with-param name="separator" select="$start-sigil"/>
935 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
936 <variable name="wrapped">
938 <copy-of select="@*"/>
939 <copy-of select="$start-node/preceding-sibling::node()"/>
940 <for-each select="$start-tokens[position()!=last()]">
941 <value-of select="."/>
942 <if test="position()!=last()">
943 <value-of select="$start-sigil"/>
946 <element name="{$element-name}" namespace="{$element-namespace}">
947 <if test="string($role)!=''">
948 <attribute name="role">
949 <value-of select="$role"/>
952 <if test="string($class)!=''">
953 <attribute name="class">
954 <value-of select="$class"/>
957 <value-of select="$start-tokens[last()]"/>
958 <copy-of select="$start-node/following-sibling::node()"/>
960 <value-of select="substring-after($end-node, $end-sigil)"/>
961 <copy-of select="$end-node/following-sibling::node()"/>
964 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
965 <with-param name="element-name" select="$element-name"/>
966 <with-param name="element-namespace" select="$element-namespace"/>
967 <with-param name="start-sigil" select="$start-sigil"/>
968 <with-param name="end-sigil" select="$end-sigil"/>
969 <with-param name="role" select="$role"/>
974 <copy-of select="@*"/>
975 <apply-templates select="node()" mode="LesML:inline">
976 <with-param name="element-name" select="$element-name"/>
977 <with-param name="element-namespace" select="$element-namespace"/>
978 <with-param name="start-sigil" select="$start-sigil"/>
979 <with-param name="end-sigil" select="$end-sigil"/>
980 <with-param name="role" select="$role"/>
987 <copy-of select="."/>
991 <template match="*" mode="LesML:partition">
992 <param name="start-sigil"/>
993 <param name="end-sigil"/>
994 <param name="separator"/>
995 <param name="ncname-keys" select="false()"/>
996 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
997 <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))"/>
999 <when test="$end-node and $has-start-node">
1000 <variable name="preceding">
1001 <copy-of select="$end-node/preceding-sibling::node()"/>
1002 <value-of select="substring-before($end-node, $end-sigil)"/>
1004 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil) and not(following-sibling::*)][last()]"/>
1005 <variable name="start-tokens-fragment">
1006 <call-template name="LesML:split">
1007 <with-param name="source" select="string($start-node)"/>
1008 <with-param name="separator" select="$start-sigil"/>
1011 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
1012 <variable name="innards">
1013 <value-of select="$start-tokens[last()]"/>
1014 <for-each select="$start-node/following-sibling::node()">
1015 <value-of select="."/>
1019 <when test="contains($innards, $separator)">
1020 <variable name="keyval-fragment">
1021 <call-template name="LesML:split">
1022 <with-param name="source" select="$innards"/>
1023 <with-param name="separator" select="$separator"/>
1026 <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
1027 <variable name="key">
1029 <when test="$ncname-keys">
1030 <value-of select="$keyval[1]"/>
1033 <for-each select="$keyval[position()!=last()]">
1034 <value-of select="."/>
1035 <if test="position()!=last()">
1036 <value-of select="$separator"/>
1042 <variable name="value">
1044 <when test="$ncname-keys">
1045 <for-each select="$keyval[position()!=1]">
1046 <value-of select="."/>
1047 <if test="position()!=last()">
1048 <value-of select="$separator"/>
1053 <value-of select="$keyval[last()]"/>
1058 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key), ' /([,*', '')=string($key) and exsldyn:evaluate(concat('not(self::html:', $key, ')'))]">
1059 <element name="span" namespace="&xhtml;">
1060 <copy-of select="$start-node/preceding-sibling::node()"/>
1061 <for-each select="$start-tokens[position()!=last()]">
1062 <value-of select="."/>
1063 <if test="position()!=last()">
1064 <value-of select="$start-sigil"/>
1068 <element name="span" namespace="&xhtml;">
1069 <value-of select="$key"/>
1071 <element name="span" namespace="&xhtml;">
1072 <value-of select="$value"/>
1074 <element name="span" namespace="&xhtml;">
1075 <value-of select="substring-after($end-node, $end-sigil)"/>
1076 <copy-of select="$end-node/following-sibling::node()"/>
1080 <element name="span" namespace="&xhtml;">
1081 <copy-of select="$start-node/preceding-sibling::node()"/>
1082 <for-each select="$start-tokens[position()!=last()]">
1083 <value-of select="."/>
1084 <if test="position()!=last()">
1085 <value-of select="$start-sigil"/>
1088 <processing-instruction name="LesML-Token-Escape">
1089 <value-of select="$start-sigil"/>
1090 </processing-instruction>
1091 <value-of select="$start-tokens[last()]"/>
1092 <value-of select="$start-node/following-sibling::node()"/>
1093 <value-of select="$end-sigil"/>
1094 <value-of select="substring-after($end-node, $end-sigil)"/>
1095 <copy-of select="$end-node/following-sibling::node()"/>
1101 <element name="span" namespace="&xhtml;">
1102 <copy-of select="$start-node/preceding-sibling::node()"/>
1103 <for-each select="$start-tokens[position()!=last()]">
1104 <value-of select="."/>
1105 <if test="position()!=last()">
1106 <value-of select="$start-sigil"/>
1109 <processing-instruction name="LesML-Token-Escape">
1110 <value-of select="$start-sigil"/>
1111 </processing-instruction>
1112 <value-of select="$start-tokens[last()]"/>
1113 <value-of select="$start-node/following-sibling::node()"/>
1114 <value-of select="$end-sigil"/>
1115 <value-of select="substring-after($end-node, $end-sigil)"/>
1116 <copy-of select="$end-node/following-sibling::node()"/>
1121 <when test="$end-node">
1122 <element name="span" namespace="&xhtml;">
1123 <copy-of select="$end-node/preceding-sibling::node()"/>
1124 <value-of select="substring-before($end-node, $end-sigil)"/>
1125 <processing-instruction name="LesML-Token-Escape">
1126 <value-of select="$end-sigil"/>
1127 </processing-instruction>
1128 <value-of select="substring-after($end-node, $end-sigil)"/>
1129 <copy-of select="$end-node/following-sibling::node()"/>
1133 <processing-instruction name="LesML-All-Done"/>
1137 <template match="node()" mode="LesML:attrify">
1138 <variable name="result">
1140 <when test="self::*">
1141 <variable name="partitioned-fragment">
1142 <apply-templates mode="LesML:partition" select=".">
1143 <with-param name="start-sigil" select="'{@'"/>
1144 <with-param name="end-sigil" select="'"}'"/>
1145 <with-param name="separator" select="'="'"/>
1146 <with-param name="ncname-keys" select="true()"/>
1149 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1151 <when test="count($partitioned)>1">
1152 <variable name="processed">
1154 <copy-of select="@*"/>
1155 <copy-of select="$partitioned[1]/node()"/>
1156 <element name="LesML:attribute" namespace="&LesML;">
1157 <attribute name="{$partitioned[2]}">
1158 <value-of select="$partitioned[3]"/>
1161 <copy-of select="$partitioned[4]/node()"/>
1164 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1166 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1168 <copy-of select="@*"/>
1169 <apply-templates select="node()" mode="LesML:attrify"/>
1173 <variable name="processed">
1175 <copy-of select="@*"/>
1176 <copy-of select="$partitioned/node()"/>
1179 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
1184 <copy-of select="."/>
1188 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify"/>
1190 <template match="node()" mode="LesML:linkify">
1191 <variable name="result">
1193 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1195 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1198 <when test="self::*">
1199 <variable name="partitioned-fragment">
1200 <apply-templates mode="LesML:partition" select=".">
1201 <with-param name="start-sigil" select="'{🔗'"/>
1202 <with-param name="end-sigil" select="'>}'"/>
1203 <with-param name="separator" select="'<'"/>
1206 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1208 <when test="count($partitioned)>1">
1209 <variable name="processed">
1211 <copy-of select="@*"/>
1212 <copy-of select="$partitioned[1]/node()"/>
1213 <element name="a" namespace="&xhtml;">
1214 <attribute name="href">
1215 <value-of select="$partitioned[3]"/>
1217 <processing-instruction name="LesML-All-Done"/>
1219 <when test="string($partitioned[2])=''">
1220 <value-of select="$partitioned[3]"/>
1223 <value-of select="$partitioned[2]"/>
1227 <copy-of select="$partitioned[4]/node()"/>
1230 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1232 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1234 <copy-of select="@*"/>
1235 <apply-templates select="node()" mode="LesML:linkify"/>
1239 <variable name="processed">
1241 <copy-of select="@*"/>
1242 <copy-of select="$partitioned/node()"/>
1245 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
1250 <copy-of select="."/>
1254 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
1256 <template match="node()" mode="LesML:strikethrough">
1257 <variable name="result">
1258 <apply-templates select="." mode="LesML:inline">
1259 <with-param name="element-name" select="'s'"/>
1260 <with-param name="element-namespace" select="'&xhtml;'"/>
1261 <with-param name="start-sigil" select="'⸠'"/>
1262 <with-param name="end-sigil" select="'⸡'"/>
1265 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
1267 <template match="node()" mode="LesML:underline">
1268 <variable name="result">
1269 <apply-templates select="." mode="LesML:inline">
1270 <with-param name="element-name" select="'u'"/>
1271 <with-param name="element-namespace" select="'&xhtml;'"/>
1272 <with-param name="start-sigil" select="'⸤'"/>
1273 <with-param name="end-sigil" select="'⸥'"/>
1276 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
1278 <template match="node()" mode="LesML:noted">
1279 <variable name="result">
1280 <apply-templates select="." mode="LesML:inline">
1281 <with-param name="element-name" select="'small'"/>
1282 <with-param name="element-namespace" select="'&xhtml;'"/>
1283 <with-param name="start-sigil" select="'⟦'"/>
1284 <with-param name="end-sigil" select="'⟧'"/>
1285 <with-param name="role" select="'note'"/>
1288 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
1290 <template match="node()" mode="LesML:parenthetical">
1291 <variable name="result">
1292 <apply-templates select="." mode="LesML:inline">
1293 <with-param name="element-name" select="'small'"/>
1294 <with-param name="element-namespace" select="'&xhtml;'"/>
1295 <with-param name="start-sigil" select="'⸨'"/>
1296 <with-param name="end-sigil" select="'⸩'"/>
1299 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
1301 <template match="node()" mode="LesML:code">
1302 <variable name="result">
1303 <apply-templates select="." mode="LesML:inline">
1304 <with-param name="element-name" select="'code'"/>
1305 <with-param name="element-namespace" select="'&xhtml;'"/>
1306 <with-param name="start-sigil" select="'`'"/>
1307 <with-param name="end-sigil" select="'´'"/>
1310 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
1312 <template match="node()" mode="LesML:titled">
1313 <variable name="result">
1314 <apply-templates select="." mode="LesML:inline">
1315 <with-param name="element-name" select="'cite'"/>
1316 <with-param name="element-namespace" select="'&xhtml;'"/>
1317 <with-param name="start-sigil" select="'⟪'"/>
1318 <with-param name="end-sigil" select="'⟫'"/>
1321 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named"/>
1323 <template match="node()" mode="LesML:named">
1324 <variable name="result">
1325 <apply-templates select="." mode="LesML:inline">
1326 <with-param name="element-name" select="'u'"/>
1327 <with-param name="element-namespace" select="'&xhtml;'"/>
1328 <with-param name="start-sigil" select="'⸶'"/>
1329 <with-param name="end-sigil" select="'⸷'"/>
1330 <with-param name="class" select="'name'"/>
1333 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
1335 <template match="node()" mode="LesML:offset">
1336 <variable name="result">
1337 <apply-templates select="." mode="LesML:inline">
1338 <with-param name="element-name" select="'i'"/>
1339 <with-param name="element-namespace" select="'&xhtml;'"/>
1340 <with-param name="start-sigil" select="'⟨'"/>
1341 <with-param name="end-sigil" select="'⟩'"/>
1344 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
1346 <template match="node()" mode="LesML:bolded">
1347 <variable name="result">
1348 <apply-templates select="." mode="LesML:inline">
1349 <with-param name="element-name" select="'b'"/>
1350 <with-param name="element-namespace" select="'&xhtml;'"/>
1351 <with-param name="start-sigil" select="'⦃'"/>
1352 <with-param name="end-sigil" select="'⦄'"/>
1355 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
1357 <template match="node()" mode="LesML:important">
1358 <variable name="result">
1359 <apply-templates select="." mode="LesML:inline">
1360 <with-param name="element-name" select="'strong'"/>
1361 <with-param name="element-namespace" select="'&xhtml;'"/>
1362 <with-param name="start-sigil" select="'☞'"/>
1363 <with-param name="end-sigil" select="'☜'"/>
1366 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
1368 <template match="node()" mode="LesML:emphasized">
1369 <apply-templates select="." mode="LesML:inline">
1370 <with-param name="element-name" select="'em'"/>
1371 <with-param name="element-namespace" select="'&xhtml;'"/>
1372 <with-param name="start-sigil" select="'⹐'"/>
1373 <with-param name="end-sigil" select="'⹑'"/>