Skip to content

Commit

Permalink
Merge pull request #736 from rvdb/jTEI_optimizeWhitespaceInEg
Browse files Browse the repository at this point in the history
optimizations for whitespace handling in eg elements
  • Loading branch information
HelenaSabel authored Feb 26, 2025
2 parents f42a7cd + 7c9ee21 commit ef5fa03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions profiles/jtei/openedition/to.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,12 @@
</xsl:template>

<xsl:template match="tei:eg">
<xsl:variable name="stripIndent" select="min((for $line in tokenize(., '\n')[.] return string-length(replace($line, '^(\s+).*', '$1'))))"/>
<!-- strip leading blank lines, normalize tabs -->
<xsl:variable name="eg" select="replace(., '^(\s*\n+)', '') ! replace(., '\t', ' ')"/>
<xsl:variable name="stripIndent" select="min((for $line in tokenize($eg, '\n')[.] return string-length(replace($line, '^(\s*).+', '$1'))))"/>
<p rend="noindent">
<code lang="xml">
<xsl:analyze-string select="." regex="\n">
<xsl:analyze-string select="replace($eg, '^\n+', '')" regex="\n">
<xsl:matching-substring>
<xsl:text>&#10;</xsl:text>
</xsl:matching-substring>
Expand Down
10 changes: 6 additions & 4 deletions profiles/jtei/pdf/to.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,14 @@
</xsl:template>

<xsl:template match="tei:eg">
<!-- strip leading blank lines, normalize tabs -->
<xsl:variable name="eg" select="replace(., '^(\s*\n+)', '') ! replace(., '\t', ' ')"/>
<!-- determine maximal amount of preceding whitespace that can be stripped out -->
<xsl:variable name="stripIndent" select="min((for $line in tokenize(., '\n')[.] return string-length(replace($line, '^(\s+).*', '$1'))))"/>
<fo:block xsl:use-attribute-sets="egXML.properties monospace.properties">
<xsl:analyze-string select="." regex="\n">
<xsl:variable name="stripIndent" select="min((for $line in tokenize($eg, '\n')[.] return string-length(replace($line, '^(\s*).+', '$1'))))"/>
<fo:block xsl:use-attribute-sets="egXML.properties monospace.properties" linefeed-treatment="preserve">
<xsl:analyze-string select="$eg" regex="\n">
<xsl:matching-substring>
<fo:block/>
<xsl:text>&#10;</xsl:text>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:analyze-string select="if ($stripIndent > 0) then replace(., concat('^\s{', $stripIndent, '}'), '') else ." regex="\s">
Expand Down

0 comments on commit ef5fa03

Please sign in to comment.