summaryrefslogtreecommitdiff
path: root/docs/newapi.xsl
diff options
context:
space:
mode:
authorClaudio Bley <cbley@av-test.de>2013-01-22 13:45:11 +0100
committerClaudio Bley <cbley@av-test.de>2013-10-30 17:30:11 +0100
commit8213f6c38e2fc48e5ea37c8fb512b17d070c07fd (patch)
treeaddcc9f474aaf69bc0e22c0753da6e176082c223 /docs/newapi.xsl
parentf26701f565525dd402df021d8923489e62412158 (diff)
downloadlibvirt-8213f6c38e2fc48e5ea37c8fb512b17d070c07fd.tar.gz
docs: process code blocks similar to Markdown
Wrap pre-formatted example code in <code> elements. This works similar to Markdown[1] code blocks[2]: Every line indented with at least 2 spaces is considered a code block and gets wrapped in <pre> and <code> tags. Look at the documentation for e.g. virStreamSend for before-and-after effects. [1] http://daringfireball.net/projects/markdown/ [2] http://daringfireball.net/projects/markdown/syntax#precode
Diffstat (limited to 'docs/newapi.xsl')
-rw-r--r--docs/newapi.xsl96
1 files changed, 74 insertions, 22 deletions
diff --git a/docs/newapi.xsl b/docs/newapi.xsl
index 7fa0f26889..d62839ad6f 100644
--- a/docs/newapi.xsl
+++ b/docs/newapi.xsl
@@ -150,6 +150,67 @@
</xsl:for-each>
</xsl:template>
+
+ <!-- process blocks of text. blocks are separated by two consecutive line -->
+ <!-- breaks. -->
+ <!-- -->
+ <!-- blocks indented with at least 2 spaces are considered code blocks. -->
+ <!-- -->
+ <!-- consecutive code blocks are collapsed into a single code block. -->
+ <xsl:template name="formatblock">
+ <xsl:param name="block"/>
+ <xsl:param name="rest"/>
+
+ <xsl:variable name="multipleCodeBlocks"
+ select="starts-with($block, ' ') and starts-with($rest, ' ')"/>
+
+ <xsl:choose>
+ <xsl:when test="$multipleCodeBlocks">
+ <xsl:call-template name="formatblock">
+ <xsl:with-param name="block">
+ <xsl:choose>
+ <xsl:when test="contains($rest, '&#xA;&#xA;')">
+ <xsl:value-of select="concat($block, '&#xA; &#xA;',
+ substring-before($rest, '&#xA;&#xA;'))" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat($block, '&#xA; &#xA;', $rest)" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ <xsl:with-param name="rest" select="substring-after($rest, '&#xA;&#xA;')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="starts-with($block, ' ')">
+ <pre class="code"><xsl:for-each select="str:tokenize($block, '&#xA;')">
+ <xsl:choose>
+ <xsl:when test="starts-with(., ' ')">
+ <xsl:value-of select="substring(., 3)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="."/>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:if test="position() != last()">
+ <xsl:text>&#xA;</xsl:text>
+ </xsl:if>
+ </xsl:for-each></pre>
+ </xsl:when>
+ <xsl:otherwise>
+ <p>
+ <xsl:call-template name="dumptext">
+ <xsl:with-param name="text" select="$block"/>
+ </xsl:call-template>
+ </p>
+ </xsl:otherwise>
+ </xsl:choose>
+ <xsl:if test="not($multipleCodeBlocks)">
+ <xsl:call-template name="formattext">
+ <xsl:with-param name="text" select="$rest"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:template>
+
<xsl:template name="formattext">
<xsl:param name="text" />
@@ -157,28 +218,19 @@
<xsl:variable name="head" select="substring-before($text, '&#xA;&#xA;')"/>
<xsl:variable name="rest" select="substring-after($text, '&#xA;&#xA;')"/>
- <xsl:choose>
- <xsl:when test="$head">
- <p>
- <xsl:call-template name="dumptext">
- <xsl:with-param name="text" select="$head"/>
- </xsl:call-template>
- </p>
- </xsl:when>
- <xsl:when test="not($rest)">
- <p>
- <xsl:call-template name="dumptext">
- <xsl:with-param name="text" select="$text"/>
- </xsl:call-template>
- </p>
- </xsl:when>
- </xsl:choose>
-
- <xsl:if test="$rest">
- <xsl:call-template name="formattext">
- <xsl:with-param name="text" select="$rest"/>
- </xsl:call-template>
- </xsl:if>
+ <xsl:call-template name="formatblock">
+ <xsl:with-param name="block">
+ <xsl:choose>
+ <xsl:when test="contains($text, '&#xA;&#xA;')">
+ <xsl:value-of select="$head"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$text"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ <xsl:with-param name="rest" select="$rest"/>
+ </xsl:call-template>
</xsl:if>
</xsl:template>