, , . https://github.com/listx/listx_blog/blob/master/blog.hs , , transformer . transformer 69-80 'posts' - pandocCompilerWithTransformM, (Pandoc -> Compiler Pandoc) python - , $PATH - (, defaultHakyllReaderOptions defaultHakyllWriterOptions)
import Text.Pandoc
import Hakyll
type Script = String
transformer
:: Script -- e.g. "/absolute/path/filter.py"
-> ReaderOptions -- e.g. defaultHakyllReaderOptions
-> WriterOptions -- e.g. defaultHakyllWriterOptions
-> (Pandoc -> Compiler Pandoc)
transformer script reader_opts writer_opts pandoc =
do let input_json = writeJSON writer_opts pandoc
output_json <- unixFilter script [] input_json
return $
-- either (error.show) id $ -- this line needs to be uncommented atm.
readJSON reader_opts output_json
, (transformer "/usr/local/bin/myfilter.py" defaultHakyllReaderOptions defaultHakyllWriterOptions) , (return . pandocTransform), 125
unixFilter:
transform :: Script -> String -> Compiler String
transform script md = do json0 <- unixFilter pandoc input_args md
json1 <- unixFilter script [] json0
unixFilter pandoc output_args json1
where
pandoc = "pandoc"
input_args = words "-f markdown -t json" -- add others
output_args = words "-f json -t html" -- add others
do unix- pandoc -t json | filter.py | pandoc -f json .
, , , , pandoc. pandocCompilerWithTransform(M) Pandoc- > Pandoc - Pandoc hakyll. , Pandoc. unixCompile .
transformXLVI :: Script -> ReaderOptions -> WriterOptions -> String -> Compiler Html
transformXLVI script ropts wopts = fmap fromJSON . unixFilter script [] . toJSON
where
toJSON = writeJSON wopts
-- . either (error . show) id -- for pandoc > 1.14
. readMarkdown ropts
fromJSON = writeHtml wopts
-- . either (error . show) id
. readJSON ropts
, ! , transform; pandoc pandoc.