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