[29] | 1 | <?xml version="1.0" encoding="utf-8"?> |
---|
| 2 | <!-- |
---|
| 3 | Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com> |
---|
| 4 | |
---|
| 5 | Distributed under the Boost Software License, Version 1.0. |
---|
| 6 | (See accompanying file LICENSE_1_0.txt or copy at |
---|
| 7 | http://www.boost.org/LICENSE_1_0.txt) |
---|
| 8 | --> |
---|
| 9 | <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
---|
| 10 | version="1.0"> |
---|
| 11 | <xsl:param name="boost.syntax.highlight">1</xsl:param> |
---|
| 12 | |
---|
| 13 | <xsl:template name="source-highlight"> |
---|
| 14 | <xsl:param name="text" select="."/> |
---|
| 15 | <xsl:choose> |
---|
| 16 | <xsl:when test="$boost.syntax.highlight='1'"> |
---|
| 17 | <xsl:call-template name="highlight-text"> |
---|
| 18 | <xsl:with-param name="text" select="$text"/> |
---|
| 19 | </xsl:call-template> |
---|
| 20 | </xsl:when> |
---|
| 21 | <xsl:otherwise> |
---|
| 22 | <xsl:value-of select="$text"/> |
---|
| 23 | </xsl:otherwise> |
---|
| 24 | </xsl:choose> |
---|
| 25 | </xsl:template> |
---|
| 26 | |
---|
| 27 | <!-- Perform C++ keyword highlighting on the given text --> |
---|
| 28 | <xsl:template name="highlight-text"> |
---|
| 29 | <xsl:param name="text" select="."/> |
---|
| 30 | <xsl:param name="keywords" |
---|
| 31 | 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'"/> |
---|
| 32 | <xsl:param name="best-match" select="''"/> |
---|
| 33 | |
---|
| 34 | <!-- Determine the current keyword --> |
---|
| 35 | <xsl:variable name="keyword"> |
---|
| 36 | <xsl:choose> |
---|
| 37 | <xsl:when test="contains($keywords, ' ')"> |
---|
| 38 | <xsl:value-of select="substring-before($keywords, ' ')"/> |
---|
| 39 | </xsl:when> |
---|
| 40 | <xsl:otherwise> |
---|
| 41 | <xsl:value-of select="$keywords"/> |
---|
| 42 | </xsl:otherwise> |
---|
| 43 | </xsl:choose> |
---|
| 44 | </xsl:variable> |
---|
| 45 | |
---|
| 46 | <!-- Determine the set of keywords that are left --> |
---|
| 47 | <xsl:variable name="keywords-left"> |
---|
| 48 | <xsl:if test="contains($keywords, ' ')"> |
---|
| 49 | <xsl:value-of select="substring-after($keywords, ' ')"/> |
---|
| 50 | </xsl:if> |
---|
| 51 | </xsl:variable> |
---|
| 52 | |
---|
| 53 | <!-- The set of characters that can be identifiers --> |
---|
| 54 | <xsl:variable name="id-chars" select="'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'"/> |
---|
| 55 | |
---|
| 56 | <xsl:variable name="X" select="'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'"/> |
---|
| 57 | |
---|
| 58 | <xsl:choose> |
---|
| 59 | <!-- Have we exhausted all keywords without finding any to highlight? --> |
---|
| 60 | <xsl:when test="$keyword='' and $best-match=''"> |
---|
| 61 | <!-- Just copy the text --> |
---|
| 62 | <xsl:copy-of select="$text"/> |
---|
| 63 | </xsl:when> |
---|
| 64 | |
---|
| 65 | <!-- Have we exhausted all keywords, but have one to highlight? If so, |
---|
| 66 | make sure we didn't just find part of an identifier. --> |
---|
| 67 | <xsl:when |
---|
| 68 | test="$keyword='' and |
---|
| 69 | not (starts-with(translate(substring-after($text, $best-match), |
---|
| 70 | $id-chars, $X), 'X')) and |
---|
| 71 | not (substring(translate(substring-before($text, $best-match), |
---|
| 72 | $id-chars, $X), |
---|
| 73 | string-length(substring-before($text, |
---|
| 74 | $best-match)), |
---|
| 75 | 1) = 'X')"> |
---|
| 76 | <!-- Copy text before this keyword --> |
---|
| 77 | <xsl:value-of select="substring-before($text, $best-match)"/> |
---|
| 78 | |
---|
| 79 | <!-- Highlight the keyword --> |
---|
| 80 | <xsl:call-template name="highlight-keyword"> |
---|
| 81 | <xsl:with-param name="keyword" select="$best-match"/> |
---|
| 82 | </xsl:call-template> |
---|
| 83 | |
---|
| 84 | <!-- Recurse on the rest of the text --> |
---|
| 85 | <xsl:call-template name="highlight-text"> |
---|
| 86 | <xsl:with-param name="text" |
---|
| 87 | select="substring-after($text, $best-match)"/> |
---|
| 88 | </xsl:call-template> |
---|
| 89 | </xsl:when> |
---|
| 90 | |
---|
| 91 | <!-- We thought we had a keyword to highlight, but it was part of an |
---|
| 92 | identifier. So output all of the text up to (but not including!) |
---|
| 93 | the last letter of the identifier, and try again to |
---|
| 94 | highlight. --> |
---|
| 95 | <xsl:when test="$keyword=''"> |
---|
| 96 | <xsl:value-of select="substring-before($text, $best-match)"/> |
---|
| 97 | <xsl:value-of |
---|
| 98 | select="substring($best-match, 1, string-length($best-match)-1)"/> |
---|
| 99 | <xsl:call-template name="highlight-text"> |
---|
| 100 | <xsl:with-param name="text" |
---|
| 101 | select="concat(substring($best-match, string-length($best-match), |
---|
| 102 | 1), substring-after($text, $best-match))"/> |
---|
| 103 | </xsl:call-template> |
---|
| 104 | </xsl:when> |
---|
| 105 | |
---|
| 106 | <!-- Does the text contain this keyword with a better match than we |
---|
| 107 | previously had? --> |
---|
| 108 | <xsl:when |
---|
| 109 | test="contains($text, $keyword) and |
---|
| 110 | (($best-match = '') or |
---|
| 111 | (string-length(substring-before($text, $keyword)) < |
---|
| 112 | string-length(substring-before($text, $best-match))))"> |
---|
| 113 | <!-- Recurse with the current keyword as the new best match --> |
---|
| 114 | <xsl:call-template name="highlight-text"> |
---|
| 115 | <xsl:with-param name="text" select="$text"/> |
---|
| 116 | <xsl:with-param name="keywords" select="$keywords-left"/> |
---|
| 117 | <xsl:with-param name="best-match" select="$keyword"/> |
---|
| 118 | </xsl:call-template> |
---|
| 119 | </xsl:when> |
---|
| 120 | |
---|
| 121 | <!-- Text does not contain this keyword. Just recurse normally --> |
---|
| 122 | <xsl:otherwise> |
---|
| 123 | <xsl:call-template name="highlight-text"> |
---|
| 124 | <xsl:with-param name="text" select="$text"/> |
---|
| 125 | <xsl:with-param name="keywords" select="$keywords-left"/> |
---|
| 126 | <xsl:with-param name="best-match" select="$best-match"/> |
---|
| 127 | </xsl:call-template> |
---|
| 128 | </xsl:otherwise> |
---|
| 129 | </xsl:choose> |
---|
| 130 | </xsl:template> |
---|
| 131 | |
---|
| 132 | <xsl:template match="*" mode="highlight"> |
---|
| 133 | <xsl:element name="{name(.)}"> |
---|
| 134 | <xsl:for-each select="./@*"> |
---|
| 135 | <xsl:choose> |
---|
| 136 | <xsl:when test="local-name(.)='last-revision'"> |
---|
| 137 | <xsl:attribute |
---|
| 138 | name="rev:last-revision" |
---|
| 139 | namespace="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" |
---|
| 140 | > |
---|
| 141 | <xsl:value-of select="."/> |
---|
| 142 | </xsl:attribute> |
---|
| 143 | </xsl:when> |
---|
| 144 | <xsl:otherwise> |
---|
| 145 | <xsl:attribute name="{name(.)}"> |
---|
| 146 | <xsl:value-of select="."/> |
---|
| 147 | </xsl:attribute> |
---|
| 148 | </xsl:otherwise> |
---|
| 149 | </xsl:choose> |
---|
| 150 | </xsl:for-each> |
---|
| 151 | <xsl:apply-templates mode="highlight"/> |
---|
| 152 | </xsl:element> |
---|
| 153 | </xsl:template> |
---|
| 154 | |
---|
| 155 | <xsl:template match="text()" mode="highlight"> |
---|
| 156 | <xsl:call-template name="source-highlight"> |
---|
| 157 | <xsl:with-param name="text" select="."/> |
---|
| 158 | </xsl:call-template> |
---|
| 159 | </xsl:template> |
---|
| 160 | |
---|
| 161 | <xsl:template match="classname|methodname|functionname|libraryname|enumname| |
---|
| 162 | conceptname|macroname" mode="highlight"> |
---|
| 163 | <xsl:apply-templates select="." mode="annotation"/> |
---|
| 164 | </xsl:template> |
---|
| 165 | </xsl:stylesheet> |
---|