Hakyll Pandoc filtering
Posted on October 2, 2012
Tags: hacksoft
Hakyll Setup Series
- Setup Mathjax
- Setup PlantUML
- Setup autobuild Hakyll site Git action CI
- Very Simple Hakyll Pandoc Filtering Example
- Add Railroad Syntax to Hakyll
- Table Of Content in Hakyll
- Hakyll Access on LAN server
Pandoc filtering and translation - similar to a compiler
It will translate certain markdown strings you type up into another form.
Here I will show the simplest example:
Append a text “EOF” string to all of our codeblocks automatically
import Text.Pandoc
import Text.Pandoc.Walk
import Data.Text
addToCodeBlock :: Pandoc -> Pandoc
= walk ftranslate
addToCodeBlock where ftranslate :: Block -> Block
CodeBlock attr txt ) = CodeBlock attr (txt <> "EOF")
ftranslate (= x
ftranslate x
simpleCompiler :: Compiler (Item String)
= pandocCompilerWithTransform defaultHakyllReaderOptions defaultHakyllWriterOptions addToCodeBlock simpleCompiler
main :: IO ()
main = do
hakyllWith config $ do
...
match "posts/*" $ do
route $ setExtension "html"
compile $ simpleCompiler --ONLY CHANGE THIS
>>= loadAndApplyTemplate "templates/post.html" (postCtxWithTags tags)
...
1 Showcase
For example in my hakyll folder, I create a new file “2099-01-01-NewBlogPost.markdown” and the contents are
---
title: Hello World
tags: tech
---
This is my blog post.
'''python
print("Hello World")
'''
The codeblock will show:
print("Hello World")
EOF
2 Extra
Text refers to Data.Text.Text
CodeBlock Attr Text Attr = (Text, [Text], [(Text, Text)])
CodeBlock (Text, [Text], [(Text, Text)]) Text
We can convert CodeBlock to Dom Elements with RawBlock.
RawBlock Format Text
example:
RawBlock (Format "html") Text