ttrpg-convert-cli icon indicating copy to clipboard operation
ttrpg-convert-cli copied to clipboard

✨ Customize embeddedLink format for images

Open patdski opened this issue 6 months ago • 17 comments

Describe the solution you'd like I would like to be able to generate captions for images in notes. The best solution I've found is a plug-in called Image Captions that uses the alt-text as a caption.

This works for short captions like "Player Map" but not for longer captions like "If you have Advantage, use the 18 If you have Disadvantage, use the 3". The reason seems to be the use of resource.shortTitle in alt-text when resource.title is longer than 50 characters, with resource.title placed after the text as rollover text.

I'm not sure why there is a 50 character limit, because a markdown link like ![If you have Advantage, use the 18 If you have Disadvantage, use the 3](place/holder/image.jpg) works just fine if manually entered in Obsidian. If it causes problems during the conversion process, I can understand that.

Another benefit of allowing customization is that rollover text is currently only available on longer image titles. Otherwise there is no rollover text at all.

Current link output:

Image

Result:

Image

Desired link output:

Image

Result:

Image

patdski avatar Jul 19 '25 01:07 patdski

I found a way to edit the plugin to get my desired result, but it only works with external links. Good enough, and I’d rather the dice roller bug get fixed.

patdski avatar Jul 25 '25 11:07 patdski

Fwiw I think it would be nice for the alt text to contain the full caption if there really is no character limit (at least as far as obsidian is concerned). Unless @ebullient sees an issue with any of this. I see no reason this would be mutually exclusive with the dice roller fix.

jboehm77 avatar Jul 25 '25 20:07 jboehm77

That’s fair. I can reopen it.

I think it would just take a small amount of editing to this file:

src/main/java/dev/ebullient/convert/qute/ImageRef.java

Basically removing the short vs long title distinction. I’m curious why it was implemented. Is there a character limit for alt text elsewhere?

patdski avatar Jul 25 '25 20:07 patdski

There isn't an alt text limit, other than the fact that some of the captions for source images are ... REALLY long. (really really).

ebullient avatar Jul 25 '25 23:07 ebullient

I learned something from messing around with the captions plugin: text in the “title” attribute doesn’t render in HTML with internal image links.

https://github.com/alangrainger/obsidian-image-captions/issues/48#issuecomment-3109805687

patdski avatar Jul 26 '25 01:07 patdski

I think this behavior has changed. Keeping the long text in titles (available with hover) used to work.

A round holy symbol that a...

I could certainly make that first length longer, but Obsidian is no longer preserving the title attribute for internal links.. that is behavior that changed somewhere along the way, and is (IMO) a bug. IIRC, there was also an issue with HTML links for internal images, but I can't remember off the top if that has been repaired.

ebullient avatar Jul 28 '25 00:07 ebullient

FWIW, you already can make these links your own way:

https://www.ebullient.dev/projects/ttrpg-convert-cli/docs/templates/ImageRef.html

{#with resource.fluffImages.get(0)}![{title}]({vaultPath}#token){/with}

ebullient avatar Jul 28 '25 01:07 ebullient

I saw that. But how do I create an edited version of the ImageRef file myself?

(Also sorry about the closing and reopening… again. Stupid fat fingers hit the wrong button.)

patdski avatar Jul 28 '25 01:07 patdski

In the example above, I'm suggesting you skip using the shortTitle entirely in your template.

You could also use the img tag: {#with resource.fluffImages.get(0)}<img src="{vaultPath}#token" title="{title}" />{/with}

ebullient avatar Jul 28 '25 01:07 ebullient

So I know how to make the config file point to custom templates txt files for things like monsters and tables, but how do I get it to point to a custom ImageRef.java file? Would this involve building and running the tool from source? I haven’t played with that yet, but maybe that’s the solution.

patdski avatar Jul 28 '25 03:07 patdski

Given the above, why would you need to customize the ImageRef impl?

ebullient avatar Jul 28 '25 16:07 ebullient

Sorry I’m being dense. Very new to all this. Where are you suggesting that code goes so that it will replace how all images are created that way in the convert process?

I can see calls for images in templates for monsters, races, etc. but what about in the main text of sources? Do I just add that to the note2md.txt file too?

patdski avatar Jul 28 '25 16:07 patdski

I can see calls for images in templates for monsters, races, etc. but what about in the main text of sources? Do I just add that to the note2md.txt file too?

Yes, I believe that's what she's suggesting. I will note, however, that I think doing so for the note2md.txt template won't preserve the original placement of the images within the text for note files. Or it may duplicate the images, as from what I can tell, images in notes are placed within the text resource.

jboehm77 avatar Jul 28 '25 23:07 jboehm77

wait.. Which are you askng for... longer alt text, a functional title hover, or display of the caption? (or are you using CSS already to display the alt text?)

ebullient avatar Aug 01 '25 13:08 ebullient

I believe @patdski's request in this issue is the lengthening of alt text for use as a caption. Displaying any caption assumes one uses a plugin or CSS. Title hover functionality was mentioned as an alternative source for the caption text, but as discussed, there remains a bug preventing its use for internal images.

I think the remaining interest here is about capability to set the alt text in image embeds to use full length titles. It's clear this can be configured in templates for most files. But specifically for note2md.txt, using {#with resource.fluffImages.get(0)}![{title}]({vaultPath}#token){/with} may not place the images where they were originally intended to be, as they normally are placed within resource.text for those files.

jboehm77 avatar Aug 01 '25 13:08 jboehm77

Everything @jboehm77 said in the 1st paragraph is correct. My basic request is to lengthen the alt text.

I've already got a plugin that displays captions from alt text, so no use duplicating that work. Hover text doesn't seem that important to me, especially since it's unavailable for internal images. If the alt text is lengthened, everyone can use an easy community plugin to display full captions if they want to.


As for configuring things in templates:

When I add {#with resource.fluffImages.get(0)}![{title}]({vaultPath}#token){/with} to my note2md.txt template, I get this error on running the CLI:

🛑 ERR| io.quarkus.qute.TemplateException: Rendering error: Property "fluffImages" not found on the base object "dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteNote" in expression {resource.fluffImages.get(0)}

And all of the note files in the output vault contain the following:

%% ERROR: io.quarkus.qute.TemplateException: Rendering error: Property "fluffImages" not found on the base object "dev.ebullient.convert.tools.dnd5e.qute.Tools5eQuteNote" in expression {resource.fluffImages.get(0)} %%

patdski avatar Aug 01 '25 18:08 patdski

Right, I should have probably checked the reference documentation. Tools5eQuteNote doesn't have any type of image attribute at all. So calling one in the note2md.txt template naturally returns an error.

jboehm77 avatar Aug 01 '25 18:08 jboehm77