Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:jagoterr/xslt-typograf
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Chizhov committed Jun 30, 2009
2 parents 28f7502 + da8f30f commit bd05a9b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/xslt/typography.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

<!DOCTYPE stylesheet [
<!ENTITY nbsp "&#x00A0;">
<!ENTITY cr "&#x000A;">
<!ENTITY lf "&#x000D;">
<!ENTITY tab "&#x0009;">
<!ENTITY ldash "&#x2014;">
<!ENTITY laquo "&#x00AB;">
<!ENTITY raquo "&#x00BB;">
Expand All @@ -24,6 +27,16 @@
<xsl:param name="typograf.cfg.tags.ignore" select="'|screen|synopsis|'"/>
<xsl:param name="typograf.cfg.debug" select="'false'"/>

<xsl:variable name="cr">
<xsl:text>&cr;</xsl:text>
</xsl:variable>
<xsl:variable name="lf">
<xsl:text>&lf;</xsl:text>
</xsl:variable>
<xsl:variable name="tab">
<xsl:text>&tab;</xsl:text>
</xsl:variable>

<!-- ROOT template -->
<xsl:template match="text()">

Expand All @@ -41,13 +54,21 @@
<!-- ok, let's process this -->

<xsl:variable name="normalized_source">
<xsl:if test="starts-with(., ' ')">
<xsl:if test="starts-with(., ' ') or
starts-with(., $cr) or
starts-with(., $lf) or
starts-with(., $tab)">
<xsl:text> </xsl:text>
</xsl:if>
<xsl:value-of select="normalize-space(.)"/>
<!-- this ugly test expression - just an implementation of the ends-with,
<!-- this following - just an implementation of the ends-with,
which is absent in xpath spec. Arghhh... -->
<xsl:if test="substring(., string-length(.), 1)=' '">
<xsl:variable name="lastchar"
select="substring(., string-length(.), 1)"/>
<xsl:if test="$lastchar=' ' or
$lastchar=$cr or
$lastchar=$lf or
$lastchar=$tab">
<xsl:if test="$typograf.cfg.debug='true'">
[DEBUG {string '<xsl:value-of select="."/>' ends with space}]
</xsl:if>
Expand Down
5 changes: 5 additions & 0 deletions test/docs/spaces.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<db:title>Тесты корректного обращения с пробелами</db:title>

<db:para>Простой тест <db:command>для пары слов</db:command> внутри inline-тэга</db:para>
<db:para>
Непростой тест <db:command>для пары слов</db:command>
потому что после тэга не пробел, а перевод строки.
А уж <db:command>тут вот:</db:command> вообще tab!
</db:para>
<db:para>Другой простой тест с тэгом-разделителем<db:coloured-nbsp/>слов в предложении</db:para>

</db:sect1>
Expand Down

0 comments on commit bd05a9b

Please sign in to comment.