- <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
- <variable name="blocked">
- <for-each select="$last-lines">
- <variable name="position" select="position()"/>
- <variable name="prev-last" select="$last-lines[($position)-1]"/>
- <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()!='']|."/>
- <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '	'))])"/>
- <variable name="text">
- <for-each select="$linespans">
- <value-of select="normalize-space()"/>
- <if test="position()!=count($linespans)">
- <text> </text>
- </if>
- </for-each>
- </variable>
- <if test="string($text)!=''">
- <variable name="par">
- <choose>
- <when test="starts-with($text, '⁌ ')">
- <html:h1>
+ <variable name="last-lines" select="$lines[normalize-space()!='' and (normalize-space(following-sibling::*[1])='' or position()=last())]"/>
+ <for-each select="$last-lines">
+ <variable name="position" select="position()"/>
+ <variable name="prev-last" select="$last-lines[($position)-1]"/>
+ <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
+ <variable name="prefix" select="substring(translate(., ' 	', ''), 1, 1)"/>
+ <variable name="all-prefixed" select="not($linespans[not(starts-with(translate(., ' 	', ''), $prefix))])"/>
+ <variable name="quoted" select="$all-prefixed and $prefix='»'"/>
+ <variable name="bracketed" select="$all-prefixed and $prefix=']'"/>
+ <choose>
+ <when test="count($linespans)=1 and translate(., concat($LESML_SECTION_BREAK_CHARS, ' 	'), '')=''">
+ <element name="hr" namespace="&xhtml;"/>
+ </when>
+ <when test="$quoted or $bracketed">
+ <variable name="innerlines-fragment">
+ <for-each select="$linespans">
+ <variable name="inner">
+ <value-of select="substring-after(., $prefix)"/>
+ </variable>
+ <copy>
+ <choose>
+ <when test="starts-with($inner, ' ') or starts-with($inner, '	')">
+ <value-of select="substring($inner, 1+count(exslstr:tokenize($inner, '')[normalize-space()='' and not(preceding-sibling::*[normalize-space()!=''])]))"/>
+ </when>
+ <otherwise>
+ <value-of select="$inner"/>
+ </otherwise>
+ </choose>
+ </copy>
+ </for-each>
+ </variable>
+ <variable name="blocked-fragment">
+ <call-template name="LesML:block">
+ <with-param name="lines" select="exsl:node-set($innerlines-fragment)/*"/>
+ </call-template>
+ </variable>
+ <variable name="innerpars" select="exsl:node-set($blocked-fragment)/node()"/>
+ <choose>
+ <when test="$quoted and $innerpars[position()=last() and self::html:footer]">
+ <element name="figure" namespace="&xhtml;">
+ <element name="blockquote" namespace="&xhtml;">
+ <copy-of select="$innerpars[position()!=last()]"/>
+ </element>
+ <element name="figcaption" namespace="&xhtml;">
+ <copy-of select="$innerpars[last()]/node()"/>
+ </element>
+ </element>
+ </when>
+ <when test="$quoted">
+ <element name="blockquote" namespace="&xhtml;">
+ <copy-of select="$innerpars"/>
+ </element>
+ </when>
+ <when test="$bracketed">
+ <element name="footer" namespace="&xhtml;">
+ <copy-of select="$innerpars"/>
+ </element>
+ </when>
+ </choose>
+ </when>
+ <otherwise>
+ <variable name="preformatted" select="$all-prefixed and $prefix='|'"/>
+ <variable name="text">
+ <for-each select="$linespans">
+ <choose>
+ <when test="$preformatted">
+ <value-of select="substring-after(., '|')"/>
+ </when>
+ <otherwise>
+ <value-of select="normalize-space()"/>
+ </otherwise>
+ </choose>
+ <if test="position()!=count($linespans)">
+ <choose>
+ <when test="$preformatted">
+ <text>
</text>
+ </when>
+ <otherwise>
+ <text> </text>
+ </otherwise>
+ </choose>
+ </if>
+ </for-each>
+ </variable>
+ <choose>
+ <when test="$preformatted">
+ <element name="pre" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="$text"/>
+ </call-template>
+ </element>
+ </when>
+ <when test="string($text)=''"/>
+ <when test="starts-with($text, '⁌') and &sigiled-text;">
+ <element name="h1" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </when>
+ <when test="starts-with($text, '§') and &sigiled-text;">
+ <element name="h2" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </when>
+ <when test="starts-with($text, '❦') and &sigiled-text;">
+ <element name="h3" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </when>
+ <when test="starts-with($text, '✠') and &sigiled-text;">
+ <element name="h4" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </when>
+ <when test="starts-with($text, '•') and &sigiled-text;">
+ <element name="li" namespace="&xhtml;">
+ <attribute name="class">
+ <text>unordered</text>
+ </attribute>
+ <attribute name="data-level">
+ <text>1</text>
+ </attribute>
+ <element name="p" namespace="&xhtml;">