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