ditaa-markdown icon indicating copy to clipboard operation
ditaa-markdown copied to clipboard

Rewrite as pandoc filter?

Open bpj opened this issue 8 years ago • 5 comments

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

/bpj

bpj avatar Apr 04 '16 10:04 bpj

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

nichtich avatar Apr 04 '16 11:04 nichtich

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!

bpj avatar Apr 04 '16 11:04 bpj

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.

nichtich avatar Apr 04 '16 15:04 nichtich

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.

bpj avatar Apr 04 '16 16:04 bpj

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

nichtich avatar Apr 06 '16 08:04 nichtich