Skip to content

Commit

Permalink
Remove work-arounds for Project Gutenberg ebookmaker.
Browse files Browse the repository at this point in the history
* improve some code comments.
  • Loading branch information
jhellingman committed May 28, 2024
1 parent 1857ba1 commit 0986f69
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
2 changes: 1 addition & 1 deletion modules/divisions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
then f:generate-href($tocEntry)
else if ($divGen and f:included-in-toc(., $maxLevel))
then f:determine-filename($divGen) || '#' || $id || '.toc'
else f:generate-href(//*[@id='toc'][1])"/>
else f:generate-href((//*[@id='toc'])[1])"/>
<xsl:value-of select="f:message('msgToc')"/>
</a>
<xsl:text>]</xsl:text>
Expand Down
12 changes: 1 addition & 11 deletions modules/header.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,7 @@

<xsl:template name="generate-html-body">
<body>
<xsl:choose>
<xsl:when test="f:is-set('pg.compliant')">
<!-- extra div to work around bug in ebookmaker -->
<div class="pgWrapper">
<xsl:call-template name="generate-html-inner-body"/>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="generate-html-inner-body"/>
</xsl:otherwise>
</xsl:choose>
<xsl:call-template name="generate-html-inner-body"/>
</body>
</xsl:template>

Expand Down
26 changes: 11 additions & 15 deletions modules/tables.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
column, and can be overridden by the <code>@rend</code> attribute on the cell itself.
Both <code>@rend</code> attributes are converted to classes, where care needs to be
taken that the column related classes are always defined before
the cell classes, as to make this work out correctly with the
the cell classes, to make this work out correctly with the
CSS precedence rules. Note that all identical <code>@rend</code> attributes are
mapped to the same class, and that those might occur in preceding
tables, we thus have to generate all column-related classes before
Expand Down Expand Up @@ -69,10 +69,6 @@
<xsl:copy-of select="f:set-lang-id-attributes(.)"/>
<xsl:apply-templates mode="table-caption" select="head"/>
<xsl:call-template name="inner-table"/>
<xsl:if test="f:is-set('pg.compliant')">
<!-- Work around a bug in PG ebookmaker, to prevent breaking a table. -->
<div class="pgKludge"/>
</xsl:if>
</div>
<xsl:call-template name="reopenpar"/>
</xsl:otherwise>
Expand Down Expand Up @@ -105,7 +101,7 @@
<xsl:if test="not(f:is-nested-table(.)) and .//note[f:is-table-note(.)][not(@sameAs)]">
<div class="footnotes">
<xsl:apply-templates select=".//note[f:is-table-note(.)][not(@sameAs)]" mode="footnotes">
<!-- Retain the order of markers, irrespective of the order of encoding the table -->
<!-- Retain the order of markers, irrespective of the order of encoding in the table. -->
<xsl:sort select="@n"/>
</xsl:apply-templates>
</div>
Expand Down Expand Up @@ -139,7 +135,7 @@
</xsl:if>

<xsl:choose>
<!-- If a table starts with label or unit roles, use the thead and tbody elements in HTML -->
<!-- If a table starts with label or unit roles, use the thead and tbody elements in HTML. -->
<xsl:when test="row[1][f:is-header-row(.)]">
<thead>
<xsl:apply-templates select="*[not(preceding-sibling::row[not(f:is-header-row(.))] or self::row[not(f:is-header-row(.))])]"/>
Expand Down Expand Up @@ -255,7 +251,7 @@
<xsl:param name="cell" as="element(cell)"/>
<xsl:variable name="row" as="element(row)" select="$cell/parent::row"/>
<xsl:if test="not($cell/following-sibling::cell) and not($row/following-sibling::row)">
<!-- We are a table in a footnote, the table is the last element of the footnote, and this is the last cell of the table -->
<!-- We are a table in a footnote, the table is the last element of the footnote, and this is the last cell of the table. -->
<xsl:if test="f:inside-footnote($cell)">
<xsl:variable name="note" select="$cell/ancestor::note[f:is-footnote(.)][1]"/>
<xsl:if test="f:last-child-is-block-element($note)">
Expand Down Expand Up @@ -370,10 +366,10 @@
<xsl:copy-of select="f:log-warning('Malformed table inside element {1} with id {2}: cell not in row.', (name(ancestor::*[@id][1]), (ancestor::*[@id][1])/@id))"/>
</xsl:if>

<!-- A cell is considered part of the table head if it has a @role of label or unit -->
<!-- A cell is considered part of the table head if it has a @role of label or unit. -->
<xsl:variable name="prefix" select="if (f:is-header-row(..)) then 'cellHead' else 'cell'"/>

<!-- Some stuff to determine this cell is at the bottom of a column in an N-up table -->
<!-- Some stuff to determine this cell is at the bottom of a column in an N-up table. -->
<xsl:variable name="parentTable" select="ancestor::table[1]"/>
<xsl:variable name="column-count" as="xs:integer" select="xs:integer(f:if-null(f:rend-value($parentTable/@rend, 'columns'), 1))"/>
<xsl:variable name="item-order" as="xs:string" select="f:rend-value($parentTable/@rend, 'item-order')"/>
Expand All @@ -391,7 +387,7 @@

<xsl:variable name="cols" select="if (@cols) then @cols else 1"/>
<xsl:choose>
<!-- Do we have the @col attribute on the table, then we can use those attributes -->
<!-- If we have the @col attribute on the table we can use that attributes. -->
<xsl:when test="@col">
<xsl:if test="@col = 1"><xsl:value-of select="$prefix"/><xsl:text>Left </xsl:text></xsl:if>
<xsl:if test="@col + $cols - 1 = ../../@cols"><xsl:value-of select="$prefix"/><xsl:text>Right </xsl:text></xsl:if>
Expand Down Expand Up @@ -420,12 +416,12 @@
</xsl:template>


<!-- Find the column number of the current cell -->
<!-- Find the column-number of the current cell -->
<xsl:template name="find-column-number">
<xsl:context-item as="element(cell)" use="required"/>

<!-- The column corresponding to this cell, taking into account preceding @cols attributes -->
<!-- If we have the @col attribute, we will use this value -->
<!-- The column corresponding to this cell, taking into account preceding @cols attributes. -->
<!-- If we have the @col attribute, we will use this value. -->
<!-- The alternative simple calculation will fail in cases where @rows attributes in preceding rows cause cells to be skipped. -->
<xsl:value-of select="if (@col) then @col else sum(preceding-sibling::cell[@cols]/@cols) + count(preceding-sibling::cell[not(@cols)]) + 1"/>
</xsl:template>
Expand Down Expand Up @@ -528,7 +524,7 @@
<xsl:if test="$i &gt; 1 and position() = 1">
<td class="cellDoubleUp">&nbsp;</td>
</xsl:if>
<!-- Prevent duplication of ids by stripping them for all but the first repeat -->
<!-- Prevent duplication of ids by stripping them from all but the first repeated instance. -->
<xsl:variable name="cellHtml">
<xsl:apply-templates select="."/>
</xsl:variable>
Expand Down

0 comments on commit 0986f69

Please sign in to comment.