Support multiple YAML items without knowing how many #415
Replies: 6 comments 9 replies
-
Hi! Thank you for your suggestion! 🙂
True, this is the current situation.
I'd probably create a new variable for this: Further questions to solveKey-value pairsWhat if the list contains also keys in addition to values? I'll use your YAML list in a bit different format: extra-pandoc-arguments:
template: foo
lua-filter: script.lua
toc: ~ # ~ denotes a null value, which could be interpreted as an empty string with no separator between the key and the empty value, i.e. no = after "toc". We could have a few arguments for the
A complete example for your casepandoc --from markdown --to pdf source.md -o destination.pdf {{yaml_values:extra-pandoc-arguments: :--$item_key=$item_value:--$item_key}} (Note that the last argument YAML: extra-pandoc-arguments:
template: foo
lua-filter: script.lua
toc: ~ # ~ denotes a null value, which could be interpreted as an empty string with no separator between the key and the empty value, i.e. no = after "toc". Result: pandoc --from markdown --to pdf source.md -o destination.pdf --template=foor --lua-filter=script.lua --toc However, see Escaping special characters below for a problem that needs to be solved. Nested listsHow to handle e.g. this? extra-pandoc-arguments:
template: foo
lua-filter: script.lua
my-nested-list:
nested1: example1
nested2:
deeply-nested: example2 I think the first development step could be this: If any of the list items is another list, show an error message telling that nested lists are not currently supported. Later, there could be some way to virtually "flatten" the list: extra-pandoc-arguments:
template: foo
lua-filter: script.lua
nested1: example1 (extra placeholders `$parent_key` = `my-nested-list`, `$parent_keys` = `my-nested-list` `$count_parents` = `1`)
deeply-nested: example2 (extra placeholders `$parent_key` = `nested2`, `$parent_keys` = `my-nested-list.nested2` `$count_parents` = `2`) Escaping special charactersAll values coming from pandoc --from markdown --to pdf source.md -o destination.pdf \-\-template\=foor\ \-\-lua\-filter\=script\.lua\ \-\-toc This would not be a desired outcome for this case. In this particular case, you could precede the variable name with an exclamation mark But I'd like to think about a solution for doing partial escaping, i.e. being able to choose which parts should be escaped and which not:
A different approach: Maybe use method syntax for this?I have some ideas to implement a method syntax for variables. Shortly, methods would be "postfixes" that denote additional processing for variables. The syntax might be In this particular case, there could be a method named
There could also be another method: |
Beta Was this translation helpful? Give feedback.
-
A few thoughts:
In my PR, I took a very simple, possibly too simple, approach. Just look at the referenced item, ie. I think this approach is pretty ok, and I have been using it myself, on my fork, however I do think it can be improved in the following ways:
|
Beta Was this translation helpful? Give feedback.
-
I forgot to respond to your suggestion about key value represented arguments, ie: extra-pandoc-arguments:
template: foo
lua-filter: script.lua
toc: ~ # ~ denotes a null value, which could be interpreted as an empty string with no separator between the key and the empty value, i.e. no = after "toc". Indeed, this would be nicer, but not, I think, strictly needed for functionality. Obsidian already auto-suggests similar yaml keys, making entry speedy in case it's not the first time I use it anywhere, and the beauty of the yaml is not something I personally care much about. If it is something that you want to support, then your suggested example:
seems as good of a way as any. |
Beta Was this translation helpful? Give feedback.
-
First step:
|
Beta Was this translation helpful? Give feedback.
-
Well, I haven't tried to break it yet, but I installed the update, and my existing scripts that relied on my customized version still worked as per usual, so thats a good sign! |
Beta Was this translation helpful? Give feedback.
-
Ok, so I first had an opportunity to use this modification the way it was intended, and I can confirm that it was nice and easy, and overall a very nice experience. I really like how your version of my mod is much more general and extensible, and while I haven't had a reason to use its more advanced capabilities, I think I probably will. The only small thing I can think of to report is that, when I first started configuring the shell command, I didn't realize that it would not work unless I added a separator. I think that adding a default separator--for example, an implied |
Beta Was this translation helpful? Give feedback.
-
Thanks for the awesome plugin. I'm using this to create custom and flexible export commands with pandoc. Pandoc has some flags that can be repeated, and just generally can require a lot of arguments to get it to do what you want. I'd love to be able to create a YAML tag like:
and then be able to glob them all into a shell command like:
And then have those arguments get expanded with a space separator. as it is, I would need to access them like
{{yaml_value:additional-pandoc-arguments.0}}
and{{yaml_value:additional-pandoc-arguments.1}}
etc, but that means I have to know ahead of time how many there are - which I dont.Another possibility would be to create a new thing like
{{yaml_value:additional-pandoc-arguments:all}}
or something for listsBeta Was this translation helpful? Give feedback.
All reactions