- <template name="LesML:block">
- <param name="lines" select="/.."/>
- <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;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '🔢') and &sigiled-text;">
- <element name="li" namespace="&xhtml;">
- <attribute name="class">
- <text>ordered</text>
- </attribute>
- <attribute name="data-level">
- <text>1</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </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>2</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '🔠') and &sigiled-text;">
- <element name="li" namespace="&xhtml;">
- <attribute name="class">
- <text>ordered</text>
- </attribute>
- <attribute name="data-level">
- <text>2</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </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>3</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '🔡') and &sigiled-text;">
- <element name="li" namespace="&xhtml;">
- <attribute name="class">
- <text>ordered</text>
- </attribute>
- <attribute name="data-level">
- <text>3</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </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>4</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '🔣') and &sigiled-text;">
- <element name="li" namespace="&xhtml;">
- <attribute name="class">
- <text>ordered</text>
- </attribute>
- <attribute name="data-level">
- <text>4</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '※') and &sigiled-text;">
- <element name="section" namespace="&xhtml;">
- <attribute name="role">
- <text>note</text>
- </attribute>
- <attribute name="class">
- <text>note</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '☡') and &sigiled-text;">
- <element name="section" namespace="&xhtml;">
- <attribute name="role">
- <text>note</text>
- </attribute>
- <attribute name="class">
- <text>caution</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '⯑') and &sigiled-text;">
- <element name="section" namespace="&xhtml;">
- <attribute name="role">
- <text>note</text>
- </attribute>
- <attribute name="class">
- <text>query</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '@') and &sigiled-text;">
- <element name="section" namespace="&xhtml;">
- <attribute name="role">
- <text>doc-abstract</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '🛈') and &sigiled-text;">
- <element name="section" namespace="&xhtml;">
- <attribute name="role">
- <text>doc-tip</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '⚠') and &sigiled-text;">
- <element name="section" namespace="&xhtml;">
- <attribute name="role">
- <text>doc-notice</text>
- </attribute>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '⋯') and &sigiled-text;">
- <element name="div" namespace="&xhtml;">
- <processing-instruction name="LesML-Continuation"/>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '^') and &sigiled-text;">
- <element name="li" namespace="&xhtml;">
- <attribute name="class">
- <text>ordered footnote</text>
- </attribute>
- <attribute name="data-level">
- <text>1</text>
- </attribute>
- <processing-instruction name="LesML-Footnote"/>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </element>
- </element>
- </when>
- <when test="starts-with($text, '#') and &sigiled-text;">
- <call-template name="LesML:comment-out">
- <with-param name="source" select="&unsigiled-text;"/>
- </call-template>
- </when>
- <otherwise>
- <element name="p" namespace="&xhtml;">
- <call-template name="LesML:id-and-contents">
- <with-param name="source" select="$text"/>
- </call-template>
- </element>
- </otherwise>
- </choose>
- </otherwise>
- </choose>
- </for-each>
- </template>
- <template name="LesML:paragraphize">
- <param name="lines" select="/.."/>
- <variable name="blocked-fragment">
- <call-template name="LesML:block">
- <with-param name="lines" select="$lines"/>
- </call-template>
- </variable>
- <variable name="blocked" select="exsl:node-set($blocked-fragment)"/>
- <variable name="footnote-ids" select="$blocked//html:li[processing-instruction()[local-name()='LesML-Footnote']]/html:p[1]/@id"/>
- <variable name="inlined-fragment">
- <apply-templates select="$blocked/node()" mode="LesML:comment">
- <with-param name="footnote-ids" select="$footnote-ids"/>
- </apply-templates>
- </variable>
- <apply-templates select="exsl:node-set($inlined-fragment)/node()" mode="LesML:finalize-tree"/>
- </template>