nichtich / ditaa-markdown

process ditaa diagrams embedded in pandoc markdown
68 stars 7 forks source link

Rewrite as pandoc filter? #6

Open bpj opened 8 years ago

bpj commented 8 years ago

@nichtich, would you mind me taking a stab at rewriting this as a pandoc filter?

/bpj

nichtich commented 8 years ago

Please do so! See also https://github.com/nichtich/Pandoc-Elements/issues/12 for ideas of improvement (parallel processing).

bpj commented 8 years ago

App::pandoc::preprocess is way to hairy for my taste. In fact I prefer https://metacpan.org/pod/IPC::Run3 to using system directly, having been bitten by too much weirdness in the past. The main advantage of a filter as I see it is that you get a whole code block as a string, write it to a file directly or indirectly, convert and are done. If you moreover do it without any nasty surprises from the shell the happier am I!

nichtich commented 8 years ago

App::pandoc::preprocess can be replaced by filters as well. But there should be a way parallelize execution of external commands such as ditaa. Executed via

pandoc --filter filter.pl < in > out

The script filter.pl would

  1. transform the full AST and collect a list of system calls
  2. execute instances of external commands (ditaa...) in parallel
  3. emit the transformed AST after last execution has ended

This is almost what App::pandoc::preprocess does. Sure we can first have an "easy" solution that directly executes the system calls instead of parallizing them.

bpj commented 8 years ago

The script filter.pl would

transform the full AST and collect a list of system calls
execute instances of external commands (ditaa...) in parallel
emit the transformed AST after last execution has ended

This is almost what App::pandoc::preprocess does. Sure we can first have an "easy" solution that directly executes the system calls instead of parallizing them.

Yes, I see that now. The code is so hairy I have problems following it.

Anyway you can see what I have done here. You will have to install File::Slurper.

BTW there was a test error when installing rdfdot.

nichtich commented 8 years ago

Thanks, this should be included as another example filter in Pandoc::Elements! See my comments at https://gist.github.com/bpj/5454765371a4e3c1a8354fedced1cc6b#gistcomment-1743401