2
0
mirror of https://github.com/boostorg/docca.git synced 2026-01-19 04:12:08 +00:00

Replace entity references with function calls

fix #137
This commit is contained in:
Evan Lenz
2023-01-26 19:50:36 -08:00
committed by evanlenz
parent 7aa8441f5c
commit 8e2c71d2ea
2 changed files with 46 additions and 35 deletions

View File

@@ -1,25 +1,29 @@
<!DOCTYPE xsl:stylesheet [
<!-- TODO: complete this list -->
<!ENTITY BLOCK_LEVEL_ELEMENT "programlisting
| itemizedlist
| orderedlist
| parameterlist
| simplesect
| para
| table
| linebreak">
]>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://github.com/vinniefalco/docca"
exclude-result-prefixes="xs d"
xmlns:my="http://localhost"
exclude-result-prefixes="xs d my"
expand-text="yes">
<xsl:include href="common.xsl"/>
<xsl:output indent="yes"/>
<xsl:function name="my:block-level-element-children">
<xsl:param name="context"/>
<!-- TODO: complete this list -->
<xsl:sequence select="$context/( programlisting
| itemizedlist
| orderedlist
| parameterlist
| simplesect
| para
| table
| linebreak
)"/>
</xsl:function>
<xsl:template match="/doxygen" priority="1">
<page id="{@d:page-id}" type="{@d:page-type}">
<xsl:apply-templates mode="index-term-atts" select="."/>
@@ -618,7 +622,7 @@
<!-- When a <para> directly contains a mix of inline nodes and block-level elements, normalize its content -->
<xsl:template match="para[&BLOCK_LEVEL_ELEMENT;]">
<xsl:template match="para[my:block-level-element-children(.)]">
<para>
<xsl:for-each-group select="* | text()" group-adjacent="d:is-inline(.)">
<xsl:apply-templates mode="capture-ranges" select="."/>
@@ -628,7 +632,7 @@
<xsl:function name="d:is-inline">
<xsl:param name="node"/>
<xsl:sequence select="not($node/../(&BLOCK_LEVEL_ELEMENT;)[. is $node])"/>
<xsl:sequence select="not($node/../my:block-level-element-children(.)[. is $node])"/>
</xsl:function>
<!-- Process the block-level elements as usual -->

View File

@@ -1,19 +1,8 @@
<!DOCTYPE xsl:stylesheet [
<!ENTITY SYNTAX_BLOCK "*[ self::compound
| self::function
| self::typedef
| self::enum
| self::variable
| self::overloaded-member
]">
<!ENTITY CODE_BLOCK "*[ self::computeroutput[not(ref)]
| self::code
]">
]>
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:d="http://github.com/vinniefalco/docca"
xmlns:my="http://localhost"
expand-text="yes">
<xsl:import href="common.xsl"/>
@@ -27,6 +16,24 @@
<xsl:variable name="list-indent-width" select="4"/>
<xsl:function name="my:is-syntax-block">
<xsl:param name="element" as="element()"/>
<xsl:sequence select="exists($element/( self::compound
| self::function
| self::typedef
| self::enum
| self::variable
| self::overloaded-member
))"/>
</xsl:function>
<xsl:function name="my:is-code-block">
<xsl:param name="element" as="element()"/>
<xsl:sequence select="exists($element/( self::computeroutput[not(ref)]
| self::code
))"/>
</xsl:function>
<xsl:template mode="before" match="/page">
<xsl:text>{$nl}</xsl:text>
<xsl:text>[section:{tokenize(@id,'\.')[last()]} {d:qb-escape(title)}]</xsl:text>
@@ -56,8 +63,8 @@
<xsl:apply-templates mode="includes-template-footer" select="."/>
</xsl:template>
<xsl:template mode="before" match="&SYNTAX_BLOCK;">{$nl}```{$nl}</xsl:template>
<xsl:template mode="after" match="&SYNTAX_BLOCK;">{$nl}```{$nl}</xsl:template>
<xsl:template mode="before" match="*[my:is-syntax-block(.)]">{$nl}```{$nl}</xsl:template>
<xsl:template mode="after" match="*[my:is-syntax-block(.)]">{$nl}```{$nl}</xsl:template>
<!-- Merge adjacent overloaded-members into one syntax block, separated by one blank line -->
<xsl:template mode="after" match="overloaded-member[following-sibling::*[1]/self::overloaded-member]" priority="1"/>
@@ -80,12 +87,12 @@
</xsl:template>
<xsl:template priority="1"
match="&SYNTAX_BLOCK;//ref">``[link {$doc-ref}.{@d:refid} {d:qb-escape(.)}]``</xsl:template>
<xsl:template match="td[1]//ref" >[link {$doc-ref}.{@d:refid} {d:qb-escape(.)}]</xsl:template>
<xsl:template match="ref" >[link {$doc-ref}.{@d:refid} `{.}`]</xsl:template>
match="*[my:is-syntax-block(.)]//ref">``[link {$doc-ref}.{@d:refid} {d:qb-escape(.)}]``</xsl:template>
<xsl:template match="td[1]//ref" >[link {$doc-ref}.{@d:refid} {d:qb-escape(.)}]</xsl:template>
<xsl:template match="ref" >[link {$doc-ref}.{@d:refid} `{.}`]</xsl:template>
<xsl:template mode="before" match="&CODE_BLOCK;">`</xsl:template>
<xsl:template mode="after" match="&CODE_BLOCK;">`</xsl:template>
<xsl:template mode="before" match="*[my:is-code-block(.)]">`</xsl:template>
<xsl:template mode="after" match="*[my:is-code-block(.)]">`</xsl:template>
<xsl:template mode="before" match="enum/name">enum </xsl:template>
@@ -240,8 +247,8 @@
</xsl:template>
<!-- But don't escape them in these contexts -->
<xsl:template match="&SYNTAX_BLOCK;//text()
| &CODE_BLOCK;//text()">
<xsl:template match="*[my:is-syntax-block(.)]//text()
| *[my:is-code-block(.)]//text()">
<!--
This implementation (using <xsl:sequence> returning a string, instead of <xsl:value-of>) can
result in a contiguous sequence of strings, which gets converted to a text node having space