obsidian-paste-image-rename icon indicating copy to clipboard operation
obsidian-paste-image-rename copied to clipboard

trim dashes from empty variables

Open c33s opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. it is a little bit unhandy that empty variables lead to unnecessary dashes in the filename

{{dirName}}-{{imageNameKey}}-{{fileName}}

leads to --my_file_name.png or my_dir_name--my_file_name if

Describe the solution you'd like i assume that the easiest solution would be to hardcode a trim for dashes at the beginning and the end of the resulting image filename.

Describe alternatives you've considered a more complex but quite nice solution would be to allow to define a pre and suffix in the variable, which are simply omited if the variable is empty

{{dirName:-}}{{__:imageNameKey:__}}{{fileName}}
  • empty dirName -> my_image_name_key__my_file_name.png
  • empty imageNameKey -> my_dir_name-my_file_name.png
  • empty dirName and imageNameKey -> my_file_name.png
  • nothing empty -> my_dir_name-__my_image_name_key__my_file_name.png

Additional context Add any other context or screenshots about the feature request here.

c33s avatar Feb 22 '23 11:02 c33s

Excellent suggestion! When I was working on the template mechanism, I did consider the issue you raised. However, I decided to put it on hold for the time being, as it would have added complexity to the plugin and would have slowed down its completion.

At this point, I believe that it would be more practical to incorporate an existing template library, rather than trying to tweak the poor function I have created. My idea would be to use a library like Handlebars or Mustache, which offer the flexibility to add new syntax or filters to meet our needs. I will delve into this matter more deeply at a later time. Thank you for bringing this up.

reorx avatar Feb 22 '23 18:02 reorx

note to self: probably the best solution is to add support to ejs <% var %> syntax while keep the old {{ var }} syntax working.

reorx avatar Feb 22 '23 18:02 reorx