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