DCsunset / pandoc-include

A pandoc filter to allow file and header inclusion
MIT License
67 stars 14 forks source link

Support for `sourcepos` extension recursively, to provide sync-preview. #50

Open belonesox opened 7 months ago

belonesox commented 7 months ago

I am working on vscode extension that provide WYSIWYM/Latex-convinienient way to work on complex markdown documentation with inclusions using pandoc-include (with my patch to support it). And with back/forward syncing like that (small demo):

https://github.com/gpoore/codebraid-preview-vscode/assets/1609739/71dd448b-6705-42db-9311-2584c2efd927

The key feature from pandoc core is core sourcepos extension that can add JSON-tags "datapos" to output. The problem is that pandoc-include does "not inherit" filters from main document.

So to support it, I wrote couple of fast LUA filters:

And add supporting PANDOC_SOURCE_FORMAT environment variable, if it exists, that would mean that we use this format for included files, and add special processing to add included filename to sourcepos tags.

First, before we get into PR, I want to discuss whether this approach looks good.

DCsunset commented 7 months ago

I'm not very familiar with the sourcepos extension, but what you are trying to do seems to be passing a few more options to the pandoc command when parsing other files. Is that correct?

belonesox commented 7 months ago

Yes, in short, if you dont want to dive into supporting sourcepos extension:

DCsunset commented 7 months ago

As for passing options, I believe we can make it more general, like supporting template variables {filename} in pandoc-options. We can also add an option to support setting arbitrary env variables.