hadynz / obsidian-kindle-plugin

Sync your Kindle notes and highlights directly into your Obsidian vault
MIT License
922 stars 52 forks source link

Default file template incorrectly uses trim command #178

Open z2k-gwp opened 2 years ago

z2k-gwp commented 2 years ago

Describe the bug

The default file template uses "trim" has a block identifier, which is not valid in Nunjucks. It is only a filter. You can see this by attempting to copy the default template directly into the plugin's settings field for customization and it will not accept the default as written. Removing the {% trim %} and {% endtrim%}` allows the default template to be usable.

PS - it sure would be nice to have the default template to just be actual default editable text. Right now, as soon as you make modifications in the plugin settings, it erases the default value - causing users to have to completely reconstruct the template from scratch.

Method of syncing

To Reproduce

  1. Go to plugin settings, type in the default file template and watch it turn red when you type {% trim %}

Expected behaviour

The default template text should not have a trim block.

Screenshots

Metadata

z2k-gwp commented 2 years ago

UPDATE: I notice now that you enabled a trim extension (very handy) for trimming out empty lines. Unfortunately, the validation routine for the file template does not support it, and thus the default template (or any modification that uses the trim and endtrim extensions will be rejected.

PPS - Thanks again for such a marvelous plugin!

lukebarton commented 1 year ago

I also wanted to extend the default template and found I couldn't. I fetched it from source, but as the OP points out, the trim function is not valid according the validation routine.

I've resorted to patching the source code, but this won't survive updates.

hadynz commented 1 year ago

I've just released as of this morning version 1.8 of the plugin. It has a completely redesigned template editor that is meant to make it much easier for you to modify templates:

I've tried recreating the issues you were all experiencing with this version and I am not able to create the errors.

Sure, adding a {% trim %} block on its own will immediately error. However, once you add the closing block statement {% endtrim %} the template is valid and the plugin accepts it.

Give it another try please and let me know if that is not the case.

A video screenshot of the problem would help me a lot get to the bottom of this problem faster.

lukebarton commented 1 year ago

CleanShot 2022-11-10 at 10 12 41 Exactly as we described

hadynz commented 1 year ago

Haha... thanks for confirming.

But... as they say, a picture is worth a thousand words.

I now understand the issue. You are using the custom trim block that is only configured to be used on the file template and NOT the highlights template.

The easiest solution is to expose this in the highlight template.

I do need to think about this. I am actually not a big fan that all users are exposed to this trim block that I never intended to be used by users. It is non-standard and it is hard for future users to get their head around it. I am wondering if its possible that the plugin auto-truncates all empty lines by default.

lukebarton commented 1 year ago

If it makes your life any easier -- I don't actually need to the trim function in highlights. But it wasn't working in the main template before your latest update -- I took the original template and pasted it into the box and it wouldn't accept the {% trim %}{% endtrim %} tags, but it doesn't seem to be an issue since your latest update.

PS: Thank you for your excellent plugin