aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2014-09-04 19:30:24 +0200
committerAdrian Kummerlaender2014-09-04 19:30:24 +0200
commit60be999bc36360cabe37a648e6a6b974485b884d (patch)
tree09b36a5138046edd610ed911a7c75c4dd3e7bfc6
parent8769770a39b7ad8fc9f2911e9a5956c2dfbf6e8c (diff)
downloadblog.kummerlaender.eu-60be999bc36360cabe37a648e6a6b974485b884d.tar
blog.kummerlaender.eu-60be999bc36360cabe37a648e6a6b974485b884d.tar.gz
blog.kummerlaender.eu-60be999bc36360cabe37a648e6a6b974485b884d.tar.bz2
blog.kummerlaender.eu-60be999bc36360cabe37a648e6a6b974485b884d.tar.lz
blog.kummerlaender.eu-60be999bc36360cabe37a648e6a6b974485b884d.tar.xz
blog.kummerlaender.eu-60be999bc36360cabe37a648e6a6b974485b884d.tar.zst
blog.kummerlaender.eu-60be999bc36360cabe37a648e6a6b974485b884d.zip
Extracted formatter functionality into formatter helper stylesheet
* functionality for formatting markdown using kramdown and embellishing the result with e.g. syntax highlighting is required for all content types
-rw-r--r--source/01_data/articles.xsl34
-rw-r--r--source/01_data/pages.xsl3
-rw-r--r--utility/formatter.xsl74
-rw-r--r--utility/helper.xsl20
4 files changed, 77 insertions, 54 deletions
diff --git a/source/01_data/articles.xsl b/source/01_data/articles.xsl
index 8e65f40..3b3ac14 100644
--- a/source/01_data/articles.xsl
+++ b/source/01_data/articles.xsl
@@ -7,7 +7,7 @@
exclude-result-prefixes="xalan InputXSLT"
>
-<xsl:include href="[utility/helper.xsl]"/>
+<xsl:include href="[utility/formatter.xsl]"/>
<xsl:include href="[utility/datasource.xsl]"/>
<xsl:variable name="meta">
@@ -15,35 +15,6 @@
<target mode="plain" value="articles.xml"/>
</xsl:variable>
-<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:variable name="formatted_code">
- <xsl:call-template name="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: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:with-param name="source" select="code/text()"/>
- </xsl:call-template>
- </xsl:variable>
-
- <pre>
- <xsl:copy-of select="xalan:nodeset($formatted_code)/pre/node()"/>
- </pre>
-</xsl:template>
-
<xsl:template name="list_tags">
<xsl:param name="path"/>
@@ -61,7 +32,6 @@
<xsl:template match="files/directory[@name = 'articles']/file[@extension = '.md']">
<xsl:variable name="content">
<xsl:call-template name="formatter">
- <xsl:with-param name="format">kramdown</xsl:with-param>
<xsl:with-param name="source" select="InputXSLT:read-file(./full)/text()"/>
</xsl:call-template>
</xsl:variable>
@@ -84,7 +54,7 @@
</xsl:call-template>
</tags>
<content>
- <xsl:apply-templates select="xalan:nodeset($content)/*[name() != 'h1']" mode="embellish"/>
+ <xsl:copy-of select="xalan:nodeset($content)/*[name() != 'h1']"/>
</content>
</entry>
</xsl:template>
diff --git a/source/01_data/pages.xsl b/source/01_data/pages.xsl
index cdfa6d4..fe0e54d 100644
--- a/source/01_data/pages.xsl
+++ b/source/01_data/pages.xsl
@@ -7,7 +7,7 @@
exclude-result-prefixes="xalan InputXSLT"
>
-<xsl:include href="[utility/helper.xsl]"/>
+<xsl:include href="[utility/formatter.xsl]"/>
<xsl:include href="[utility/datasource.xsl]"/>
<xsl:variable name="meta">
@@ -18,7 +18,6 @@
<xsl:template match="files/directory[@name = 'pages']//file[@extension = '.md']">
<xsl:variable name="content">
<xsl:call-template name="formatter">
- <xsl:with-param name="format">kramdown</xsl:with-param>
<xsl:with-param name="source" select="InputXSLT:read-file(./full)/text()"/>
</xsl:call-template>
</xsl:variable>
diff --git a/utility/formatter.xsl b/utility/formatter.xsl
new file mode 100644
index 0000000..2c7f3b9
--- /dev/null
+++ b/utility/formatter.xsl
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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="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="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>
diff --git a/utility/helper.xsl b/utility/helper.xsl
deleted file mode 100644
index 84b6b31..0000000
--- a/utility/helper.xsl
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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="xalan InputXSLT"
->
-
-<xsl:template name="formatter">
- <xsl:param name="format"/>
- <xsl:param name="source"/>
-
- <xsl:copy-of select="InputXSLT:external-command(
- $format,
- $source
- )/self::command/node()"/>
-</xsl:template>
-
-</xsl:stylesheet>