|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62214 - in trunk: doc/src tools/boostbook/xsl
From: steven_at_[hidden]
Date: 2010-05-25 16:40:30
Author: steven_watanabe
Date: 2010-05-25 16:40:27 EDT (Tue, 25 May 2010)
New Revision: 62214
URL: http://svn.boost.org/trac/boost/changeset/62214
Log:
Use the same syntax highlighting that QuickBook generates for the Doxygen/BoostBook synopsis sections
Text files modified:
trunk/doc/src/boostbook.css | 33 +++--
trunk/tools/boostbook/xsl/docbook.xsl | 18 ---
trunk/tools/boostbook/xsl/fo.xsl | 45 ++++++-
trunk/tools/boostbook/xsl/source-highlight.xsl | 227 +++++++++++++++++++++++++++++++++++++--
4 files changed, 264 insertions(+), 59 deletions(-)
Modified: trunk/doc/src/boostbook.css
==============================================================================
--- trunk/doc/src/boostbook.css (original)
+++ trunk/doc/src/boostbook.css 2010-05-25 16:40:27 EDT (Tue, 25 May 2010)
@@ -385,14 +385,29 @@
background-color: #FFFFFF;
color: #000000;
}
-
+
+ /* Syntax Highlighting */
+ .keyword { color: #0000AA; }
+ .identifier { color: #000000; }
+ .special { color: #707070; }
+ .preprocessor { color: #402080; }
+ .char { color: teal; }
+ .comment { color: #800000; }
+ .string { color: teal; }
+ .number { color: teal; }
+ .white_bkd { background-color: #FFFFFF; }
+ .dk_grey_bkd { background-color: #999999; }
+
/* Links */
- a
+ a, a .keyword, a .identifier, a .special, a .preprocessor
+ a .char, a .comment, a .string, a .number
{
color: #005a9c;
}
- a:visited
+ a:visited, a:visited .keyword, a:visited .identifier,
+ a:visited .special, a:visited .preprocessor a:visited .char,
+ a:visited .comment, a:visited .string, a:visited .number
{
color: #9c5a9c;
}
@@ -405,18 +420,6 @@
color: #000000;
}
- /* Syntax Highlighting */
- .keyword { color: #0000AA; }
- .identifier { color: #000000; }
- .special { color: #707070; }
- .preprocessor { color: #402080; }
- .char { color: teal; }
- .comment { color: #800000; }
- .string { color: teal; }
- .number { color: teal; }
- .white_bkd { background-color: #FFFFFF; }
- .dk_grey_bkd { background-color: #999999; }
-
/* Copyright, Legal Notice */
.copyright
{
Modified: trunk/tools/boostbook/xsl/docbook.xsl
==============================================================================
--- trunk/tools/boostbook/xsl/docbook.xsl (original)
+++ trunk/tools/boostbook/xsl/docbook.xsl 2010-05-25 16:40:27 EDT (Tue, 25 May 2010)
@@ -180,24 +180,6 @@
<xsl:copy-of select="."/>
</xsl:template>
- <!-- Syntax highlighting -->
- <xsl:template name="highlight-keyword">
- <xsl:param name="keyword"/>
- <xsl:choose>
- <xsl:when test="$boost.syntax.highlight='1'">
- <emphasis role="bold"><xsl:value-of select="$keyword"/></emphasis>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$keyword"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
-
- <xsl:template name="highlight-comment">
- <xsl:param name="text"/>
- <emphasis><xsl:copy-of select="$text"/></emphasis>
- </xsl:template>
-
<xsl:template name="monospaced">
<xsl:param name="text"/>
<computeroutput><xsl:value-of select="$text"/></computeroutput>
Modified: trunk/tools/boostbook/xsl/fo.xsl
==============================================================================
--- trunk/tools/boostbook/xsl/fo.xsl (original)
+++ trunk/tools/boostbook/xsl/fo.xsl 2010-05-25 16:40:27 EDT (Tue, 25 May 2010)
@@ -129,31 +129,58 @@
-->
-<xsl:template match="//programlisting/phrase[@role='keyword']">
+<xsl:template match="//phrase[@role='keyword' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="#0000AA"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='special']">
+<xsl:template match="//phrase[@role='special' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="#707070"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='preprocessor']">
+<xsl:template match="//phrase[@role='preprocessor' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="#402080"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='char']">
+<xsl:template match="//phrase[@role='char' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="teal"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='comment']">
+<xsl:template match="//phrase[@role='comment' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="#800000"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='string']">
+<xsl:template match="//phrase[@role='string' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="teal"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='number']">
+<xsl:template match="//phrase[@role='number' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="teal"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='white_bkd']">
+<xsl:template match="//phrase[@role='white_bkd' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="#FFFFFF"><xsl:apply-templates/></fo:inline>
</xsl:template>
-<xsl:template match="//programlisting/phrase[@role='dk_grey_bkd']">
+<xsl:template match="//phrase[@role='dk_grey_bkd' and
+ (ancestor::programlisting or
+ ancestor::synopsis or
+ ancestor::literallayout)]">
<fo:inline color="#999999"><xsl:apply-templates/></fo:inline>
</xsl:template>
Modified: trunk/tools/boostbook/xsl/source-highlight.xsl
==============================================================================
--- trunk/tools/boostbook/xsl/source-highlight.xsl (original)
+++ trunk/tools/boostbook/xsl/source-highlight.xsl 2010-05-25 16:40:27 EDT (Tue, 25 May 2010)
@@ -27,8 +27,26 @@
<xsl:variable name="id-chars" select="'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_'"/>
<xsl:variable name="keywords"
select="' asm auto bool break case catch char class const const_cast continue default delete do double dynamic_cast else enum explicit export extern false float for friend goto if inline int long mutable namespace new operator private protected public register reinterpret_cast return short signed sizeof static static_cast struct switch template this throw true try typedef typeid typename union unsigned using virtual void volatile wchar_t while '"/>
-
-
+ <xsl:variable name="operators4" select="'%:%:'"/>
+ <xsl:variable name="operators3" select="'>>= <<= ->* ...'"/>
+ <xsl:variable name="operators2" select="'## <: :> <% %> %: += -= *= /= %= ^= &= |= << >> == != <= >= && || ++ -- ->'"/>
+ <xsl:variable name="operators1" select="'{ } [ ] # ( ) ; : + - * / % ^ & | ~ ! = < > ,'"/>
+
+ <!-- Syntax highlighting -->
+ <xsl:template name="highlight-keyword">
+ <xsl:param name="keyword"/>
+ <xsl:choose>
+ <xsl:when test="$boost.syntax.highlight='1'">
+ <phrase role="keyword">
+ <xsl:value-of select="$keyword"/>
+ </phrase>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$keyword"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
<xsl:template name="highlight-identifier">
<xsl:param name="identifier"/>
<xsl:choose>
@@ -37,33 +55,156 @@
<xsl:with-param name="keyword" select="$identifier"/>
</xsl:call-template>
</xsl:when>
+ <xsl:when test="$boost.syntax.highlight='1'">
+ <phrase role="identifier">
+ <xsl:value-of select="$identifier"/>
+ </phrase>
+ </xsl:when>
<xsl:otherwise>
<xsl:value-of select="$identifier"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
+
+ <xsl:template name="highlight-comment">
+ <xsl:param name="text"/>
+ <xsl:choose>
+ <xsl:when test="$boost.syntax.highlight='1'">
+ <phrase role="comment">
+ <xsl:value-of select="$text"/>
+ </phrase>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$text"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="highlight-special">
+ <xsl:param name="text"/>
+ <xsl:choose>
+ <xsl:when test="$boost.syntax.highlight='1'">
+ <phrase role="special">
+ <xsl:value-of select="$text"/>
+ </phrase>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$text"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="highlight-pp-directive">
+ <xsl:param name="text"/>
+ <xsl:choose>
+ <xsl:when test="$boost.syntax.highlight='1'">
+ <phrase role="preprocessor">
+ <xsl:value-of select="$text"/>
+ </phrase>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$text"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
- <xsl:template name="highlight-text-impl-ident">
+ <xsl:template name="highlight-text-ident-length">
<xsl:param name="text"/>
- <xsl:param name="pos"/>
+ <xsl:param name="pos" select="1"/>
<xsl:choose>
<xsl:when test="string-length($text) + 1 = $pos">
- <xsl:call-template name="highlight-identifier">
- <xsl:with-param name="identifier" select="substring($text, 1, $pos - 1)"/>
+ <xsl:value-of select="$pos - 1"/>
+ </xsl:when>
+ <xsl:when test="contains($id-chars, substring($text, $pos, 1))">
+ <xsl:call-template name ="highlight-text-ident-length">
+ <xsl:with-param name="text" select="$text"/>
+ <xsl:with-param name="pos" select="$pos + 1"/>
</xsl:call-template>
</xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$pos - 1"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="highlight-text-operator-length">
+ <xsl:param name="text"/>
+ <xsl:choose>
+ <xsl:when test="string-length($text) >= 4 and
+ not(contains(substring($text, 1, 4), ' ')) and
+ contains($operators4, substring($text, 1, 4))">
+ <xsl:value-of select="4"/>
+ </xsl:when>
+ <xsl:when test="string-length($text) >= 3 and
+ not(contains(substring($text, 1, 3), ' ')) and
+ contains($operators3, substring($text, 1, 3))">
+ <xsl:value-of select="3"/>
+ </xsl:when>
+ <xsl:when test="string-length($text) >= 2 and
+ not(contains(substring($text, 1, 2), ' ')) and
+ contains($operators2, substring($text, 1, 2))">
+ <xsl:value-of select="2"/>
+ </xsl:when>
+ <xsl:when test="string-length($text) >= 1 and
+ not(contains(substring($text, 1, 1), ' ')) and
+ contains($operators1, substring($text, 1, 1))">
+ <xsl:value-of select="1"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="0"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="highlight-text-pp-directive-length">
+ <xsl:param name="text"/>
+ <!-- Assume that the first character is a # -->
+ <xsl:param name="pos" select="2"/>
+ <xsl:choose>
<xsl:when test="contains($id-chars, substring($text, $pos, 1))">
- <xsl:call-template name ="highlight-text-impl-ident">
+ <xsl:call-template name="highlight-text-ident-length">
+ <xsl:with-param name="text" select="$text"/>
+ <xsl:with-param name="pos" select="$pos + 1"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="contains(' \t', substring($text, $pos, 1))">
+ <xsl:call-template name="highlight-text-pp-directive-length">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="pos" select="$pos + 1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
- <xsl:call-template name="highlight-identifier">
- <xsl:with-param name="identifier" select="substring($text, 1, $pos - 1)"/>
+ <xsl:value-of select="$pos - 1"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+ <xsl:template name="highlight-text-impl-leading-whitespace">
+ <xsl:param name="text"/>
+ <xsl:choose>
+ <xsl:when test="string-length($text) = 0"/>
+ <xsl:when test="contains(' 

	', substring($text, 1, 1))">
+ <xsl:value-of select="substring($text, 1, 1)"/>
+ <xsl:call-template name="highlight-text-impl-leading-whitespace">
+ <xsl:with-param name="text" select="substring($text, 2)"/>
</xsl:call-template>
- <xsl:call-template name ="highlight-text-impl-root">
- <xsl:with-param name="text" select="substring($text, $pos)"/>
+ </xsl:when>
+ <xsl:when test="'#' = substring($text, 1, 1)">
+ <xsl:variable name="pp-length">
+ <xsl:call-template name="highlight-text-pp-directive-length">
+ <xsl:with-param name="text" select="$text"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:call-template name="highlight-pp-directive">
+ <xsl:with-param name="text" select="substring($text, 1, $pp-length)"/>
+ </xsl:call-template>
+ <xsl:call-template name="highlight-text-impl-root">
+ <xsl:with-param name="text" select="substring($text, $pp-length + 1)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="highlight-text-impl-root">
+ <xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
@@ -74,24 +215,76 @@
<xsl:choose>
<xsl:when test="string-length($text) = 0"/>
<xsl:when test="contains($id-chars, substring($text, 1, 1))">
- <xsl:call-template name="highlight-text-impl-ident">
- <xsl:with-param name="text" select="$text"/>
- <xsl:with-param name="pos" select="2"/>
+ <xsl:variable name="ident-length">
+ <xsl:call-template name="highlight-text-ident-length">
+ <xsl:with-param name="text" select="$text"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:call-template name="highlight-identifier">
+ <xsl:with-param name="identifier" select="substring($text, 1, $ident-length)"/>
+ </xsl:call-template>
+ <xsl:call-template name="highlight-text-impl-root">
+ <xsl:with-param name="text" select="substring($text, $ident-length + 1)"/>
</xsl:call-template>
</xsl:when>
- <xsl:otherwise>
+ <xsl:when test="substring($text, 1, 2) = '//'">
+ <xsl:call-template name="highlight-comment">
+ <xsl:with-param name="text" select="substring-before($text, '\n')"/>
+ </xsl:call-template>
+ <xsl:call-template name="highlight-text-impl-root">
+ <xsl:with-param name="text" select="concat('\n', substring-after($text, '\n'))"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="substring($text, 1, 2) = '/*'">
+ <xsl:call-template name="highlight-comment">
+ <xsl:with-param name="text" select="concat(substring-before($text, '*/'), '*/')"/>
+ </xsl:call-template>
+ <xsl:call-template name="highlight-text-impl-root">
+ <xsl:with-param name="text" select="substring-after($text, '*/')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="contains('

', substring($text, 1, 1))">
+ <xsl:value-of select="substring($text, 1, 1)"/>
+ <xsl:call-template name="highlight-text-impl-leading-whitespace">
+ <xsl:with-param name="text" select="substring($text, 2)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="contains(' 	', substring($text, 1, 1))">
<xsl:value-of select="substring($text, 1, 1)"/>
<xsl:call-template name="highlight-text-impl-root">
<xsl:with-param name="text" select="substring($text, 2)"/>
</xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="operator-length">
+ <xsl:call-template name="highlight-text-operator-length">
+ <xsl:with-param name="text" select="$text"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="$operator-length = 0">
+ <xsl:value-of select="substring($text, 1, 1)"/>
+ <xsl:call-template name="highlight-text-impl-root">
+ <xsl:with-param name="text" select="substring($text, 2)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="highlight-special">
+ <xsl:with-param name="text" select="substring($text, 1, $operator-length)"/>
+ </xsl:call-template>
+ <xsl:call-template name="highlight-text-impl-root">
+ <xsl:with-param name="text" select="substring($text, $operator-length + 1)"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- <!-- Perform C++ keyword highlighting on the given text -->
+ <!-- Perform C++ syntax highlighting on the given text -->
<xsl:template name="highlight-text">
<xsl:param name="text" select="."/>
- <xsl:call-template name="highlight-text-impl-root">
+ <xsl:call-template name="highlight-text-impl-leading-whitespace">
<xsl:with-param name="text" select="$text"/>
</xsl:call-template>
</xsl:template>
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk