I am writing these blogs in markdown and using Pandoc to compile them into html. Lunky for me, Pandoc is written in Haskell and there is a way to alter how Pandoc works to fit my needs. These are called filters and I am experimenting with them a bit.
Here is a rundown of how they work:
The path looks like:
INPUT -{Pandoc}-> Internal -{Filter}-> New Internal -{Pandoc}-> OUTPUT
The first usefule thing I implemented was an ability to use the
@
symbol to tell Pandoc that the word that follows it is
important and should have a link to a blog with the same name as the
word. For example @pandoc-filters
or pandoc-filters will make a link
back to this page. These pages don’t even need to be implemented and the link will
just take you to where it expects I might one day add the link (click on
implemented to see).
Here is an example of a Haskell code that produces this effect:
import qualified Data.Text as T
import Text.Pandoc.JSON
main :: IO ()
= do
main
toJSONFilter linkToBlogreturn ()
-- | adds a link to any blog with a word in the form @word
linkToBlog :: Inline -> Inline
Str strText)
linkToBlog (| head strString == '@' = linkTo
where
= T.unpack strText
strString = tail . T.unpack . T.toLower
toLowerStr = Link
linkTo
( T.empty , [] , [] )Underline [ Str (T.tail strText) ]]
[ "./" ++ toLowerStr strText ++ ".html") , T.empty )
( T.pack (= x -- any other case just don't do anything linkToBlog x
Then when I call my homemade script:
pandoc $(pwd)/md/blogs/$name}.md -o $(pwd)/generated/blogs/$name.html -f markdown -T html --filter pandoc-filter/exe/pandoc-filter
where the --filter
option is where I put the executable
I get from Haskell code.
These are cool and I hope to continue to use them to make my life easier!