mirror of
https://github.com/boostorg/boostbook.git
synced 2025-05-09 15:03:57 +00:00
Rewrite the id code to convert the characters of parts of the id at the time of
generating the id. This means that characters are translated to underscores for ids as well as for filenames, since in the eventual documents they have to be percent encoded this is probably an approvement. It also lets us deal with the translation more intelligently and truncate long identifiers. [SVN r48927]
This commit is contained in:
parent
bd57856bca
commit
b9f65e69a4
@ -20,27 +20,9 @@
|
||||
<xsl:key name="named-entities" match="class|struct|union|concept|function|overloaded-function|macro|library|namespace/data-member|header/data-member|*[attribute::id]" use="@name|@id"/>
|
||||
|
||||
<xsl:template match="function|overloaded-function" mode="generate.id">
|
||||
<xsl:variable name="name" select="normalize-space(@name)"/>
|
||||
<xsl:variable name="translated-name"
|
||||
select="translate($name,
|
||||
'~!%^&*()[].,<>|/ +-=',
|
||||
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')"/>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="count(key('named-entities', $name))=1
|
||||
and ($translated-name=$name)">
|
||||
<xsl:call-template name="fully-qualified-id">
|
||||
<xsl:with-param name="node" select="."/>
|
||||
</xsl:call-template>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:call-template name="fully-qualified-id">
|
||||
<xsl:with-param name="node" select="."/>
|
||||
</xsl:call-template>
|
||||
<xsl:text>_</xsl:text>
|
||||
<xsl:value-of select="generate-id(.)"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
<xsl:call-template name="fully-qualified-id">
|
||||
<xsl:with-param name="node" select="."/>
|
||||
</xsl:call-template>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="classname" mode="annotation">
|
||||
|
@ -28,7 +28,7 @@
|
||||
<xsl:choose>
|
||||
<xsl:when test="not($recursive)">
|
||||
<!-- translate dots into directory separators, and replace illegal file path characters with underscores -->
|
||||
<xsl:value-of select="translate(normalize-space(translate($basename, '.<>\:*?"|,()!+=&', '/ ' )), ' ', '_')"/>
|
||||
<xsl:value-of select="translate($basename, '.<>\:*?"|,()!+=&', '/_______________' )"/>
|
||||
<xsl:value-of select="$html.ext"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
|
@ -152,7 +152,7 @@
|
||||
|
||||
<xsl:template match="header" mode="generate.id">
|
||||
<xsl:text>header.</xsl:text>
|
||||
<xsl:value-of select="translate(@name, '/','.')"/>
|
||||
<xsl:value-of select="translate(@name, '/.', '._')"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="*" mode="passthrough">
|
||||
|
@ -9,7 +9,10 @@
|
||||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
||||
version="1.0">
|
||||
|
||||
<xsl:param name="boost.max.id.length">26</xsl:param>
|
||||
<!-- Maximum length of directory and file names is 31 characters.
|
||||
'.html' uses 5 characters.
|
||||
31 - 5 = 26 -->
|
||||
<xsl:param name="boost.max.id.part.length">26</xsl:param>
|
||||
|
||||
<!-- Generate an ID for the entity referenced -->
|
||||
<xsl:template name="generate.id">
|
||||
@ -125,42 +128,31 @@
|
||||
<!-- Build the fully-qualified id of the given node -->
|
||||
<xsl:template name="fully-qualified-id">
|
||||
<xsl:param name="node"/>
|
||||
<xsl:variable name="name">
|
||||
<xsl:apply-templates select="$node" mode="fully-qualified-name">
|
||||
<xsl:with-param name="separator" select="'@'"/>
|
||||
</xsl:apply-templates>
|
||||
</xsl:variable>
|
||||
<xsl:value-of select="translate(normalize-space(translate($name, '.', ' ')), ' @', '_.')"/>
|
||||
<xsl:if test="$node/ancestor-or-self::class-specialization|
|
||||
$node/ancestor-or-self::struct-specialization|
|
||||
$node/ancestor-or-self::union-specialization">
|
||||
<xsl:text>_</xsl:text>
|
||||
<xsl:value-of select="generate-id($node)"/>
|
||||
</xsl:if>
|
||||
|
||||
<xsl:apply-templates select="$node" mode="fully-qualified-name">
|
||||
<xsl:with-param name="is.id" select="true()"/>
|
||||
</xsl:apply-templates>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Build the fully-qualified name of the given node -->
|
||||
<xsl:template name="fully-qualified-name">
|
||||
<xsl:param name="node"/>
|
||||
<xsl:param name="separator" select="'::'"/>
|
||||
<xsl:apply-templates select="$node" mode="fully-qualified-name">
|
||||
<xsl:with-param name="separator" select="$separator"/>
|
||||
</xsl:apply-templates>
|
||||
<xsl:apply-templates select="$node" mode="fully-qualified-name"/>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Hack to make the node we are building the current node so that the
|
||||
ancestor:: syntax will work -->
|
||||
<xsl:template match="*" mode="fully-qualified-name">
|
||||
<xsl:param name="separator" select="'::'"/>
|
||||
<xsl:param name="is.id" select="false()" />
|
||||
<xsl:call-template name="build-fully-qualified-name">
|
||||
<xsl:with-param name="separator" select="$separator"/>
|
||||
<xsl:with-param name="is.id" select="$is.id"/>
|
||||
</xsl:call-template>
|
||||
</xsl:template>
|
||||
|
||||
<!-- The real routine that builds a fully-qualified name for the current
|
||||
node. -->
|
||||
<xsl:template name="build-fully-qualified-name">
|
||||
<xsl:param name="separator" select="'::'"/>
|
||||
<xsl:param name="is.id" select="false()" />
|
||||
|
||||
<!-- The depth of qualified name element that we will print now-->
|
||||
<xsl:param name="depth" select="1"/>
|
||||
@ -173,22 +165,69 @@
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test="$depth > count($ancestors)">
|
||||
<xsl:apply-templates select="." mode="print-name"/>
|
||||
<xsl:apply-templates select="." mode="print-id-part">
|
||||
<xsl:with-param name="is.id" select="$is.id"/>
|
||||
</xsl:apply-templates>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:if test="name($ancestors[$depth])='namespace' or
|
||||
count(ancestor::free-function-group)=0">
|
||||
<xsl:apply-templates select="$ancestors[$depth]" mode="print-name"/>
|
||||
<xsl:value-of select="$separator"/>
|
||||
<xsl:apply-templates select="$ancestors[$depth]" mode="print-id-part">
|
||||
<xsl:with-param name="is.id" select="$is.id"/>
|
||||
</xsl:apply-templates>
|
||||
<xsl:choose>
|
||||
<xsl:when test="$is.id"><xsl:text>.</xsl:text></xsl:when>
|
||||
<xsl:otherwise><xsl:text>::</xsl:text></xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:if>
|
||||
<xsl:call-template name="build-fully-qualified-name">
|
||||
<xsl:with-param name="separator" select="$separator"/>
|
||||
<xsl:with-param name="is.id" select="$is.id"/>
|
||||
<xsl:with-param name="depth" select="$depth + 1"/>
|
||||
</xsl:call-template>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Print the part of a fully qualified name for a single element -->
|
||||
<xsl:template match="*" mode="print-id-part">
|
||||
<xsl:param name="is.id"/>
|
||||
|
||||
<xsl:variable name="part">
|
||||
<xsl:apply-templates select="." mode="print-name"/>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:variable name="unique-name">
|
||||
<xsl:apply-templates select="." mode="unique.name"/>
|
||||
</xsl:variable>
|
||||
|
||||
<xsl:choose>
|
||||
<xsl:when test=
|
||||
"$is.id and (
|
||||
string-length($part) > $boost.max.id.part.length or
|
||||
$unique-name = 0 or
|
||||
translate($part, '.<>;\:*?"| ', '') != $part
|
||||
)">
|
||||
<xsl:variable name="normalized" select="translate(normalize-space(translate($part, '.<>;\:*?"|_', ' ')), ' ', '_')"/>
|
||||
<xsl:value-of select =
|
||||
"concat(
|
||||
substring($normalized, 1, $boost.max.id.part.length - string-length(generate-id(.) - 1)),
|
||||
concat('_', generate-id(.)))"/>
|
||||
</xsl:when>
|
||||
<xsl:otherwise>
|
||||
<xsl:value-of select="$part"/>
|
||||
</xsl:otherwise>
|
||||
</xsl:choose>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Override this if an id might not be unique -->
|
||||
<xsl:template match="*" mode="unique.name">
|
||||
<xsl:value-of select="1"/>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="function|overloaded-function" mode="unique.name">
|
||||
<xsl:value-of select="number(count(key('named-entities', @name)) = 1)"/>
|
||||
</xsl:template>
|
||||
|
||||
<!-- Print the name of the current node -->
|
||||
<xsl:template match="*" mode="print-name">
|
||||
<xsl:value-of select="@name"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user