]> Lady’s Gitweb - LesML/blob - parser.xslt
fbfa6241bb654b233b22e0f1fd0a5e1f4bd0adc3
[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 <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 <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 <html:footer class="head">
238 <for-each select="$record-separators">
239 <variable name="position" select="position()"/>
240 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
241 <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)])]"/>
242 <if test="$fields">
243 <html:dl>
244 <for-each select="$fields">
245 <choose>
246 <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
247 <otherwise>
248 <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
249 <html:div>
250 <html:dt>
251 <value-of select="normalize-space(substring-before(., ':'))"/>
252 </html:dt>
253 <html:dd>
254 <variable name="firstline">
255 <choose>
256 <when test="contains(., ':')">
257 <value-of select="normalize-space(substring-after(., ':'))"/>
258 </when>
259 <otherwise>
260 <value-of select="normalize-space(.)"/>
261 </otherwise>
262 </choose>
263 </variable>
264 <choose>
265 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
266 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
267 </when>
268 <otherwise>
269 <value-of select="$firstline"/>
270 </otherwise>
271 </choose>
272 <for-each select="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
273 <variable name="nextline" select="normalize-space(.)"/>
274 <choose>
275 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
276 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
277 </when>
278 <otherwise>
279 <value-of select="$nextline"/>
280 </otherwise>
281 </choose>
282 </for-each>
283 </html:dd>
284 </html:div>
285 </otherwise>
286 </choose>
287 </for-each>
288 </html:dl>
289 </if>
290 <if test=".!='%%'">
291 <comment>
292 <value-of select="substring-after(., '%%')"/>
293 </comment>
294 </if>
295 </for-each>
296 </html:footer>
297 </if>
298 <html:div class="body">
299 <call-template name="LesML:paragraphize">
300 <with-param name="lines" select="$doclines[not($record-separators) or preceding-sibling::*[generate-id()=generate-id($record-separators[last()])]]"/>
301 </call-template>
302 </html:div>
303 </html:article>
304 </if>
305 <if test="$docsep">
306 <call-template name="LesML:parse">
307 <with-param name="lines" select="$docsep|$lines[preceding-sibling::*[generate-id()=generate-id($docsep)]]"/>
308 <with-param name="parent-params" select="$params"/>
309 </call-template>
310 </if>
311 </template>
312 <template name="LesML:paragraphize">
313 <param name="lines" select="/.."/>
314 <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
315 <variable name="blocked">
316 <for-each select="$last-lines">
317 <variable name="position" select="position()"/>
318 <variable name="prev-last" select="$last-lines[($position)-1]"/>
319 <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()!='']|."/>
320 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '&#x9;'))])"/>
321 <variable name="preformatted" select="not($linespans[not(starts-with(normalize-space(), '|'))])"/>
322 <variable name="text">
323 <for-each select="$linespans">
324 <choose>
325 <when test="$preformatted">
326 <value-of select="substring-after(., '|')"/>
327 </when>
328 <otherwise>
329 <value-of select="normalize-space()"/>
330 </otherwise>
331 </choose>
332 <if test="position()!=count($linespans)">
333 <choose>
334 <when test="$preformatted">
335 <text>&#xA;</text>
336 </when>
337 <otherwise>
338 <text> </text>
339 </otherwise>
340 </choose>
341 </if>
342 </for-each>
343 </variable>
344 <if test="string($text)!=''">
345 <variable name="par">
346 <choose>
347 <when test="$preformatted">
348 <html:pre>
349 <call-template name="LesML:id-and-contents">
350 <with-param name="source" select="$text"/>
351 </call-template>
352 </html:pre>
353 </when>
354 <when test="starts-with($text, '⁌') and &sigiled-text;">
355 <html:h1>
356 <call-template name="LesML:id-and-contents">
357 <with-param name="source" select="&unsigiled-text;"/>
358 </call-template>
359 </html:h1>
360 </when>
361 <when test="starts-with($text, '§') and &sigiled-text;">
362 <html:h2>
363 <call-template name="LesML:id-and-contents">
364 <with-param name="source" select="&unsigiled-text;"/>
365 </call-template>
366 </html:h2>
367 </when>
368 <when test="starts-with($text, '❦') and &sigiled-text;">
369 <html:h3>
370 <call-template name="LesML:id-and-contents">
371 <with-param name="source" select="&unsigiled-text;"/>
372 </call-template>
373 </html:h3>
374 </when>
375 <when test="starts-with($text, '✠') and &sigiled-text;">
376 <html:h4>
377 <call-template name="LesML:id-and-contents">
378 <with-param name="source" select="&unsigiled-text;"/>
379 </call-template>
380 </html:h4>
381 </when>
382 <when test="starts-with($text, '•') and &sigiled-text;">
383 <html:li class="unordered" data-level="1">
384 <html:p>
385 <call-template name="LesML:id-and-contents">
386 <with-param name="source" select="&unsigiled-text;"/>
387 </call-template>
388 </html:p>
389 </html:li>
390 </when>
391 <when test="starts-with($text, '🔢') and &sigiled-text;">
392 <html:li class="ordered" data-level="1">
393 <html:p>
394 <call-template name="LesML:id-and-contents">
395 <with-param name="source" select="&unsigiled-text;"/>
396 </call-template>
397 </html:p>
398 </html:li>
399 </when>
400 <when test="starts-with($text, '◦') and &sigiled-text;">
401 <html:li class="unordered" data-level="2">
402 <html:p>
403 <call-template name="LesML:id-and-contents">
404 <with-param name="source" select="&unsigiled-text;"/>
405 </call-template>
406 </html:p>
407 </html:li>
408 </when>
409 <when test="starts-with($text, '🔠') and &sigiled-text;">
410 <html:li class="ordered" data-level="2">
411 <html:p>
412 <call-template name="LesML:id-and-contents">
413 <with-param name="source" select="&unsigiled-text;"/>
414 </call-template>
415 </html:p>
416 </html:li>
417 </when>
418 <when test="starts-with($text, '▪') and &sigiled-text;">
419 <html:li class="unordered" data-level="3">
420 <html:p>
421 <call-template name="LesML:id-and-contents">
422 <with-param name="source" select="&unsigiled-text;"/>
423 </call-template>
424 </html:p>
425 </html:li>
426 </when>
427 <when test="starts-with($text, '🔡') and &sigiled-text;">
428 <html:li class="ordered" data-level="3">
429 <html:p>
430 <call-template name="LesML:id-and-contents">
431 <with-param name="source" select="&unsigiled-text;"/>
432 </call-template>
433 </html:p>
434 </html:li>
435 </when>
436 <when test="starts-with($text, '⁃') and &sigiled-text;">
437 <html:li class="unordered" data-level="4">
438 <html:p>
439 <call-template name="LesML:id-and-contents">
440 <with-param name="source" select="&unsigiled-text;"/>
441 </call-template>
442 </html:p>
443 </html:li>
444 </when>
445 <when test="starts-with($text, '🔣') and &sigiled-text;">
446 <html:li class="ordered" data-level="4">
447 <html:p>
448 <call-template name="LesML:id-and-contents">
449 <with-param name="source" select="&unsigiled-text;"/>
450 </call-template>
451 </html:p>
452 </html:li>
453 </when>
454 <when test="starts-with($text, '🛈') and &sigiled-text;">
455 <html:div role="note" class="info">
456 <html:p>
457 <call-template name="LesML:id-and-contents">
458 <with-param name="source" select="&unsigiled-text;"/>
459 </call-template>
460 </html:p>
461 </html:div>
462 </when>
463 <when test="starts-with($text, '⯑') and &sigiled-text;">
464 <html:div role="note" class="query">
465 <html:p>
466 <call-template name="LesML:id-and-contents">
467 <with-param name="source" select="&unsigiled-text;"/>
468 </call-template>
469 </html:p>
470 </html:div>
471 </when>
472 <when test="starts-with($text, '⚠︎') and &sigiled-text;">
473 <html:div role="note" class="warn">
474 <html:p>
475 <call-template name="LesML:id-and-contents">
476 <with-param name="source" select="&unsigiled-text;"/>
477 </call-template>
478 </html:p>
479 </html:div>
480 </when>
481 <when test="starts-with($text, '※') and &sigiled-text;">
482 <html:div role="note" class="note">
483 <html:p>
484 <call-template name="LesML:id-and-contents">
485 <with-param name="source" select="&unsigiled-text;"/>
486 </call-template>
487 </html:p>
488 </html:div>
489 </when>
490 <when test="starts-with($text, '☡') and &sigiled-text;">
491 <html:div role="note" class="caution">
492 <html:p>
493 <call-template name="LesML:id-and-contents">
494 <with-param name="source" select="&unsigiled-text;"/>
495 </call-template>
496 </html:p>
497 </html:div>
498 </when>
499 <when test="starts-with($text, '⋯') and &sigiled-text;">
500 <html:div class="continuation">
501 <html:p>
502 <call-template name="LesML:id-and-contents">
503 <with-param name="source" select="&unsigiled-text;"/>
504 </call-template>
505 </html:p>
506 </html:div>
507 </when>
508 <when test="starts-with($text, '#') and &sigiled-text;">
509 <comment>
510 <value-of select="&unsigiled-text;"/>
511 </comment>
512 </when>
513 <otherwise>
514 <html:p>
515 <call-template name="LesML:id-and-contents">
516 <with-param name="source" select="$text"/>
517 </call-template>
518 </html:p>
519 </otherwise>
520 </choose>
521 </variable>
522 <choose>
523 <when test="translate(string($text), '&section-break; ', '')=''">
524 <html:hr/>
525 </when>
526 <when test="$quoted">
527 <html:blockquote>
528 <copy-of select="$par"/>
529 </html:blockquote>
530 </when>
531 <otherwise>
532 <copy-of select="$par"/>
533 </otherwise>
534 </choose>
535 </if>
536 </for-each>
537 </variable>
538 <variable name="inlined">
539 <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
540 </variable>
541 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
542 </template>
543 <template match="html:script[@type='text/lesml']">
544 <variable name="lines-fragment">
545 <call-template name="LesML:split">
546 <with-param name="source">
547 <for-each select=".//text()">
548 <value-of select="."/>
549 </for-each>
550 </with-param>
551 </call-template>
552 </variable>
553 <call-template name="LesML:parse">
554 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
555 </call-template>
556 </template>
557 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
558 <copy>
559 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
560 </copy>
561 </template>
562 <template match="text()" mode="LesML:finalize-tree">
563 <call-template name="LesML:break-and-unescape">
564 <with-param name="source" select="string(.)"/>
565 </call-template>
566 </template>
567 <template match="html:blockquote" mode="LesML:finalize-tree">
568 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
569 <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
570 <variable name="contents">
571 <copy-of select="node()"/>
572 <for-each select="following-sibling::node()[not($notquote) or following-sibling::node()[generate-id()=generate-id($notquote)]]">
573 <copy-of select="node()"/>
574 </for-each>
575 </variable>
576 <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
577 <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()]"/>
578 <choose>
579 <when test="starts-with($laststarttext, '— ')">
580 <variable name="caption">
581 <copy-of select="$laststarttext/preceding-sibling::node()"/>
582 <value-of select="substring-after($laststarttext, '— ')"/>
583 <copy-of select="$laststarttext/following-sibling::node()"/>
584 </variable>
585 <html:figure>
586 <copy>
587 <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
588 </copy>
589 <html:figcaption>
590 <for-each select="$content-nodes[last()]">
591 <copy>
592 <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
593 </copy>
594 </for-each>
595 </html:figcaption>
596 </html:figure>
597 </when>
598 <otherwise>
599 <copy>
600 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
601 </copy>
602 </otherwise>
603 </choose>
604 </if>
605 </template>
606 <template match="html:div" mode="LesML:finalize-tree">
607 <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)]">
608 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
609 <copy>
610 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
611 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
612 <apply-templates select="node()" mode="LesML:finalize-tree"/>
613 </for-each>
614 </copy>
615 </if>
616 </template>
617 <template match="html:li" mode="LesML:finalize-tree">
618 <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)]">
619 <apply-templates select="." mode="LesML:finalize-list"/>
620 </if>
621 </template>
622 <template match="html:li" mode="LesML:finalize-list">
623 <param name="parent-level" select="0"/>
624 <variable name="current-class" select="string(@class)"/>
625 <variable name="current-level" select="number(@data-level)"/>
626 <variable name="wrapper">
627 <choose>
628 <when test="@class='ordered'">
629 <text>ol</text>
630 </when>
631 <otherwise>
632 <text>ul</text>
633 </otherwise>
634 </choose>
635 </variable>
636 <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]"/>
637 <element name="html:{$wrapper}" namespace="http://www.w3.org/1999/xhtml">
638 <for-each select=".|following-sibling::html:li[@data-level=$current-level and (not($notinlist) or following-sibling::node()[generate-id()=generate-id($notinlist)])]">
639 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
640 <copy>
641 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
642 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
643 <apply-templates select="node()" mode="LesML:finalize-tree"/>
644 </for-each>
645 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
646 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
647 <with-param name="parent-level" select="$current-level"/>
648 </apply-templates>
649 </if>
650 </copy>
651 </for-each>
652 </element>
653 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
654 <apply-templates select="$notinlist" mode="LesML:finalize-list">
655 <with-param name="parent-level" select="$parent-level"/>
656 </apply-templates>
657 </if>
658 </template>
659 <template match="node()" mode="LesML:inline">
660 <param name="element-name"/>
661 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
662 <param name="start-sigil"/>
663 <param name="end-sigil"/>
664 <param name="role"/>
665 <param name="langtag-supported" select="false()"/>
666 <choose>
667 <when test="self::*">
668 <copy>
669 <copy-of select="@*"/>
670 <variable name="start-node" select="text()[contains(., $start-sigil)][1]"/>
671 <choose>
672 <when test="$start-node">
673 <variable name="remaining">
674 <value-of select="substring-after($start-node, $start-sigil)"/>
675 <copy-of select="$start-node/following-sibling::node()"/>
676 </variable>
677 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., $end-sigil)][1]"/>
678 <choose>
679 <when test="$end-node">
680 <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
681 <variable name="maybe-langtag">
682 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
683 <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
684 </if>
685 </variable>
686 <variable name="langtag">
687 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
688 <value-of select="$maybe-langtag"/>
689 </if>
690 </variable>
691 <variable name="rest">
692 <html:div>
693 <choose>
694 <when test="string($langtag)!=''">
695 <value-of select="substring-after($restoftext, '$')"/>
696 </when>
697 <otherwise>
698 <value-of select="$restoftext"/>
699 </otherwise>
700 </choose>
701 <copy-of select="$end-node/following-sibling::node()"/>
702 </html:div>
703 </variable>
704 <variable name="processed-rest">
705 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:inline">
706 <with-param name="element-name" select="$element-name"/>
707 <with-param name="element-namespace" select="$element-namespace"/>
708 <with-param name="start-sigil" select="$start-sigil"/>
709 <with-param name="end-sigil" select="$end-sigil"/>
710 <with-param name="role" select="$role"/>
711 <with-param name="langtag-supported" select="$langtag-supported"/>
712 </apply-templates>
713 </variable>
714 <copy-of select="$start-node/preceding-sibling::node()"/>
715 <value-of select="substring-before($start-node, $start-sigil)"/>
716 <element name="{$element-name}" namespace="{$element-namespace}">
717 <if test="string($role)!=''">
718 <attribute name="role">
719 <value-of select="$role"/>
720 </attribute>
721 </if>
722 <if test="string($langtag)!=''">
723 <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
724 <attribute name="lang">
725 <value-of select="$langtag"/>
726 </attribute>
727 </if>
728 <attribute name="xml:lang">
729 <value-of select="$langtag"/>
730 </attribute>
731 </if>
732 <copy-of select="$end-node/preceding-sibling::node()"/>
733 <value-of select="substring-before($end-node, $end-sigil)"/>
734 </element>
735 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
736 </when>
737 <otherwise>
738 <apply-templates select="node()" mode="LesML:inline">
739 <with-param name="element-name" select="$element-name"/>
740 <with-param name="element-namespace" select="$element-namespace"/>
741 <with-param name="start-sigil" select="$start-sigil"/>
742 <with-param name="end-sigil" select="$end-sigil"/>
743 <with-param name="role" select="$role"/>
744 <with-param name="langtag-supported" select="$langtag-supported"/>
745 </apply-templates>
746 </otherwise>
747 </choose>
748 </when>
749 <otherwise>
750 <apply-templates select="node()" mode="LesML:inline">
751 <with-param name="element-name" select="$element-name"/>
752 <with-param name="element-namespace" select="$element-namespace"/>
753 <with-param name="start-sigil" select="$start-sigil"/>
754 <with-param name="end-sigil" select="$end-sigil"/>
755 <with-param name="role" select="$role"/>
756 <with-param name="langtag-supported" select="$langtag-supported"/>
757 </apply-templates>
758 </otherwise>
759 </choose>
760 </copy>
761 </when>
762 <otherwise>
763 <copy-of select="."/>
764 </otherwise>
765 </choose>
766 </template>
767 <template match="node()" mode="LesML:linkify">
768 <variable name="result">
769 <choose>
770 <when test="self::*">
771 <copy>
772 <copy-of select="@*"/>
773 <variable name="start-node" select="text()[contains(., '{🔗')][1]"/>
774 <choose>
775 <when test="$start-node">
776 <variable name="remaining">
777 <value-of select="substring-after($start-node, '{🔗')"/>
778 <copy-of select="$start-node/following-sibling::node()"/>
779 </variable>
780 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., '>}') and not(preceding-sibling::*)][1]"/>
781 <variable name="hyperlink">
782 <for-each select="$end-node/preceding-sibling::node()">
783 <value-of select="."/>
784 </for-each>
785 <value-of select="substring-before($end-node, '>}')"/>
786 </variable>
787 <choose>
788 <when test="contains($hyperlink, '&lt;')">
789 <variable name="ltcomponents">
790 <call-template name="LesML:split">
791 <with-param name="source" select="$hyperlink"/>
792 <with-param name="separator" select="'&lt;'"/>
793 </call-template>
794 </variable>
795 <variable name="ltcomponent-nodes" select="exsl:node-set($ltcomponents)/*"/>
796 <variable name="rest">
797 <html:div>
798 <value-of select="substring-after($end-node, '>}')"/>
799 <copy-of select="$end-node/following-sibling::node()"/>
800 </html:div>
801 </variable>
802 <variable name="processed-rest">
803 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
804 </variable>
805 <copy-of select="$start-node/preceding-sibling::node()"/>
806 <value-of select="substring-before($start-node, '{🔗')"/>
807 <html:a href="{$ltcomponent-nodes[last()]}">
808 <choose>
809 <when test="count($ltcomponent-nodes)>2 or normalize-space($ltcomponent-nodes[1])!=''">
810 <value-of select="$ltcomponent-nodes[1]"/>
811 <for-each select="$ltcomponent-nodes[position()>1 and position()!=last()]">
812 <text>&lt;</text>
813 <value-of select="."/>
814 </for-each>
815 </when>
816 <otherwise>
817 <value-of select="$ltcomponent-nodes[last()]"/>
818 </otherwise>
819 </choose>
820 </html:a>
821 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
822 </when>
823 <otherwise>
824 <variable name="rest">
825 <html:div>
826 <copy-of select="$remaining"/>
827 </html:div>
828 </variable>
829 <variable name="processed-rest">
830 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
831 </variable>
832 <copy-of select="$start-node/preceding-sibling::node()"/>
833 <value-of select="substring-before($start-node, '{🔗')"/>
834 <text>{🔗</text>
835 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
836 </otherwise>
837 </choose>
838 </when>
839 <otherwise>
840 <apply-templates select="node()" mode="LesML:linkify"/>
841 </otherwise>
842 </choose>
843 </copy>
844 </when>
845 <otherwise>
846 <copy-of select="."/>
847 </otherwise>
848 </choose>
849 </variable>
850 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
851 </template>
852 <template match="node()" mode="LesML:strikethrough">
853 <variable name="result">
854 <apply-templates select="." mode="LesML:inline">
855 <with-param name="element-name" select="'html:s'"/>
856 <with-param name="start-sigil" select="'⸠'"/>
857 <with-param name="end-sigil" select="'⸡'"/>
858 </apply-templates>
859 </variable>
860 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
861 </template>
862 <template match="node()" mode="LesML:underline">
863 <variable name="result">
864 <apply-templates select="." mode="LesML:inline">
865 <with-param name="element-name" select="'html:u'"/>
866 <with-param name="start-sigil" select="'⸤'"/>
867 <with-param name="end-sigil" select="'⸥'"/>
868 </apply-templates>
869 </variable>
870 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
871 </template>
872 <template match="node()" mode="LesML:noted">
873 <variable name="result">
874 <apply-templates select="." mode="LesML:inline">
875 <with-param name="element-name" select="'html:small'"/>
876 <with-param name="start-sigil" select="'⟦'"/>
877 <with-param name="end-sigil" select="'⟧'"/>
878 <with-param name="role" select="'note'"/>
879 </apply-templates>
880 </variable>
881 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
882 </template>
883 <template match="node()" mode="LesML:parenthetical">
884 <variable name="result">
885 <apply-templates select="." mode="LesML:inline">
886 <with-param name="element-name" select="'html:small'"/>
887 <with-param name="start-sigil" select="'⸨'"/>
888 <with-param name="end-sigil" select="'⸩'"/>
889 </apply-templates>
890 </variable>
891 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
892 </template>
893 <template match="node()" mode="LesML:important">
894 <variable name="result">
895 <apply-templates select="." mode="LesML:inline">
896 <with-param name="element-name" select="'html:strong'"/>
897 <with-param name="start-sigil" select="'☞'"/>
898 <with-param name="end-sigil" select="'☜'"/>
899 </apply-templates>
900 </variable>
901 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
902 </template>
903 <template match="node()" mode="LesML:emphasized">
904 <variable name="result">
905 <apply-templates select="." mode="LesML:inline">
906 <with-param name="element-name" select="'html:em'"/>
907 <with-param name="start-sigil" select="'⹐'"/>
908 <with-param name="end-sigil" select="'⹑'"/>
909 </apply-templates>
910 </variable>
911 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
912 </template>
913 <template match="node()" mode="LesML:titled">
914 <variable name="result">
915 <apply-templates select="." mode="LesML:inline">
916 <with-param name="element-name" select="'html:cite'"/>
917 <with-param name="start-sigil" select="'⟪'"/>
918 <with-param name="end-sigil" select="'⟫'"/>
919 </apply-templates>
920 </variable>
921 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
922 </template>
923 <template match="node()" mode="LesML:offset">
924 <variable name="result">
925 <apply-templates select="." mode="LesML:inline">
926 <with-param name="element-name" select="'html:i'"/>
927 <with-param name="start-sigil" select="'⟨'"/>
928 <with-param name="end-sigil" select="'⟩'"/>
929 <with-param name="langtag-supported" select="true()"/>
930 </apply-templates>
931 </variable>
932 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
933 </template>
934 <template match="node()" mode="LesML:bolded">
935 <variable name="result">
936 <apply-templates select="." mode="LesML:inline">
937 <with-param name="element-name" select="'html:b'"/>
938 <with-param name="start-sigil" select="'⦃'"/>
939 <with-param name="end-sigil" select="'⦄'"/>
940 </apply-templates>
941 </variable>
942 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
943 </template>
944 <template match="node()" mode="LesML:code">
945 <apply-templates select="." mode="LesML:inline">
946 <with-param name="element-name" select="'html:code'"/>
947 <with-param name="start-sigil" select="'`'"/>
948 <with-param name="end-sigil" select="'´'"/>
949 </apply-templates>
950 </template>
951 </transform>
This page took 0.199197 seconds and 3 git commands to generate.