haskell - How to use Pandoc filter within Hakyll? -
i sorry ask such question. new haskell. searched internet whole day didn't find example.
i have pandoc filter written in python (tikzcd.py
). want use filter process blog posts.
i guess need use unixfilter
or pandoccompilewithtransform
knowledge haskell not enough find solution myself.
so, provide me example?
-----------u--p--d--a--t--e--s---------------
@michael gives solution using pandoccompilewithtransformm
, unixfilter
. works. there problem.
when using filter command line,
pandoc -t json -readeroptions input.markdown | ./filter.py | pandoc -f json -writeroptions -o output.html
or equivalentlypandoc --filter ./filter.py -readeroptions -writeroptions -o html
this command shorter doesn't show procedures.
but pandoccompilertransformm
, like
pandoc -t html -readeroptions -writeroptions input.mardown | pandoc -t json | ./filter.py | pandoc -f json -writeroptions -o output.html
the difference text passed filter.py
different: 1 contents directly produced markdown, while other texts produced html produced markdown. know, convert , forth produce unexpected problem. think there may better solution.
ps. i've stared learn haskell. hope solve problem myself someday. thank you!
in end think use both. using https://github.com/listx/listx_blog/blob/master/blog.hs model, following have same shape transformer
has in it. transformer
used on lines 69-80 'posts' -- third argument pandoccompilerwithtransformm
, (pandoc -> compiler pandoc)
here need add absolute path python filter -- or name if it's in $path -- , reader , writer options (e.g. 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 = let input_json = writejson writer_opts pandoc output_json <- unixfilter script [] input_json return $ -- either (error.show) id $ -- line needs uncommented atm. readjson reader_opts output_json
similarly, (transformer "/usr/local/bin/myfilter.py" defaulthakyllreaderoptions defaulthakyllwriteroptions)
might used (return . pandoctransform)
used, on line 125 of example gist
for debugging might outsource unixfilter
:
transform :: script -> string -> compiler string transform script md = json0 <- unixfilter pandoc input_args md json1 <- unixfilter script [] json0 unixfilter pandoc output_args json1 pandoc = "pandoc" input_args = words "-f markdown -t json" -- add others output_args = words "-f json -t html" -- add others
the 3 lines of do
block equivalent of stages of unix piping in pandoc -t json | filter.py | pandoc -f json
whatever additional arguments.
i think maybe right there layer of pandoc , forth here. pandoccompilerwithtransform(m)
functions direct pandoc-> pandoc function - applied pandoc hakyll comes with. think should dispense , use pandoc libraries directly. use of unixcompile
might this.
transformxlvi :: script -> readeroptions -> writeroptions -> string -> compiler html transformxlvi script ropts wopts = fmap fromjson . unixfilter script [] . tojson tojson = writejson wopts -- . either (error . show) id -- pandoc > 1.14 . readmarkdown ropts fromjson = writehtml wopts -- . either (error . show) id . readjson ropts
i hope principles emerging these variations! should pretty same preceding transform
; using pandoc library in place of calls pandoc
executable.
Comments
Post a Comment