Created
March 31, 2016 11:21
-
-
Save scturtle/9236b7208aab9985a3af0d319bdb4041 to your computer and use it in GitHub Desktop.
hakyll use external pygments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
customPandocCompiler :: Compiler (Item String) | |
customPandocCompiler = | |
let extraExtensions = | |
[ Ext_east_asian_line_breaks | |
, Ext_tex_math_double_backslash | |
] | |
customExtensions = foldr S.insert pandocExtensions extraExtensions | |
writerOptions = defaultHakyllWriterOptions { | |
writerExtensions = customExtensions | |
, writerHighlight = True | |
, writerHTMLMathMethod = MathJax "" | |
} | |
in pandocCompilerWithTransformM defaultHakyllReaderOptions | |
writerOptions | |
pygmentize | |
-- modified from bitbucket.org/honk/pandoc-filters | |
pygmentize :: Pandoc -> Compiler Pandoc | |
pygmentize (Pandoc meta bs) = Pandoc meta <$> mapM highlight bs | |
highlight :: Block -> Compiler Block | |
highlight (CodeBlock (_, options, _) code) = | |
RawBlock "html" <$> unsafeCompiler (pygments code options) | |
highlight x = return x | |
pygments :: String -> [String] -> IO String | |
pygments code options = | |
case options of | |
(lang:_) -> | |
readProcess "pygmentize" ["-l", toLower <$> lang, "-f", "html"] code | |
_ -> return $ "<div class =\"highlight\"><pre>" ++ code ++ "</pre></div>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! Any insight on how to use this? I added it to my Hakyll site's Main.hs file and I'm getting the following errors: