diff options
author | Adrian Kummerlaender | 2016-02-14 23:00:23 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2016-02-14 23:01:18 +0100 |
commit | da8a33160ff609025ba18986a6f671bf3e857a4d (patch) | |
tree | 09228bd5be251b76f84e4c958778f4d5fbed068c /utility | |
parent | f73301f782137a497ea09a42feaec9b2f239c286 (diff) | |
download | Overview-da8a33160ff609025ba18986a6f671bf3e857a4d.tar Overview-da8a33160ff609025ba18986a6f671bf3e857a4d.tar.gz Overview-da8a33160ff609025ba18986a6f671bf3e857a4d.tar.bz2 Overview-da8a33160ff609025ba18986a6f671bf3e857a4d.tar.lz Overview-da8a33160ff609025ba18986a6f671bf3e857a4d.tar.xz Overview-da8a33160ff609025ba18986a6f671bf3e857a4d.tar.zst Overview-da8a33160ff609025ba18986a6f671bf3e857a4d.zip |
Port `blog.kummerlaender.eu` code block handling for commit messages
Diffstat (limited to 'utility')
-rw-r--r-- | utility/formatter.xsl | 59 |
1 files changed, 57 insertions, 2 deletions
diff --git a/utility/formatter.xsl b/utility/formatter.xsl index d2c2f7c..2c7f3b9 100644 --- a/utility/formatter.xsl +++ b/utility/formatter.xsl @@ -2,11 +2,12 @@ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xalan="http://xml.apache.org/xalan" xmlns:InputXSLT="function.inputxslt.application" - exclude-result-prefixes="InputXSLT" + exclude-result-prefixes="xalan InputXSLT" > -<xsl:template name="formatter"> +<xsl:template name="plain_formatter"> <xsl:param name="format"/> <xsl:param name="source"/> @@ -16,4 +17,58 @@ )/self::command/node()"/> </xsl:template> +<xsl:template name="highlighter"> + <xsl:param name="source"/> + <xsl:param name="language"/> + + <xsl:variable name="formatted_code"> + <xsl:call-template name="plain_formatter"> + <xsl:with-param name="format"> + <xsl:text>highlight --out-format=xhtml --inline-css --style=molokai --fragment --enclose-pre --wrap-simple --syntax=</xsl:text> + <xsl:value-of select="$language"/> + </xsl:with-param> + <xsl:with-param name="source" select="$source"/> + </xsl:call-template> + </xsl:variable> + + <pre> + <xsl:copy-of select="xalan:nodeset($formatted_code)/pre/node()"/> + </pre> +</xsl:template> + +<xsl:template match="@*|node()" mode="embellish"> + <xsl:copy> + <xsl:apply-templates select="@*|node()" mode="embellish"/> + </xsl:copy> +</xsl:template> + +<xsl:template match="pre" mode="embellish"> + <xsl:call-template name="highlighter"> + <xsl:with-param name="source" select="code/text()"/> + <xsl:with-param name="language"> + <xsl:choose> + <xsl:when test="code/@class"> + <xsl:value-of select="substring(code/@class, 10, string-length(code/@class))"/> + </xsl:when> + <xsl:otherwise> + <xsl:text>txt</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:with-param> + </xsl:call-template> +</xsl:template> + +<xsl:template name="formatter"> + <xsl:param name="source"/> + + <xsl:variable name="content"> + <xsl:call-template name="plain_formatter"> + <xsl:with-param name="format">kramdown</xsl:with-param> + <xsl:with-param name="source" select="$source"/> + </xsl:call-template> + </xsl:variable> + + <xsl:apply-templates select="xalan:nodeset($content)" mode="embellish"/> +</xsl:template> + </xsl:stylesheet> |