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