How to use Python filter with Pandoc to convert md with tikz to html on Windows 8.1

微笑、不失礼 提交于 2019-12-05 04:00:50

The -t option is used followed by a format not a file with the extension for example pandoc -f json -t markdown will output that markdown, -t html will output html etcetera to capture the output use a redirection operator operation > file.some_extension. But your output is going to the console. So the correct syntax is literally pandoc -f json -t markdown.

Also the pandoc documentation. If you run into problems try to modify your lune from:pandoc -o temp.html --filter .\tikz.bat -s temp.md ==> pandoc -t json | ./caps.py latex | pandoc -f json -t html.

This is how it works.

                 source format = input_file.html
                      ↓
                   (pandoc) = pandoc -t json input_file.html
                      ↓
              JSON-formatted AST 
                      ↓
                   (filter)    = python $HOME/Downloads/pandocfilters-1.2.4/examples/caps.py
                      ↓
              JSON-formatted AST
                      ↓
                   (pandoc)    =  pandoc -f json -t markdown
                      ↓
                target format = output_file.md

Separate the commands to examine output and use a pipe | to redirect output:

 pandoc -t json ~/testing/testing.html | python examples/caps.py | pandoc -f json -t markdown > output_file.md

No need to install pandocfilters download the tar file, run tar -xvf file.x.y.z or use any other application of choice and refer to the examples calling python dir/to/script.py then pipe the out put to pandoc again and redireect output to desired file format. Here is line by line:

 $pandoc -t json ~/testing/testing.html
[{"unMeta":{"viewport":{"t":"MetaInlines","c":[{"t":"Str","c":"width=device-width,"},{"t":"Space","c":[]},{"t":"Str","c":"initial-scale=1"}]},"title":{"t":"MetaInlines","c":[]},"description":{"t":"MetaInlines","c":[]}}},[{"t":"Para","c":[{"t":"Str","c":"Hello"},{"t":"Space","c":[]},{"t":"Str","c":"world!"},{"t":"Space","c":[]},{"t":"Str","c":"This"},{"t":"Space","c":[]},{"t":"Str","c":"is"},{"t":"Space","c":[]},{"t":"Str","c":"HTML5"},{"t":"Space","c":[]},{"t":"Str","c":"Boilerplate."}]},{"t":"Para","c":[{"t":"Str","c":"l"}]}]]

then:

$pandoc -t json ~/testing/testing.html | python examples/caps.py 
[{"unMeta": {"description": {"c": [], "t": "MetaInlines"}, "viewport": {"c": [{"c": "WIDTH=DEVICE-WIDTH,", "t": "Str"}, {"c": [], "t": "Space"}, {"c": "INITIAL-SCALE=1", "t": "Str"}], "t": "MetaInlines"}, "title": {"c": [], "t": "MetaInlines"}}}, [{"c": [{"c": "HELLO", "t": "Str"}, {"c": [], "t": "Space"}, {"c": "WORLD!", "t": "Str"}, {"c": [], "t": "Space"}, {"c": "THIS", "t": "Str"}, {"c": [], "t": "Space"}, {"c": "IS", "t": "Str"}, {"c": [], "t": "Space"}, {"c": "HTML5", "t": "Str"}, {"c": [], "t": "Space"}, {"c": "BOILERPLATE.", "t": "Str"}], "t": "Para"}, {"c": [{"c": "L", "t": "Str"}], "t": "Para"}]]

finally:

pandoc -t json ~/testing/testing.html | python examples/caps.py | pandoc -f json -t markdown
HELLO WORLD! THIS IS HTML5 BOILERPLATE.

notes:

diff -y pandoc_json.txt caps_json.txt
[{"unMeta":{"viewport":{"t":"MetaInlines","c":[{"t":"Str","c" / [{"unMeta": {"description": {"c": [], "t": "MetaInlines"}, "v
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!