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