]> Lady’s Gitweb - LesML/blob - parser.xslt
Don’t use literal result elements
[LesML] / parser.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ 💄📝 Les·M·L ∷ parser.xslt
8
9 © 2024 Lady [@ Lady’s Computer]
10
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/>.
13 -->
14 <!DOCTYPE transform [
15 <!ENTITY section-break "*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~">
16 <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ')">
17 <!ENTITY unsigiled-text "substring($text, 3, string-length($text)-2)">
18 ]>
19 <transform
20 xmlns="http://www.w3.org/1999/XSL/Transform"
21 xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
22 xmlns:exsl="http://exslt.org/common"
23 xmlns:exslstr="http://exslt.org/strings"
24 xmlns:html="http://www.w3.org/1999/xhtml"
25 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
26 exclude-result-prefixes="LesML"
27 extension-element-prefixes="exsl exslstr"
28 version="1.0"
29 >
30 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
31 <template name="LesML:split">
32 <param name="source"/>
33 <param name="separator" select="'&#xA;'"/>
34 <choose>
35 <when test="contains($source, $separator)">
36 <html:span>
37 <value-of select="substring-before($source, $separator)"/>
38 </html:span>
39 <call-template name="LesML:split">
40 <with-param name="source" select="substring-after($source, $separator)"/>
41 <with-param name="separator" select="$separator"/>
42 </call-template>
43 </when>
44 <otherwise>
45 <html:span>
46 <value-of select="$source"/>
47 </html:span>
48 </otherwise>
49 </choose>
50 </template>
51 <template name="LesML:break-and-unescape">
52 <param name="source"/>
53 <variable name="broken-fragment">
54 <call-template name="LesML:split">
55 <with-param name="source" select="$source"/>
56 <with-param name="separator" select="'&#xA;'"/>
57 </call-template>
58 </variable>
59 <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
60 <for-each select="$broken">
61 <call-template name="LesML:unescape">
62 <with-param name="source" select="string()"/>
63 </call-template>
64 <if test="position()!=count($broken)">
65 <element name="html:br"/>
66 </if>
67 </for-each>
68 </template>
69 <template name="LesML:unescape">
70 <param name="source"/>
71 <choose>
72 <when test="contains($source, '&lt;U+')">
73 <variable name="after" select="substring-after($source, '&lt;U+')"/>
74 <choose>
75 <when test="contains($after, '>')">
76 <variable name="inner" select="substring-before($after, '>')"/>
77 <variable name="components">
78 <call-template name="LesML:split">
79 <with-param name="source" select="$inner"/>
80 <with-param name="separator" select="'.'"/>
81 </call-template>
82 </variable>
83 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
84 <choose>
85 <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
86 <value-of select="substring-before($source, '&lt;U+')"/>
87 <text>&lt;U+</text>
88 <value-of select="$inner"/>
89 <text>></text>
90 <call-template name="LesML:unescape">
91 <with-param name="source" select="substring-after($after, '>')"/>
92 </call-template>
93 </when>
94 <otherwise>
95 <for-each select="$component-nodes">
96 <text disable-output-escaping="yes">&amp;#x</text>
97 <value-of select="."/>
98 <text>;</text>
99 </for-each>
100 <call-template name="LesML:unescape">
101 <with-param name="source" select="substring-after($after, '>')"/>
102 </call-template>
103 </otherwise>
104 </choose>
105 </when>
106 <otherwise>
107 <value-of select="substring-before($source, '&lt;U+')"/>
108 <text>&lt;U+</text>
109 <call-template name="LesML:unescape">
110 <with-param name="source" select="$after"/>
111 </call-template>
112 </otherwise>
113 </choose>
114 </when>
115 <otherwise>
116 <value-of select="$source"/>
117 </otherwise>
118 </choose>
119 </template>
120 <template name="LesML:id-and-contents">
121 <param name="source"/>
122 <choose>
123 <when test="starts-with($source, '¶')">
124 <choose>
125 <when test="contains($source, ' ')">
126 <variable name="id" select="substring-before(substring-after($source, '¶'), ' ')"/>
127 <if test="$id!=''">
128 <attribute name="id">
129 <value-of select="$id"/>
130 </attribute>
131 </if>
132 <value-of select="substring-after($source, ' ')"/>
133 </when>
134 <otherwise>
135 <attribute name="id">
136 <value-of select="substring-after($source, '¶')"/>
137 </attribute>
138 </otherwise>
139 </choose>
140 </when>
141 <otherwise>
142 <value-of select="$source"/>
143 </otherwise>
144 </choose>
145 </template>
146 <template name="LesML:parse">
147 <param name="lines" select="/.."/>
148 <param name="parent-params" select="/.."/>
149 <variable name="first-line" select="$lines[1]"/>
150 <variable name="shebang">
151 <if test="starts-with($first-line, '#!lesml')">
152 <value-of select="$first-line"/>
153 </if>
154 </variable>
155 <variable name="params-string">
156 <choose>
157 <when test="starts-with($shebang, '#!lesml@')">
158 <value-of select="substring-after($shebang, '$')"/>
159 </when>
160 <otherwise>
161 <value-of select="substring-after($shebang, '#!lesml')"/>
162 </otherwise>
163 </choose>
164 </variable>
165 <variable name="params-fragment">
166 <choose>
167 <when test="$shebang!=''">
168 <html:dl>
169 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
170 <html:div>
171 <html:dt>
172 <text> LANG </text>
173 </html:dt>
174 <html:dd>
175 <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
176 </html:dd>
177 </html:div>
178 </if>
179 <for-each select="exslstr:tokenize($params-string)">
180 <choose>
181 <when test="contains(., '=')">
182 <html:div>
183 <html:dt>
184 <value-of select="substring-before(., '=')"/>
185 </html:dt>
186 <html:dd>
187 <value-of select="substring-after(., '=')"/>
188 </html:dd>
189 </html:div>
190 </when>
191 <otherwise>
192 <html:div>
193 <html:dt>
194 <value-of select="."/>
195 </html:dt>
196 <html:dd/>
197 </html:div>
198 </otherwise>
199 </choose>
200 </for-each>
201 </html:dl>
202 </when>
203 <when test="$parent-params">
204 <copy-of select="$parent-params"/>
205 </when>
206 <otherwise>
207 <html:dl/>
208 </otherwise>
209 </choose>
210 </variable>
211 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
212 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
213 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
214 <variable name="doclines" select="$noshebang[not($docsep) or following-sibling::*[generate-id()=generate-id($docsep)]]"/>
215 <if test="starts-with($first-line, '##') and $first-line!='##'">
216 <comment>
217 <value-of select="substring-after($first-line, '##')"/>
218 </comment>
219 </if>
220 <if test="$shebang!='' or $doclines[normalize-space()!='']">
221 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
222 <element name="html:article">
223 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
224 <attribute name="lang">
225 <value-of select="following-sibling::html:dd"/>
226 </attribute>
227 <attribute name="xml:lang">
228 <value-of select="following-sibling::html:dd"/>
229 </attribute>
230 </for-each>
231 <for-each select="$params/html:div/html:dt[string()='profile']">
232 <attribute name="data-lesml-profile">
233 <value-of select="following-sibling::html:dd"/>
234 </attribute>
235 </for-each>
236 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
237 <element name="html:footer">
238 <attribute name="class">
239 <text>head</text>
240 </attribute>
241 <for-each select="$record-separators">
242 <variable name="position" select="position()"/>
243 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
244 <variable name="fields" select="$noshebang[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-separator) or preceding-sibling::*[generate-id()=generate-id($prev-separator)])]"/>
245 <if test="$fields">
246 <element name="html:dl">
247 <for-each select="$fields">
248 <choose>
249 <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
250 <otherwise>
251 <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
252 <element name="html:div">
253 <element name="html:dt">
254 <value-of select="normalize-space(substring-before(., ':'))"/>
255 </element>
256 <element name="html:dd">
257 <variable name="firstline">
258 <choose>
259 <when test="contains(., ':')">
260 <value-of select="normalize-space(substring-after(., ':'))"/>
261 </when>
262 <otherwise>
263 <value-of select="normalize-space(.)"/>
264 </otherwise>
265 </choose>
266 </variable>
267 <choose>
268 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
269 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
270 </when>
271 <otherwise>
272 <value-of select="$firstline"/>
273 </otherwise>
274 </choose>
275 <for-each select="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
276 <variable name="nextline" select="normalize-space(.)"/>
277 <choose>
278 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
279 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
280 </when>
281 <otherwise>
282 <value-of select="$nextline"/>
283 </otherwise>
284 </choose>
285 </for-each>
286 </element>
287 </element>
288 </otherwise>
289 </choose>
290 </for-each>
291 </element>
292 </if>
293 <if test=".!='%%'">
294 <comment>
295 <value-of select="substring-after(., '%%')"/>
296 </comment>
297 </if>
298 </for-each>
299 </element>
300 </if>
301 <element name="html:div">
302 <attribute name="class">
303 <text>body</text>
304 </attribute>
305 <call-template name="LesML:paragraphize">
306 <with-param name="lines" select="$doclines[not($record-separators) or preceding-sibling::*[generate-id()=generate-id($record-separators[last()])]]"/>
307 </call-template>
308 </element>
309 </element>
310 </if>
311 <if test="$docsep">
312 <call-template name="LesML:parse">
313 <with-param name="lines" select="$docsep|$lines[preceding-sibling::*[generate-id()=generate-id($docsep)]]"/>
314 <with-param name="parent-params" select="$params"/>
315 </call-template>
316 </if>
317 </template>
318 <template name="LesML:paragraphize">
319 <param name="lines" select="/.."/>
320 <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
321 <variable name="blocked">
322 <for-each select="$last-lines">
323 <variable name="position" select="position()"/>
324 <variable name="prev-last" select="$last-lines[($position)-1]"/>
325 <variable name="linespans" select="$lines[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-last) or preceding-sibling::*[generate-id()=generate-id($prev-last)]) and normalize-space()!='']|."/>
326 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '&#x9;'))])"/>
327 <variable name="preformatted" select="not($linespans[not(starts-with(normalize-space(), '|'))])"/>
328 <variable name="text">
329 <for-each select="$linespans">
330 <choose>
331 <when test="$preformatted">
332 <value-of select="substring-after(., '|')"/>
333 </when>
334 <otherwise>
335 <value-of select="normalize-space()"/>
336 </otherwise>
337 </choose>
338 <if test="position()!=count($linespans)">
339 <choose>
340 <when test="$preformatted">
341 <text>&#xA;</text>
342 </when>
343 <otherwise>
344 <text> </text>
345 </otherwise>
346 </choose>
347 </if>
348 </for-each>
349 </variable>
350 <if test="string($text)!=''">
351 <variable name="par">
352 <choose>
353 <when test="$preformatted">
354 <element name="html:pre">
355 <call-template name="LesML:id-and-contents">
356 <with-param name="source" select="$text"/>
357 </call-template>
358 </element>
359 </when>
360 <when test="starts-with($text, '⁌') and &sigiled-text;">
361 <element name="html:h1">
362 <call-template name="LesML:id-and-contents">
363 <with-param name="source" select="&unsigiled-text;"/>
364 </call-template>
365 </element>
366 </when>
367 <when test="starts-with($text, '§') and &sigiled-text;">
368 <element name="html:h2">
369 <call-template name="LesML:id-and-contents">
370 <with-param name="source" select="&unsigiled-text;"/>
371 </call-template>
372 </element>
373 </when>
374 <when test="starts-with($text, '❦') and &sigiled-text;">
375 <element name="html:h3">
376 <call-template name="LesML:id-and-contents">
377 <with-param name="source" select="&unsigiled-text;"/>
378 </call-template>
379 </element>
380 </when>
381 <when test="starts-with($text, '✠') and &sigiled-text;">
382 <element name="html:h4">
383 <call-template name="LesML:id-and-contents">
384 <with-param name="source" select="&unsigiled-text;"/>
385 </call-template>
386 </element>
387 </when>
388 <when test="starts-with($text, '•') and &sigiled-text;">
389 <element name="html:li">
390 <attribute name="class">
391 <text>unordered</text>
392 </attribute>
393 <attribute name="data-level">
394 <text>1</text>
395 </attribute>
396 <element name="html:p">
397 <call-template name="LesML:id-and-contents">
398 <with-param name="source" select="&unsigiled-text;"/>
399 </call-template>
400 </element>
401 </element>
402 </when>
403 <when test="starts-with($text, '🔢') and &sigiled-text;">
404 <element name="html:li">
405 <attribute name="class">
406 <text>ordered</text>
407 </attribute>
408 <attribute name="data-level">
409 <text>1</text>
410 </attribute>
411 <element name="html:p">
412 <call-template name="LesML:id-and-contents">
413 <with-param name="source" select="&unsigiled-text;"/>
414 </call-template>
415 </element>
416 </element>
417 </when>
418 <when test="starts-with($text, '◦') and &sigiled-text;">
419 <element name="html:li">
420 <attribute name="class">
421 <text>unordered</text>
422 </attribute>
423 <attribute name="data-level">
424 <text>2</text>
425 </attribute>
426 <element name="html:p">
427 <call-template name="LesML:id-and-contents">
428 <with-param name="source" select="&unsigiled-text;"/>
429 </call-template>
430 </element>
431 </element>
432 </when>
433 <when test="starts-with($text, '🔠') and &sigiled-text;">
434 <element name="html:li">
435 <attribute name="class">
436 <text>ordered</text>
437 </attribute>
438 <attribute name="data-level">
439 <text>2</text>
440 </attribute>
441 <element name="html:p">
442 <call-template name="LesML:id-and-contents">
443 <with-param name="source" select="&unsigiled-text;"/>
444 </call-template>
445 </element>
446 </element>
447 </when>
448 <when test="starts-with($text, '▪') and &sigiled-text;">
449 <element name="html:li">
450 <attribute name="class">
451 <text>unordered</text>
452 </attribute>
453 <attribute name="data-level">
454 <text>3</text>
455 </attribute>
456 <element name="html:p">
457 <call-template name="LesML:id-and-contents">
458 <with-param name="source" select="&unsigiled-text;"/>
459 </call-template>
460 </element>
461 </element>
462 </when>
463 <when test="starts-with($text, '🔡') and &sigiled-text;">
464 <element name="html:li">
465 <attribute name="class">
466 <text>ordered</text>
467 </attribute>
468 <attribute name="data-level">
469 <text>3</text>
470 </attribute>
471 <element name="html:p">
472 <call-template name="LesML:id-and-contents">
473 <with-param name="source" select="&unsigiled-text;"/>
474 </call-template>
475 </element>
476 </element>
477 </when>
478 <when test="starts-with($text, '⁃') and &sigiled-text;">
479 <element name="html:li">
480 <attribute name="class">
481 <text>unordered</text>
482 </attribute>
483 <attribute name="data-level">
484 <text>4</text>
485 </attribute>
486 <element name="html:p">
487 <call-template name="LesML:id-and-contents">
488 <with-param name="source" select="&unsigiled-text;"/>
489 </call-template>
490 </element>
491 </element>
492 </when>
493 <when test="starts-with($text, '🔣') and &sigiled-text;">
494 <element name="html:li">
495 <attribute name="class">
496 <text>ordered</text>
497 </attribute>
498 <attribute name="data-level">
499 <text>4</text>
500 </attribute>
501 <element name="html:p">
502 <call-template name="LesML:id-and-contents">
503 <with-param name="source" select="&unsigiled-text;"/>
504 </call-template>
505 </element>
506 </element>
507 </when>
508 <when test="starts-with($text, '🛈') and &sigiled-text;">
509 <element name="html:div">
510 <attribute name="role">
511 <text>note</text>
512 </attribute>
513 <attribute name="class">
514 <text>info</text>
515 </attribute>
516 <element name="html:p">
517 <call-template name="LesML:id-and-contents">
518 <with-param name="source" select="&unsigiled-text;"/>
519 </call-template>
520 </element>
521 </element>
522 </when>
523 <when test="starts-with($text, '⯑') and &sigiled-text;">
524 <element name="html:div">
525 <attribute name="role">
526 <text>note</text>
527 </attribute>
528 <attribute name="class">
529 <text>query</text>
530 </attribute>
531 <element name="html:p">
532 <call-template name="LesML:id-and-contents">
533 <with-param name="source" select="&unsigiled-text;"/>
534 </call-template>
535 </element>
536 </element>
537 </when>
538 <when test="starts-with($text, '⚠︎') and &sigiled-text;">
539 <element name="html:div">
540 <attribute name="role">
541 <text>note</text>
542 </attribute>
543 <attribute name="class">
544 <text>warn</text>
545 </attribute>
546 <element name="html:p">
547 <call-template name="LesML:id-and-contents">
548 <with-param name="source" select="&unsigiled-text;"/>
549 </call-template>
550 </element>
551 </element>
552 </when>
553 <when test="starts-with($text, '※') and &sigiled-text;">
554 <element name="html:div">
555 <attribute name="role">
556 <text>note</text>
557 </attribute>
558 <attribute name="class">
559 <text>note</text>
560 </attribute>
561 <element name="html:p">
562 <call-template name="LesML:id-and-contents">
563 <with-param name="source" select="&unsigiled-text;"/>
564 </call-template>
565 </element>
566 </element>
567 </when>
568 <when test="starts-with($text, '☡') and &sigiled-text;">
569 <element name="html:div">
570 <attribute name="role">
571 <text>note</text>
572 </attribute>
573 <attribute name="class">
574 <text>caution</text>
575 </attribute>
576 <element name="html:p">
577 <call-template name="LesML:id-and-contents">
578 <with-param name="source" select="&unsigiled-text;"/>
579 </call-template>
580 </element>
581 </element>
582 </when>
583 <when test="starts-with($text, '⋯') and &sigiled-text;">
584 <element name="html:div">
585 <attribute name="class">
586 <text>continuation</text>
587 </attribute>
588 <element name="html:p">
589 <call-template name="LesML:id-and-contents">
590 <with-param name="source" select="&unsigiled-text;"/>
591 </call-template>
592 </element>
593 </element>
594 </when>
595 <when test="starts-with($text, '#') and &sigiled-text;">
596 <comment>
597 <value-of select="&unsigiled-text;"/>
598 </comment>
599 </when>
600 <otherwise>
601 <element name="html:p">
602 <call-template name="LesML:id-and-contents">
603 <with-param name="source" select="$text"/>
604 </call-template>
605 </element>
606 </otherwise>
607 </choose>
608 </variable>
609 <choose>
610 <when test="translate(string($text), '&section-break; ', '')=''">
611 <element name="html:hr"/>
612 </when>
613 <when test="$quoted">
614 <element name="html:blockquote">
615 <copy-of select="$par"/>
616 </element>
617 </when>
618 <otherwise>
619 <copy-of select="$par"/>
620 </otherwise>
621 </choose>
622 </if>
623 </for-each>
624 </variable>
625 <variable name="inlined">
626 <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
627 </variable>
628 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
629 </template>
630 <template match="html:script[@type='text/lesml']">
631 <variable name="lines-fragment">
632 <call-template name="LesML:split">
633 <with-param name="source">
634 <for-each select=".//text()">
635 <value-of select="."/>
636 </for-each>
637 </with-param>
638 </call-template>
639 </variable>
640 <call-template name="LesML:parse">
641 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
642 </call-template>
643 </template>
644 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
645 <copy>
646 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
647 </copy>
648 </template>
649 <template match="text()" mode="LesML:finalize-tree">
650 <call-template name="LesML:break-and-unescape">
651 <with-param name="source" select="string(.)"/>
652 </call-template>
653 </template>
654 <template match="html:blockquote" mode="LesML:finalize-tree">
655 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
656 <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
657 <variable name="contents">
658 <copy-of select="node()"/>
659 <for-each select="following-sibling::node()[not($notquote) or following-sibling::node()[generate-id()=generate-id($notquote)]]">
660 <copy-of select="node()"/>
661 </for-each>
662 </variable>
663 <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
664 <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()]"/>
665 <choose>
666 <when test="starts-with($laststarttext, '— ')">
667 <variable name="caption">
668 <copy-of select="$laststarttext/preceding-sibling::node()"/>
669 <value-of select="substring-after($laststarttext, '— ')"/>
670 <copy-of select="$laststarttext/following-sibling::node()"/>
671 </variable>
672 <element name="html:figure">
673 <copy>
674 <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
675 </copy>
676 <element name="html:figcaption">
677 <for-each select="$content-nodes[last()]">
678 <copy>
679 <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
680 </copy>
681 </for-each>
682 </element>
683 </element>
684 </when>
685 <otherwise>
686 <copy>
687 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
688 </copy>
689 </otherwise>
690 </choose>
691 </if>
692 </template>
693 <template match="html:div" mode="LesML:finalize-tree">
694 <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)]">
695 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
696 <copy>
697 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
698 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
699 <apply-templates select="node()" mode="LesML:finalize-tree"/>
700 </for-each>
701 </copy>
702 </if>
703 </template>
704 <template match="html:li" mode="LesML:finalize-tree">
705 <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)]">
706 <apply-templates select="." mode="LesML:finalize-list"/>
707 </if>
708 </template>
709 <template match="html:li" mode="LesML:finalize-list">
710 <param name="parent-level" select="0"/>
711 <variable name="current-class" select="string(@class)"/>
712 <variable name="current-level" select="number(@data-level)"/>
713 <variable name="wrapper">
714 <choose>
715 <when test="@class='ordered'">
716 <text>ol</text>
717 </when>
718 <otherwise>
719 <text>ul</text>
720 </otherwise>
721 </choose>
722 </variable>
723 <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]"/>
724 <element name="html:{$wrapper}" namespace="http://www.w3.org/1999/xhtml">
725 <for-each select=".|following-sibling::html:li[@data-level=$current-level and (not($notinlist) or following-sibling::node()[generate-id()=generate-id($notinlist)])]">
726 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
727 <copy>
728 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
729 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
730 <apply-templates select="node()" mode="LesML:finalize-tree"/>
731 </for-each>
732 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
733 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
734 <with-param name="parent-level" select="$current-level"/>
735 </apply-templates>
736 </if>
737 </copy>
738 </for-each>
739 </element>
740 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
741 <apply-templates select="$notinlist" mode="LesML:finalize-list">
742 <with-param name="parent-level" select="$parent-level"/>
743 </apply-templates>
744 </if>
745 </template>
746 <template match="node()" mode="LesML:inline">
747 <param name="element-name"/>
748 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
749 <param name="start-sigil"/>
750 <param name="end-sigil"/>
751 <param name="role"/>
752 <param name="langtag-supported" select="false()"/>
753 <choose>
754 <when test="self::*">
755 <copy>
756 <copy-of select="@*"/>
757 <variable name="start-node" select="text()[contains(., $start-sigil)][1]"/>
758 <choose>
759 <when test="$start-node">
760 <variable name="remaining">
761 <value-of select="substring-after($start-node, $start-sigil)"/>
762 <copy-of select="$start-node/following-sibling::node()"/>
763 </variable>
764 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., $end-sigil)][1]"/>
765 <choose>
766 <when test="$end-node">
767 <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
768 <variable name="maybe-langtag">
769 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
770 <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
771 </if>
772 </variable>
773 <variable name="langtag">
774 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
775 <value-of select="$maybe-langtag"/>
776 </if>
777 </variable>
778 <variable name="rest">
779 <html:div>
780 <choose>
781 <when test="string($langtag)!=''">
782 <value-of select="substring-after($restoftext, '$')"/>
783 </when>
784 <otherwise>
785 <value-of select="$restoftext"/>
786 </otherwise>
787 </choose>
788 <copy-of select="$end-node/following-sibling::node()"/>
789 </html:div>
790 </variable>
791 <variable name="processed-rest">
792 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:inline">
793 <with-param name="element-name" select="$element-name"/>
794 <with-param name="element-namespace" select="$element-namespace"/>
795 <with-param name="start-sigil" select="$start-sigil"/>
796 <with-param name="end-sigil" select="$end-sigil"/>
797 <with-param name="role" select="$role"/>
798 <with-param name="langtag-supported" select="$langtag-supported"/>
799 </apply-templates>
800 </variable>
801 <copy-of select="$start-node/preceding-sibling::node()"/>
802 <value-of select="substring-before($start-node, $start-sigil)"/>
803 <element name="{$element-name}" namespace="{$element-namespace}">
804 <if test="string($role)!=''">
805 <attribute name="role">
806 <value-of select="$role"/>
807 </attribute>
808 </if>
809 <if test="string($langtag)!=''">
810 <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
811 <attribute name="lang">
812 <value-of select="$langtag"/>
813 </attribute>
814 </if>
815 <attribute name="xml:lang">
816 <value-of select="$langtag"/>
817 </attribute>
818 </if>
819 <copy-of select="$end-node/preceding-sibling::node()"/>
820 <value-of select="substring-before($end-node, $end-sigil)"/>
821 </element>
822 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
823 </when>
824 <otherwise>
825 <apply-templates select="node()" mode="LesML:inline">
826 <with-param name="element-name" select="$element-name"/>
827 <with-param name="element-namespace" select="$element-namespace"/>
828 <with-param name="start-sigil" select="$start-sigil"/>
829 <with-param name="end-sigil" select="$end-sigil"/>
830 <with-param name="role" select="$role"/>
831 <with-param name="langtag-supported" select="$langtag-supported"/>
832 </apply-templates>
833 </otherwise>
834 </choose>
835 </when>
836 <otherwise>
837 <apply-templates select="node()" mode="LesML:inline">
838 <with-param name="element-name" select="$element-name"/>
839 <with-param name="element-namespace" select="$element-namespace"/>
840 <with-param name="start-sigil" select="$start-sigil"/>
841 <with-param name="end-sigil" select="$end-sigil"/>
842 <with-param name="role" select="$role"/>
843 <with-param name="langtag-supported" select="$langtag-supported"/>
844 </apply-templates>
845 </otherwise>
846 </choose>
847 </copy>
848 </when>
849 <otherwise>
850 <copy-of select="."/>
851 </otherwise>
852 </choose>
853 </template>
854 <template match="node()" mode="LesML:linkify">
855 <variable name="result">
856 <choose>
857 <when test="self::*">
858 <copy>
859 <copy-of select="@*"/>
860 <variable name="start-node" select="text()[contains(., '{🔗')][1]"/>
861 <choose>
862 <when test="$start-node">
863 <variable name="remaining">
864 <value-of select="substring-after($start-node, '{🔗')"/>
865 <copy-of select="$start-node/following-sibling::node()"/>
866 </variable>
867 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., '>}') and not(preceding-sibling::*)][1]"/>
868 <variable name="hyperlink">
869 <for-each select="$end-node/preceding-sibling::node()">
870 <value-of select="."/>
871 </for-each>
872 <value-of select="substring-before($end-node, '>}')"/>
873 </variable>
874 <choose>
875 <when test="contains($hyperlink, '&lt;')">
876 <variable name="ltcomponents">
877 <call-template name="LesML:split">
878 <with-param name="source" select="$hyperlink"/>
879 <with-param name="separator" select="'&lt;'"/>
880 </call-template>
881 </variable>
882 <variable name="ltcomponent-nodes" select="exsl:node-set($ltcomponents)/*"/>
883 <variable name="rest">
884 <html:div>
885 <value-of select="substring-after($end-node, '>}')"/>
886 <copy-of select="$end-node/following-sibling::node()"/>
887 </html:div>
888 </variable>
889 <variable name="processed-rest">
890 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
891 </variable>
892 <copy-of select="$start-node/preceding-sibling::node()"/>
893 <value-of select="substring-before($start-node, '{🔗')"/>
894 <element name="html:a">
895 <attribute name="href">
896 <value-of select="$ltcomponent-nodes[last()]"/>
897 </attribute>
898 <choose>
899 <when test="count($ltcomponent-nodes)>2 or normalize-space($ltcomponent-nodes[1])!=''">
900 <value-of select="$ltcomponent-nodes[1]"/>
901 <for-each select="$ltcomponent-nodes[position()>1 and position()!=last()]">
902 <text>&lt;</text>
903 <value-of select="."/>
904 </for-each>
905 </when>
906 <otherwise>
907 <value-of select="$ltcomponent-nodes[last()]"/>
908 </otherwise>
909 </choose>
910 </element>
911 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
912 </when>
913 <otherwise>
914 <variable name="rest">
915 <html:div>
916 <copy-of select="$remaining"/>
917 </html:div>
918 </variable>
919 <variable name="processed-rest">
920 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
921 </variable>
922 <copy-of select="$start-node/preceding-sibling::node()"/>
923 <value-of select="substring-before($start-node, '{🔗')"/>
924 <text>{🔗</text>
925 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
926 </otherwise>
927 </choose>
928 </when>
929 <otherwise>
930 <apply-templates select="node()" mode="LesML:linkify"/>
931 </otherwise>
932 </choose>
933 </copy>
934 </when>
935 <otherwise>
936 <copy-of select="."/>
937 </otherwise>
938 </choose>
939 </variable>
940 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
941 </template>
942 <template match="node()" mode="LesML:strikethrough">
943 <variable name="result">
944 <apply-templates select="." mode="LesML:inline">
945 <with-param name="element-name" select="'html:s'"/>
946 <with-param name="start-sigil" select="'⸠'"/>
947 <with-param name="end-sigil" select="'⸡'"/>
948 </apply-templates>
949 </variable>
950 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
951 </template>
952 <template match="node()" mode="LesML:underline">
953 <variable name="result">
954 <apply-templates select="." mode="LesML:inline">
955 <with-param name="element-name" select="'html:u'"/>
956 <with-param name="start-sigil" select="'⸤'"/>
957 <with-param name="end-sigil" select="'⸥'"/>
958 </apply-templates>
959 </variable>
960 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
961 </template>
962 <template match="node()" mode="LesML:noted">
963 <variable name="result">
964 <apply-templates select="." mode="LesML:inline">
965 <with-param name="element-name" select="'html:small'"/>
966 <with-param name="start-sigil" select="'⟦'"/>
967 <with-param name="end-sigil" select="'⟧'"/>
968 <with-param name="role" select="'note'"/>
969 </apply-templates>
970 </variable>
971 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
972 </template>
973 <template match="node()" mode="LesML:parenthetical">
974 <variable name="result">
975 <apply-templates select="." mode="LesML:inline">
976 <with-param name="element-name" select="'html:small'"/>
977 <with-param name="start-sigil" select="'⸨'"/>
978 <with-param name="end-sigil" select="'⸩'"/>
979 </apply-templates>
980 </variable>
981 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
982 </template>
983 <template match="node()" mode="LesML:important">
984 <variable name="result">
985 <apply-templates select="." mode="LesML:inline">
986 <with-param name="element-name" select="'html:strong'"/>
987 <with-param name="start-sigil" select="'☞'"/>
988 <with-param name="end-sigil" select="'☜'"/>
989 </apply-templates>
990 </variable>
991 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
992 </template>
993 <template match="node()" mode="LesML:emphasized">
994 <variable name="result">
995 <apply-templates select="." mode="LesML:inline">
996 <with-param name="element-name" select="'html:em'"/>
997 <with-param name="start-sigil" select="'⹐'"/>
998 <with-param name="end-sigil" select="'⹑'"/>
999 </apply-templates>
1000 </variable>
1001 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
1002 </template>
1003 <template match="node()" mode="LesML:titled">
1004 <variable name="result">
1005 <apply-templates select="." mode="LesML:inline">
1006 <with-param name="element-name" select="'html:cite'"/>
1007 <with-param name="start-sigil" select="'⟪'"/>
1008 <with-param name="end-sigil" select="'⟫'"/>
1009 </apply-templates>
1010 </variable>
1011 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
1012 </template>
1013 <template match="node()" mode="LesML:offset">
1014 <variable name="result">
1015 <apply-templates select="." mode="LesML:inline">
1016 <with-param name="element-name" select="'html:i'"/>
1017 <with-param name="start-sigil" select="'⟨'"/>
1018 <with-param name="end-sigil" select="'⟩'"/>
1019 <with-param name="langtag-supported" select="true()"/>
1020 </apply-templates>
1021 </variable>
1022 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
1023 </template>
1024 <template match="node()" mode="LesML:bolded">
1025 <variable name="result">
1026 <apply-templates select="." mode="LesML:inline">
1027 <with-param name="element-name" select="'html:b'"/>
1028 <with-param name="start-sigil" select="'⦃'"/>
1029 <with-param name="end-sigil" select="'⦄'"/>
1030 </apply-templates>
1031 </variable>
1032 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
1033 </template>
1034 <template match="node()" mode="LesML:code">
1035 <apply-templates select="." mode="LesML:inline">
1036 <with-param name="element-name" select="'html:code'"/>
1037 <with-param name="start-sigil" select="'`'"/>
1038 <with-param name="end-sigil" select="'´'"/>
1039 </apply-templates>
1040 </template>
1041 </transform>
This page took 0.174357 seconds and 5 git commands to generate.