Skip to content

Commit

Permalink
More ways to render milestone elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellingman committed Sep 10, 2024
1 parent 64bf7fa commit 359ceca
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
21 changes: 20 additions & 1 deletion modules/block.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
<xd:doc>
<xd:short>Handle a milestone (thematic break).</xd:short>
<xd:detail>Handle a document milestone. This is mostly used to encode thematic breaks. Generates
slightly different outputs, depending on the <code>@type</code> and <code>@rend</code>-attributes.</xd:detail>
slightly different outputs, depending on the <code>@unit</code> and <code>@rend</code>-attributes.</xd:detail>
</xd:doc>

<xsl:template match="milestone[@unit='theme' or @unit='tb']">
Expand All @@ -260,6 +260,25 @@
<xsl:with-param name="string" select="f:repeat('*', '&nbsp;&nbsp;&nbsp;', xs:integer(f:rend-value(@rend, 'stars')))"/>
</xsl:call-template>
</xsl:when>

<xsl:when test="f:has-rend-value(@rend, 'repeat')">
<xsl:variable name="repeat" select="f:rend-value(@rend, 'repeat')"/>
<xsl:variable name="string" as="xs:string">
<xsl:analyze-string select="$repeat" regex="(.+?),\s*(.+?),\s*([0-9]+)">
<xsl:matching-substring>
<xsl:value-of select="f:repeat(regex-group(1), regex-group(2), xs:integer(regex-group(3)))"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:copy-of select="f:log-error('unexpected parameters for repeat([char], [separator], [count]) in: repeat({1}).', ($repeat))"/>
<xsl:value-of select="f:repeat('*', '&nbsp;&nbsp;&nbsp;', 3)"/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:call-template name="generate-milestone-paragraph">
<xsl:with-param name="string" select="$string"/>
</xsl:call-template>
</xsl:when>

<xsl:when test="@rend = map:keys($milestone-markers)">
<xsl:call-template name="generate-milestone-paragraph">
<xsl:with-param name="string" select="$milestone-markers(@rend)"/>
Expand Down
11 changes: 3 additions & 8 deletions modules/css.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,8 @@
<xsl:when test="$property='hemistich'"/> <!-- render text given in value invisible (i.e., white) to indent with width of previous line. -->

<!-- Non-CSS properties related to decorative initials -->
<xsl:when test="$property='dropcap'"/>
<xsl:when test="$property='dropcap-height'"/>
<xsl:when test="$property='dropcap-offset'"/>
<xsl:when test="$property='initial-height'"/>
<xsl:when test="$property='initial-image'"/>
<xsl:when test="$property='initial-offset'"/>
<xsl:when test="$property='initial-width'"/>
<xsl:when test="$property = ('dropcap', 'dropcap-height', 'dropcap-offset')"/>
<xsl:when test="$property = ('initial-height', 'initial-image', 'initial-offset', 'initial-width')"/>

<!-- divGen related special handling. -->
<xsl:when test="$element = 'divGen' and $property = 'include'"/>
Expand All @@ -485,7 +480,7 @@
<xsl:when test="$element='lb' and $property='indent'"/>

<!-- Thematic breaks with decorative stars -->
<xsl:when test="$element='tb' and $property='stars'"/>
<xsl:when test="$element='milestone' and $property = ('stars', 'repeat')"/>

<!-- Properties related to special font usage -->
<xsl:when test="$property='font' and $value='fraktur'">font-family:'<xsl:value-of select="f:get-setting('css.frakturFont')"/>'; </xsl:when>
Expand Down
26 changes: 25 additions & 1 deletion xspec/block.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!DOCTYPE x:description [

<!ENTITY nbsp "&#160;">
<!ENTITY mdash "&#x2014;">
<!ENTITY zwsp "&#x200B;">
<!ENTITY ldquo "&#x201C;">
<!ENTITY asterism "&#x2042;">
Expand Down Expand Up @@ -116,7 +117,7 @@
<hr class="tb tb01" id="..."/>
<p class="tb" id="...">. . . . . . . . . . . . . . . . . . . . .</p>
<p class="tb" id="...">*&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;*</p>
<p class="tb" id="...">*&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;*</p>
<p class="tb" id="...">*&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;*</p>
<p class="tb" id="...">*</p>
<p class="tb" id="...">&asterism;</p>
<p class="tb" id="..."/>
Expand All @@ -128,6 +129,29 @@
</x:expect>
</x:scenario>

<x:scenario label="When rendering a tb with rend='repeat(char, separator, count)' inside a div">
<x:context>
<div>
<p>Blah blah.</p>
<milestone unit="tb" rend="repeat(*, &nbsp;, 4)"/>
<milestone unit="tb" rend="repeat(&mdash;, &nbsp;, 4)"/>
<milestone unit="tb" rend="repeat(4)"/>
<p>Blah blah.</p>
</div>
</x:context>
<x:expect label="will result extra paragraphs representing the thematic break">
<div xmlns="http://www.w3.org/1999/xhtml" id="..." class="div1 last-child">
<div class="divBody">
<p id="..." class="first">Blah blah.</p>
<p class="tb" id="...">*&nbsp;*&nbsp;*&nbsp;*</p>
<p class="tb" id="...">&mdash;&nbsp;&mdash;&nbsp;&mdash;&nbsp;&mdash;</p>
<p class="tb" id="...">*&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;*</p>
<p id="...">Blah blah.</p>
</div>
</div>
</x:expect>
</x:scenario>

<x:scenario pending="no support for ugly escaping hack" label="When rendering a tb inside a paragraph">
<x:context>
<div>
Expand Down

0 comments on commit 359ceca

Please sign in to comment.