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