OliverBalfour / obsidian-pandoc

Pandoc document export plugin for Obsidian (https://obsidian.md)
MIT License
719 stars 60 forks source link

Extra Pandoc Arguments do not recognise " or ' and mess up with directory paths and export fails. #136

Open vasilisniaouris opened 2 years ago

vasilisniaouris commented 2 years ago

Hello! First off I would like to thank you for this plugin, it has been of great use to me and so many others.

In the plugin settings, when you type Extra Pandoc Arguments, the conversion between the string and the actual command (line ~310 in the main.js file) is faulty. The " and ' are not applied properly, and the spaces essentially separate a single command in two.

I will give an example from your examples. Let's say we typed --bibliography "Zotero Exports\My Library.json". This would run --bibliography "Zotero which does not exist, and the export will fail.

I found a work around for myself, and since I do not know any Java Script, I do think there are better ways of doing this. Specifically, I changed:

if (extraParams) {
    extraParams = extraParams.flatMap(x => x.split(' ')).filter(x => x.length);
    args.push(...extraParams);
}

to:

if (extraParams) {
    for (let i = 0; i < extraParams.length; i++) {
        let extraParam = extraParams[i].split('=');
        args.push(extraParam[0], extraParam[1]);
              }
}

This way you can only add arguments as --template=letter.tex (so the = is mandatory) and separate them by new lines, not spaces. Now you do not have a problem with --bibliography=Zotero Exports\My Library.json, meaning that even in a weird format, you get the full functionality of the argument settings.

I am hoping that with this issue report, we will eventually find a better work around on the main topic of " and '.

P.S. For extra ease, when calling pandoc, instead of passing the extra arguments as (line ~ 11280) this.settings.extraArguments.split('\n'), I pass them as this.settings.extraArguments.replace('$VAULT_PATH$', this.vaultBasePath()).split('\n'), allowing me to use the vault path, without writing it out. It would be a cool feature to add to later releases. This way I can define a new --data-dir=$VAULT_PATH\.pandoc for pandoc, which will be saved in the local vault folder and better reflects Obsidian's mentality of having everything local and in the same folder. I am sorry for getting slightly off topic with this.

luoxiaobatman commented 2 years ago

same issue here. Arguments parser doesn't respect " or '.

kitchokly commented 2 years ago

I'm having the same issue. Would love to see this fixed. Thanks for the workaround in the meanwhile!