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