3 SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
 
   4 SPDX-License-Identifier: MPL-2.0
 
   7 ⁌ 💄📝 Les·M·L ∷ parser.xslt
 
   9 © 2024 Lady [@ Lady’s Computer]
 
  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/>.
 
  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)">
 
  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"
 
  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="'
'"/>
 
  35                         <when test="contains($source, $separator)">
 
  37                                         <value-of select="substring-before($source, $separator)"/>
 
  39                                 <call-template name="LesML:split">
 
  40                                         <with-param name="source" select="substring-after($source, $separator)"/>
 
  41                                         <with-param name="separator" select="$separator"/>
 
  46                                         <value-of select="$source"/>
 
  51         <template name="LesML:break-and-unescape">
 
  52                 <param name="source"/>
 
  53                 <variable name="broken-fragment">
 
  54                         <call-template name="LesML:split">
 
  55                                 <with-param name="source" select="$source"/>
 
  56                                 <with-param name="separator" select="'
'"/>
 
  59                 <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
 
  60                 <for-each select="$broken">
 
  61                         <call-template name="LesML:unescape">
 
  62                                 <with-param name="source" select="string()"/>
 
  64                         <if test="position()!=count($broken)">
 
  65                                 <element name="html:br"/>
 
  69         <template name="LesML:unescape">
 
  70                 <param name="source"/>
 
  72                         <when test="contains($source, '<U+')">
 
  73                                 <variable name="after" select="substring-after($source, '<U+')"/>
 
  75                                         <when test="contains($after, '>')">
 
  76                                                 <variable name="inner" select="substring-before($after, '>')"/>
 
  77                                                 <variable name="components">
 
  78                                                         <call-template name="LesML:split">
 
  79                                                                 <with-param name="source" select="$inner"/>
 
  80                                                                 <with-param name="separator" select="'.'"/>
 
  83                                                 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
 
  85                                                         <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
 
  86                                                                 <value-of select="substring-before($source, '<U+')"/>
 
  88                                                                 <value-of select="$inner"/>
 
  90                                                                 <call-template name="LesML:unescape">
 
  91                                                                         <with-param name="source" select="substring-after($after, '>')"/>
 
  95                                                                 <for-each select="$component-nodes">
 
  96                                                                         <text disable-output-escaping="yes">&#x</text>
 
  97                                                                         <value-of select="."/>
 
 100                                                                 <call-template name="LesML:unescape">
 
 101                                                                         <with-param name="source" select="substring-after($after, '>')"/>
 
 107                                                 <value-of select="substring-before($source, '<U+')"/>
 
 109                                                 <call-template name="LesML:unescape">
 
 110                                                         <with-param name="source" select="$after"/>
 
 116                                 <value-of select="$source"/>
 
 120         <template name="LesML:id-and-contents">
 
 121                 <param name="source"/>
 
 123                         <when test="starts-with($source, '¶')">
 
 125                                         <when test="contains($source, ' ')">
 
 126                                                 <variable name="id" select="substring-before(substring-after($source, '¶'), ' ')"/>
 
 128                                                         <attribute name="id">
 
 129                                                                 <value-of select="$id"/>
 
 132                                                 <value-of select="substring-after($source, ' ')"/>
 
 135                                                 <attribute name="id">
 
 136                                                         <value-of select="substring-after($source, '¶')"/>
 
 142                                 <value-of select="$source"/>
 
 146         <template name="LesML:parse">
 
 147                 <param name="lines" select="/.."/>
 
 148                 <param name="parent-params" select="/.."/>
 
 149                 <variable name="first-line" select="$lines[1]"/>
 
 150                 <variable name="shebang">
 
 151                         <if test="starts-with($first-line, '#!lesml')">
 
 152                                 <value-of select="$first-line"/>
 
 155                 <variable name="params-string">
 
 157                                 <when test="starts-with($shebang, '#!lesml@')">
 
 158                                         <value-of select="substring-after($shebang, '$')"/>
 
 161                                         <value-of select="substring-after($shebang, '#!lesml')"/>
 
 165                 <variable name="params-fragment">
 
 167                                 <when test="$shebang!=''">
 
 169                                                 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
 
 175                                                                         <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
 
 179                                                 <for-each select="exslstr:tokenize($params-string)">
 
 181                                                                 <when test="contains(., '=')">
 
 184                                                                                         <value-of select="substring-before(., '=')"/>
 
 187                                                                                         <value-of select="substring-after(., '=')"/>
 
 194                                                                                         <value-of select="."/>
 
 203                                 <when test="$parent-params">
 
 204                                         <copy-of select="$parent-params"/>
 
 211                 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
 
 212                 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
 
 213                 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
 
 214                 <variable name="doclines" select="$noshebang[not($docsep) or following-sibling::*[generate-id()=generate-id($docsep)]]"/>
 
 215                 <if test="starts-with($first-line, '##') and $first-line!='##'">
 
 217                                 <value-of select="substring-after($first-line, '##')"/>
 
 220                 <if test="$shebang!='' or $doclines[normalize-space()!='']">
 
 221                         <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
 
 222                         <element name="html:article">
 
 223                                 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
 
 224                                         <attribute name="lang">
 
 225                                                 <value-of select="following-sibling::html:dd"/>
 
 227                                         <attribute name="xml:lang">
 
 228                                                 <value-of select="following-sibling::html:dd"/>
 
 231                                 <for-each select="$params/html:div/html:dt[string()='profile']">
 
 232                                         <attribute name="data-lesml-profile">
 
 233                                                 <value-of select="following-sibling::html:dd"/>
 
 236                                 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
 
 237                                         <element name="html:footer">
 
 238                                                 <attribute name="class">
 
 241                                                 <for-each select="$record-separators">
 
 242                                                         <variable name="position" select="position()"/>
 
 243                                                         <variable name="prev-separator" select="$record-separators[($position)-1]"/>
 
 244                                                         <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)])]"/>
 
 246                                                                 <element name="html:dl">
 
 247                                                                         <for-each select="$fields">
 
 249                                                                                         <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
 
 251                                                                                                 <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
 
 252                                                                                                 <element name="html:div">
 
 253                                                                                                         <element name="html:dt">
 
 254                                                                                                                 <value-of select="normalize-space(substring-before(., ':'))"/>
 
 256                                                                                                         <element name="html:dd">
 
 257                                                                                                                 <variable name="firstline">
 
 259                                                                                                                                 <when test="contains(., ':')">
 
 260                                                                                                                                         <value-of select="normalize-space(substring-after(., ':'))"/>
 
 263                                                                                                                                         <value-of select="normalize-space(.)"/>
 
 268                                                                                                                         <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
 
 269                                                                                                                                 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
 
 272                                                                                                                                 <value-of select="$firstline"/>
 
 275                                                                                                                 <for-each select="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
 
 276                                                                                                                         <variable name="nextline" select="normalize-space(.)"/>
 
 278                                                                                                                                 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
 
 279                                                                                                                                         <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
 
 282                                                                                                                                         <value-of select="$nextline"/>
 
 295                                                                         <value-of select="substring-after(., '%%')"/>
 
 301                                 <element name="html:div">
 
 302                                         <attribute name="class">
 
 305                                         <call-template name="LesML:paragraphize">
 
 306                                                 <with-param name="lines" select="$doclines[not($record-separators) or preceding-sibling::*[generate-id()=generate-id($record-separators[last()])]]"/>
 
 312                         <call-template name="LesML:parse">
 
 313                                 <with-param name="lines" select="$docsep|$lines[preceding-sibling::*[generate-id()=generate-id($docsep)]]"/>
 
 314                                 <with-param name="parent-params" select="$params"/>
 
 318         <template name="LesML:paragraphize">
 
 319                 <param name="lines" select="/.."/>
 
 320                 <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
 
 321                 <variable name="blocked">
 
 322                         <for-each select="$last-lines">
 
 323                                 <variable name="position" select="position()"/>
 
 324                                 <variable name="prev-last" select="$last-lines[($position)-1]"/>
 
 325                                 <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()!='']|."/>
 
 326                                 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '	'))])"/>
 
 327                                 <variable name="preformatted" select="not($linespans[not(starts-with(normalize-space(), '|'))])"/>
 
 328                                 <variable name="text">
 
 329                                         <for-each select="$linespans">
 
 331                                                         <when test="$preformatted">
 
 332                                                                 <value-of select="substring-after(., '|')"/>
 
 335                                                                 <value-of select="normalize-space()"/>
 
 338                                                 <if test="position()!=count($linespans)">
 
 340                                                                 <when test="$preformatted">
 
 350                                 <if test="string($text)!=''">
 
 351                                         <variable name="par">
 
 353                                                         <when test="$preformatted">
 
 354                                                                 <element name="html:pre">
 
 355                                                                         <call-template name="LesML:id-and-contents">
 
 356                                                                                 <with-param name="source" select="$text"/>
 
 360                                                         <when test="starts-with($text, '⁌') and &sigiled-text;">
 
 361                                                                 <element name="html:h1">
 
 362                                                                         <call-template name="LesML:id-and-contents">
 
 363                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 367                                                         <when test="starts-with($text, '§') and &sigiled-text;">
 
 368                                                                 <element name="html:h2">
 
 369                                                                         <call-template name="LesML:id-and-contents">
 
 370                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 374                                                         <when test="starts-with($text, '❦') and &sigiled-text;">
 
 375                                                                 <element name="html:h3">
 
 376                                                                         <call-template name="LesML:id-and-contents">
 
 377                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 381                                                         <when test="starts-with($text, '✠') and &sigiled-text;">
 
 382                                                                 <element name="html:h4">
 
 383                                                                         <call-template name="LesML:id-and-contents">
 
 384                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 388                                                         <when test="starts-with($text, '•') and &sigiled-text;">
 
 389                                                                 <element name="html:li">
 
 390                                                                         <attribute name="class">
 
 391                                                                                 <text>unordered</text>
 
 393                                                                         <attribute name="data-level">
 
 396                                                                         <element name="html:p">
 
 397                                                                                 <call-template name="LesML:id-and-contents">
 
 398                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 403                                                         <when test="starts-with($text, '🔢') and &sigiled-text;">
 
 404                                                                 <element name="html:li">
 
 405                                                                         <attribute name="class">
 
 408                                                                         <attribute name="data-level">
 
 411                                                                         <element name="html:p">
 
 412                                                                                 <call-template name="LesML:id-and-contents">
 
 413                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 418                                                         <when test="starts-with($text, '◦') and &sigiled-text;">
 
 419                                                                 <element name="html:li">
 
 420                                                                         <attribute name="class">
 
 421                                                                                 <text>unordered</text>
 
 423                                                                         <attribute name="data-level">
 
 426                                                                         <element name="html:p">
 
 427                                                                                 <call-template name="LesML:id-and-contents">
 
 428                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 433                                                         <when test="starts-with($text, '🔠') and &sigiled-text;">
 
 434                                                                 <element name="html:li">
 
 435                                                                         <attribute name="class">
 
 438                                                                         <attribute name="data-level">
 
 441                                                                         <element name="html:p">
 
 442                                                                                 <call-template name="LesML:id-and-contents">
 
 443                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 448                                                         <when test="starts-with($text, '▪') and &sigiled-text;">
 
 449                                                                 <element name="html:li">
 
 450                                                                         <attribute name="class">
 
 451                                                                                 <text>unordered</text>
 
 453                                                                         <attribute name="data-level">
 
 456                                                                         <element name="html:p">
 
 457                                                                                 <call-template name="LesML:id-and-contents">
 
 458                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 463                                                         <when test="starts-with($text, '🔡') and &sigiled-text;">
 
 464                                                                 <element name="html:li">
 
 465                                                                         <attribute name="class">
 
 468                                                                         <attribute name="data-level">
 
 471                                                                         <element name="html:p">
 
 472                                                                                 <call-template name="LesML:id-and-contents">
 
 473                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 478                                                         <when test="starts-with($text, '⁃') and &sigiled-text;">
 
 479                                                                 <element name="html:li">
 
 480                                                                         <attribute name="class">
 
 481                                                                                 <text>unordered</text>
 
 483                                                                         <attribute name="data-level">
 
 486                                                                         <element name="html:p">
 
 487                                                                                 <call-template name="LesML:id-and-contents">
 
 488                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 493                                                         <when test="starts-with($text, '🔣') and &sigiled-text;">
 
 494                                                                 <element name="html:li">
 
 495                                                                         <attribute name="class">
 
 498                                                                         <attribute name="data-level">
 
 501                                                                         <element name="html:p">
 
 502                                                                                 <call-template name="LesML:id-and-contents">
 
 503                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 508                                                         <when test="starts-with($text, '🛈') and &sigiled-text;">
 
 509                                                                 <element name="html:div">
 
 510                                                                         <attribute name="role">
 
 513                                                                         <attribute name="class">
 
 516                                                                         <element name="html:p">
 
 517                                                                                 <call-template name="LesML:id-and-contents">
 
 518                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 523                                                         <when test="starts-with($text, '⯑') and &sigiled-text;">
 
 524                                                                 <element name="html:div">
 
 525                                                                         <attribute name="role">
 
 528                                                                         <attribute name="class">
 
 531                                                                         <element name="html:p">
 
 532                                                                                 <call-template name="LesML:id-and-contents">
 
 533                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 538                                                         <when test="starts-with($text, '⚠︎') and &sigiled-text;">
 
 539                                                                 <element name="html:div">
 
 540                                                                         <attribute name="role">
 
 543                                                                         <attribute name="class">
 
 546                                                                         <element name="html:p">
 
 547                                                                                 <call-template name="LesML:id-and-contents">
 
 548                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 553                                                         <when test="starts-with($text, '※') and &sigiled-text;">
 
 554                                                                 <element name="html:div">
 
 555                                                                         <attribute name="role">
 
 558                                                                         <attribute name="class">
 
 561                                                                         <element name="html:p">
 
 562                                                                                 <call-template name="LesML:id-and-contents">
 
 563                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 568                                                         <when test="starts-with($text, '☡') and &sigiled-text;">
 
 569                                                                 <element name="html:div">
 
 570                                                                         <attribute name="role">
 
 573                                                                         <attribute name="class">
 
 576                                                                         <element name="html:p">
 
 577                                                                                 <call-template name="LesML:id-and-contents">
 
 578                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 583                                                         <when test="starts-with($text, '⋯') and &sigiled-text;">
 
 584                                                                 <element name="html:div">
 
 585                                                                         <attribute name="class">
 
 586                                                                                 <text>continuation</text>
 
 588                                                                         <element name="html:p">
 
 589                                                                                 <call-template name="LesML:id-and-contents">
 
 590                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 595                                                         <when test="starts-with($text, '#') and &sigiled-text;">
 
 597                                                                         <value-of select="&unsigiled-text;"/>
 
 601                                                                 <element name="html:p">
 
 602                                                                         <call-template name="LesML:id-and-contents">
 
 603                                                                                 <with-param name="source" select="$text"/>
 
 610                                                 <when test="translate(string($text), '§ion-break; ', '')=''">
 
 611                                                         <element name="html:hr"/>
 
 613                                                 <when test="$quoted">
 
 614                                                         <element name="html:blockquote">
 
 615                                                                 <copy-of select="$par"/>
 
 619                                                         <copy-of select="$par"/>
 
 625                 <variable name="inlined">
 
 626                         <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
 
 628                 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
 
 630         <template match="html:script[@type='text/lesml']">
 
 631                 <variable name="lines-fragment">
 
 632                         <call-template name="LesML:split">
 
 633                                 <with-param name="source">
 
 634                                         <for-each select=".//text()">
 
 635                                                 <value-of select="."/>
 
 640                 <call-template name="LesML:parse">
 
 641                         <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
 
 644         <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
 
 646                         <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
 
 649         <template match="text()" mode="LesML:finalize-tree">
 
 650                 <call-template name="LesML:break-and-unescape">
 
 651                         <with-param name="source" select="string(.)"/>
 
 654         <template match="html:blockquote" mode="LesML:finalize-tree">
 
 655                 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
 
 656                         <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
 
 657                         <variable name="contents">
 
 658                                 <copy-of select="node()"/>
 
 659                                 <for-each select="following-sibling::node()[not($notquote) or following-sibling::node()[generate-id()=generate-id($notquote)]]">
 
 660                                         <copy-of select="node()"/>
 
 663                         <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
 
 664                         <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()]"/>
 
 666                                 <when test="starts-with($laststarttext, '— ')">
 
 667                                         <variable name="caption">
 
 668                                                 <copy-of select="$laststarttext/preceding-sibling::node()"/>
 
 669                                                 <value-of select="substring-after($laststarttext, '— ')"/>
 
 670                                                 <copy-of select="$laststarttext/following-sibling::node()"/>
 
 672                                         <element name="html:figure">
 
 674                                                         <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
 
 676                                                 <element name="html:figcaption">
 
 677                                                         <for-each select="$content-nodes[last()]">
 
 679                                                                         <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
 
 687                                                 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
 
 693         <template match="html:div" mode="LesML:finalize-tree">
 
 694                 <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)]">
 
 695                         <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
 
 697                                 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
 
 698                                 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
 
 699                                         <apply-templates select="node()" mode="LesML:finalize-tree"/>
 
 704         <template match="html:li" mode="LesML:finalize-tree">
 
 705                 <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)]">
 
 706                         <apply-templates select="." mode="LesML:finalize-list"/>
 
 709         <template match="html:li" mode="LesML:finalize-list">
 
 710                 <param name="parent-level" select="0"/>
 
 711                 <variable name="current-class" select="string(@class)"/>
 
 712                 <variable name="current-level" select="number(@data-level)"/>
 
 713                 <variable name="wrapper">
 
 715                                 <when test="@class='ordered'">
 
 723                 <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]"/>
 
 724                 <element name="html:{$wrapper}" namespace="http://www.w3.org/1999/xhtml">
 
 725                         <for-each select=".|following-sibling::html:li[@data-level=$current-level and (not($notinlist) or following-sibling::node()[generate-id()=generate-id($notinlist)])]">
 
 726                                 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
 
 728                                         <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
 
 729                                         <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
 
 730                                                 <apply-templates select="node()" mode="LesML:finalize-tree"/>
 
 732                                         <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
 
 733                                                 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
 
 734                                                         <with-param name="parent-level" select="$current-level"/>
 
 740                 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
 
 741                         <apply-templates select="$notinlist" mode="LesML:finalize-list">
 
 742                                 <with-param name="parent-level" select="$parent-level"/>
 
 746         <template match="node()" mode="LesML:inline">
 
 747                 <param name="element-name"/>
 
 748                 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
 
 749                 <param name="start-sigil"/>
 
 750                 <param name="end-sigil"/>
 
 752                 <param name="langtag-supported" select="false()"/>
 
 754                         <when test="self::*">
 
 756                                         <copy-of select="@*"/>
 
 757                                         <variable name="start-node" select="text()[contains(., $start-sigil)][1]"/>
 
 759                                                 <when test="$start-node">
 
 760                                                         <variable name="remaining">
 
 761                                                                 <value-of select="substring-after($start-node, $start-sigil)"/>
 
 762                                                                 <copy-of select="$start-node/following-sibling::node()"/>
 
 764                                                         <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., $end-sigil)][1]"/>
 
 766                                                                 <when test="$end-node">
 
 767                                                                         <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
 
 768                                                                         <variable name="maybe-langtag">
 
 769                                                                                 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
 
 770                                                                                         <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
 
 773                                                                         <variable name="langtag">
 
 774                                                                                 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
 
 775                                                                                         <value-of select="$maybe-langtag"/>
 
 778                                                                         <variable name="rest">
 
 781                                                                                                 <when test="string($langtag)!=''">
 
 782                                                                                                         <value-of select="substring-after($restoftext, '$')"/>
 
 785                                                                                                         <value-of select="$restoftext"/>
 
 788                                                                                         <copy-of select="$end-node/following-sibling::node()"/>
 
 791                                                                         <variable name="processed-rest">
 
 792                                                                                 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:inline">
 
 793                                                                                         <with-param name="element-name" select="$element-name"/>
 
 794                                                                                         <with-param name="element-namespace" select="$element-namespace"/>
 
 795                                                                                         <with-param name="start-sigil" select="$start-sigil"/>
 
 796                                                                                         <with-param name="end-sigil" select="$end-sigil"/>
 
 797                                                                                         <with-param name="role" select="$role"/>
 
 798                                                                                         <with-param name="langtag-supported" select="$langtag-supported"/>
 
 801                                                                         <copy-of select="$start-node/preceding-sibling::node()"/>
 
 802                                                                         <value-of select="substring-before($start-node, $start-sigil)"/>
 
 803                                                                         <element name="{$element-name}" namespace="{$element-namespace}">
 
 804                                                                                 <if test="string($role)!=''">
 
 805                                                                                         <attribute name="role">
 
 806                                                                                                 <value-of select="$role"/>
 
 809                                                                                 <if test="string($langtag)!=''">
 
 810                                                                                         <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
 
 811                                                                                                 <attribute name="lang">
 
 812                                                                                                         <value-of select="$langtag"/>
 
 815                                                                                         <attribute name="xml:lang">
 
 816                                                                                                 <value-of select="$langtag"/>
 
 819                                                                                 <copy-of select="$end-node/preceding-sibling::node()"/>
 
 820                                                                                 <value-of select="substring-before($end-node, $end-sigil)"/>
 
 822                                                                         <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
 
 825                                                                         <apply-templates select="node()" mode="LesML:inline">
 
 826                                                                                 <with-param name="element-name" select="$element-name"/>
 
 827                                                                                 <with-param name="element-namespace" select="$element-namespace"/>
 
 828                                                                                 <with-param name="start-sigil" select="$start-sigil"/>
 
 829                                                                                 <with-param name="end-sigil" select="$end-sigil"/>
 
 830                                                                                 <with-param name="role" select="$role"/>
 
 831                                                                                 <with-param name="langtag-supported" select="$langtag-supported"/>
 
 837                                                         <apply-templates select="node()" mode="LesML:inline">
 
 838                                                                 <with-param name="element-name" select="$element-name"/>
 
 839                                                                 <with-param name="element-namespace" select="$element-namespace"/>
 
 840                                                                 <with-param name="start-sigil" select="$start-sigil"/>
 
 841                                                                 <with-param name="end-sigil" select="$end-sigil"/>
 
 842                                                                 <with-param name="role" select="$role"/>
 
 843                                                                 <with-param name="langtag-supported" select="$langtag-supported"/>
 
 850                                 <copy-of select="."/>
 
 854         <template match="node()" mode="LesML:linkify">
 
 855                 <variable name="result">
 
 857                                 <when test="self::*">
 
 859                                                 <copy-of select="@*"/>
 
 860                                                 <variable name="start-node" select="text()[contains(., '{🔗')][1]"/>
 
 862                                                         <when test="$start-node">
 
 863                                                                 <variable name="remaining">
 
 864                                                                         <value-of select="substring-after($start-node, '{🔗')"/>
 
 865                                                                         <copy-of select="$start-node/following-sibling::node()"/>
 
 867                                                                 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., '>}') and not(preceding-sibling::*)][1]"/>
 
 868                                                                 <variable name="hyperlink">
 
 869                                                                         <for-each select="$end-node/preceding-sibling::node()">
 
 870                                                                                 <value-of select="."/>
 
 872                                                                         <value-of select="substring-before($end-node, '>}')"/>
 
 875                                                                         <when test="contains($hyperlink, '<')">
 
 876                                                                                 <variable name="ltcomponents">
 
 877                                                                                         <call-template name="LesML:split">
 
 878                                                                                                 <with-param name="source" select="$hyperlink"/>
 
 879                                                                                                 <with-param name="separator" select="'<'"/>
 
 882                                                                                 <variable name="ltcomponent-nodes" select="exsl:node-set($ltcomponents)/*"/>
 
 883                                                                                 <variable name="rest">
 
 885                                                                                                 <value-of select="substring-after($end-node, '>}')"/>
 
 886                                                                                                 <copy-of select="$end-node/following-sibling::node()"/>
 
 889                                                                                 <variable name="processed-rest">
 
 890                                                                                         <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
 
 892                                                                                 <copy-of select="$start-node/preceding-sibling::node()"/>
 
 893                                                                                 <value-of select="substring-before($start-node, '{🔗')"/>
 
 894                                                                                 <element name="html:a">
 
 895                                                                                         <attribute name="href">
 
 896                                                                                                 <value-of select="$ltcomponent-nodes[last()]"/>
 
 899                                                                                                 <when test="count($ltcomponent-nodes)>2 or normalize-space($ltcomponent-nodes[1])!=''">
 
 900                                                                                                         <value-of select="$ltcomponent-nodes[1]"/>
 
 901                                                                                                         <for-each select="$ltcomponent-nodes[position()>1 and position()!=last()]">
 
 903                                                                                                                 <value-of select="."/>
 
 907                                                                                                         <value-of select="$ltcomponent-nodes[last()]"/>
 
 911                                                                                 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
 
 914                                                                                 <variable name="rest">
 
 916                                                                                                 <copy-of select="$remaining"/>
 
 919                                                                                 <variable name="processed-rest">
 
 920                                                                                         <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
 
 922                                                                                 <copy-of select="$start-node/preceding-sibling::node()"/>
 
 923                                                                                 <value-of select="substring-before($start-node, '{🔗')"/>
 
 925                                                                                 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
 
 930                                                                 <apply-templates select="node()" mode="LesML:linkify"/>
 
 936                                         <copy-of select="."/>
 
 940                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
 
 942         <template match="node()" mode="LesML:strikethrough">
 
 943                 <variable name="result">
 
 944                         <apply-templates select="." mode="LesML:inline">
 
 945                                 <with-param name="element-name" select="'html:s'"/>
 
 946                                 <with-param name="start-sigil" select="'⸠'"/>
 
 947                                 <with-param name="end-sigil" select="'⸡'"/>
 
 950                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
 
 952         <template match="node()" mode="LesML:underline">
 
 953                 <variable name="result">
 
 954                         <apply-templates select="." mode="LesML:inline">
 
 955                                 <with-param name="element-name" select="'html:u'"/>
 
 956                                 <with-param name="start-sigil" select="'⸤'"/>
 
 957                                 <with-param name="end-sigil" select="'⸥'"/>
 
 960                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
 
 962         <template match="node()" mode="LesML:noted">
 
 963                 <variable name="result">
 
 964                         <apply-templates select="." mode="LesML:inline">
 
 965                                 <with-param name="element-name" select="'html:small'"/>
 
 966                                 <with-param name="start-sigil" select="'⟦'"/>
 
 967                                 <with-param name="end-sigil" select="'⟧'"/>
 
 968                                 <with-param name="role" select="'note'"/>
 
 971                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
 
 973         <template match="node()" mode="LesML:parenthetical">
 
 974                 <variable name="result">
 
 975                         <apply-templates select="." mode="LesML:inline">
 
 976                                 <with-param name="element-name" select="'html:small'"/>
 
 977                                 <with-param name="start-sigil" select="'⸨'"/>
 
 978                                 <with-param name="end-sigil" select="'⸩'"/>
 
 981                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
 
 983         <template match="node()" mode="LesML:important">
 
 984                 <variable name="result">
 
 985                         <apply-templates select="." mode="LesML:inline">
 
 986                                 <with-param name="element-name" select="'html:strong'"/>
 
 987                                 <with-param name="start-sigil" select="'☞'"/>
 
 988                                 <with-param name="end-sigil" select="'☜'"/>
 
 991                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
 
 993         <template match="node()" mode="LesML:emphasized">
 
 994                 <variable name="result">
 
 995                         <apply-templates select="." mode="LesML:inline">
 
 996                                 <with-param name="element-name" select="'html:em'"/>
 
 997                                 <with-param name="start-sigil" select="'⹐'"/>
 
 998                                 <with-param name="end-sigil" select="'⹑'"/>
 
1001                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
 
1003         <template match="node()" mode="LesML:titled">
 
1004                 <variable name="result">
 
1005                         <apply-templates select="." mode="LesML:inline">
 
1006                                 <with-param name="element-name" select="'html:cite'"/>
 
1007                                 <with-param name="start-sigil" select="'⟪'"/>
 
1008                                 <with-param name="end-sigil" select="'⟫'"/>
 
1011                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
 
1013         <template match="node()" mode="LesML:offset">
 
1014                 <variable name="result">
 
1015                         <apply-templates select="." mode="LesML:inline">
 
1016                                 <with-param name="element-name" select="'html:i'"/>
 
1017                                 <with-param name="start-sigil" select="'⟨'"/>
 
1018                                 <with-param name="end-sigil" select="'⟩'"/>
 
1019                                 <with-param name="langtag-supported" select="true()"/>
 
1022                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
 
1024         <template match="node()" mode="LesML:bolded">
 
1025                 <variable name="result">
 
1026                         <apply-templates select="." mode="LesML:inline">
 
1027                                 <with-param name="element-name" select="'html:b'"/>
 
1028                                 <with-param name="start-sigil" select="'⦃'"/>
 
1029                                 <with-param name="end-sigil" select="'⦄'"/>
 
1032                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
 
1034         <template match="node()" mode="LesML:code">
 
1035                 <apply-templates select="." mode="LesML:inline">
 
1036                         <with-param name="element-name" select="'html:code'"/>
 
1037                         <with-param name="start-sigil" select="'`'"/>
 
1038                         <with-param name="end-sigil" select="'´'"/>