jghauser / auto-pandoc.nvim

Use pandoc to convert markdown files according to options from a yaml block
GNU General Public License v3.0
33 stars 1 forks source link

Suggestion: Add support for nested mappings #5

Open inkfin opened 1 week ago

inkfin commented 1 week ago

Hi, thanks for the amazing plugin!

I occasionally need to pass in --variables key=val1 to render my PDF document. However, it seems we don't support nested maps right now.

I am posting the Pandoc documentation about the options here for reference: https://pandoc.org/MANUAL.html#general-writer-options-1.

I saw some other structures that need nested structure support, and I think it would be great to have this.

inkfin commented 6 days ago

After exploring enhancements for handling 'variables' in my script, I found that using Pandoc's default YAML configuration file is most efficient. A snippet like this works well:

# defaults.yaml
template: eisvogel
listings: true
pdf-engine: xelatex
variables:
  CJKmainfont: "HiraginoSans-W4"

I realized attempting to convert command-line arguments into YAML configurations manually introduces complexity due to inconsistent formatting. For example:

--citeproc --lua-filter=count-words.lua --filter=special.lua

versus the YAML equivalent:

filters:
  - citeproc
  - count-words.lua
  - {type: "json", path: "special.lua"}

Given these discrepancies, it's more practical to leverage Pandoc directly for configuration parsing, avoiding the need for extensive, custom conversion logic in our script. This decision prioritizes simplicity and efficiency by embracing native Pandoc features.

In conclusion, I'm documenting this for others who might face similar challenges. The takeaway: for managing diverse Pandoc settings, rely on its built-in YAML support for the most straightforward and reliable approach.

jghauser commented 6 days ago

Thanks for this issue report! This is definitely something that this plugin should support. I'm not sure I'll be implementing this soon, but I'm always happy about PRs :blush:.

inkfin commented 6 days ago

Hi, I've checked the lua code and I think we can do better to parse the yaml format, such as adding some user-friendly hint when the config format is wrong.

Adding all the pandoc config can be challenging, but here I have a bit of code I wrote during my little experiments, I will create a pull request to see if this can be a good start 😉