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