summaryrefslogtreecommitdiff
path: root/utility/formatter.xsl
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-02-11 22:22:27 +0100
committerAdrian Kummerlaender2017-02-11 22:22:27 +0100
commit490963c1550efffe046179ced9b39573185e3e1d (patch)
treea5d7ed4bd1dc7408a77dda09b22ae0d332938925 /utility/formatter.xsl
downloadtree.kummerlaender.eu-490963c1550efffe046179ced9b39573185e3e1d.tar
tree.kummerlaender.eu-490963c1550efffe046179ced9b39573185e3e1d.tar.gz
tree.kummerlaender.eu-490963c1550efffe046179ced9b39573185e3e1d.tar.bz2
tree.kummerlaender.eu-490963c1550efffe046179ced9b39573185e3e1d.tar.lz
tree.kummerlaender.eu-490963c1550efffe046179ced9b39573185e3e1d.tar.xz
tree.kummerlaender.eu-490963c1550efffe046179ced9b39573185e3e1d.tar.zst
tree.kummerlaender.eu-490963c1550efffe046179ced9b39573185e3e1d.zip
Initial implementation of a tree-like website generator based on InputXSLT
The foundation was forked from `blog.kummerlaender.eu`. Currently generates arbitrarily nested markdown documents in addition to overview pages for branches in the tree. This includes resolution of branch node contents.
Diffstat (limited to 'utility/formatter.xsl')
-rw-r--r--utility/formatter.xsl134
1 files changed, 134 insertions, 0 deletions
diff --git a/utility/formatter.xsl b/utility/formatter.xsl
new file mode 100644
index 0000000..f590d89
--- /dev/null
+++ b/utility/formatter.xsl
@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet
+ version="1.0"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xalan="http://xml.apache.org/xalan"
+ xmlns:InputXSLT="function.inputxslt.application"
+ exclude-result-prefixes="xalan InputXSLT"
+>
+
+<xsl:template name="plain_formatter">
+ <xsl:param name="format"/>
+ <xsl:param name="source"/>
+
+ <xsl:copy-of select="InputXSLT:external-command(
+ $format,
+ $source
+ )/self::command/node()"/>
+</xsl:template>
+
+<xsl:template name="math_highlighter">
+ <xsl:param name="source"/>
+ <xsl:param name="arguments"/>
+
+ <xsl:variable name="formatted_expression">
+ <xsl:call-template name="plain_formatter">
+ <xsl:with-param name="format">
+ <xsl:text>katex </xsl:text>
+ <xsl:value-of select="$arguments"/>
+ </xsl:with-param>
+ <xsl:with-param name="source" select="$source"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:copy-of select="xalan:nodeset($formatted_expression)/node()"/>
+</xsl:template>
+
+<xsl:template name="code_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="h2" mode="embellish">
+ <h3>
+ <xsl:apply-templates select="node()" mode="embellish"/>
+ </h3>
+</xsl:template>
+
+<xsl:template match="h3" mode="embellish">
+ <h4>
+ <xsl:apply-templates select="node()" mode="embellish"/>
+ </h4>
+</xsl:template>
+
+<xsl:template match="pre" mode="embellish">
+ <xsl:call-template name="code_highlighter">
+ <xsl:with-param name="source" select="code/text()"/>
+ <xsl:with-param name="language">
+ <xsl:choose>
+ <xsl:when test="@class">
+ <xsl:value-of select="@class"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:text>txt</xsl:text>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:with-param>
+ </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="div[@class = 'figure']" mode="embellish">
+ <p>
+ <xsl:apply-templates select="img" mode="embellish"/>
+ </p>
+</xsl:template>
+
+<xsl:template match="div[@class = 'footnotes']/hr" mode="embellish"/>
+
+<xsl:template match="span[contains(@class, 'math')]" mode="embellish">
+ <xsl:choose>
+ <xsl:when test="contains(@class, 'display')">
+ <p class="math">
+ <xsl:call-template name="math_highlighter">
+ <xsl:with-param name="source" select="text()"/>
+ <xsl:with-param name="arguments">
+ <xsl:text>--display-mode</xsl:text>
+ </xsl:with-param>
+ </xsl:call-template>
+ </p>
+ </xsl:when>
+ <xsl:otherwise>
+ <span class="math">
+ <xsl:call-template name="math_highlighter">
+ <xsl:with-param name="source" select="text()"/>
+ </xsl:call-template>
+ </span>
+ </xsl:otherwise>
+ </xsl:choose>
+</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">pandoc -f markdown -t html --katex --no-highlight</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>