I had someone reach out to me to ask if it was possible to use the image flags with other plugins that use the same “alt” section such as the image caption plugin.
The short answer is: “not with css”
The long answer is: The image flags will play nice with the plugins since it is looking specifically for the flags. The plugin, however, will display the flags as part of the caption. To change this, you would need to change the plugin code to filter out the flags.
Here are two ways of doing this with the image-caption plugin specifically. I couldn’t find any forum posts for that specific plugin which is why I’m posting here.
First way:
This will take whatever is used before the first “+” used in the alt text. If a caption has a “+” in it, then whatever comes after it will get cut off.
This would be the easiest way to do it without having to conver things since you probably have the captions already in front of your image flags.
To enable this, navigate to the main.js file of the image caption plugin then replace the following code (should be around line 58):
const caption_text = mutation.target.getAttribute("alt");
With this:
const alt = mutation.target.getAttribute("alt");
const caption_text = alt.split("+", 1);
Save the main.js file then reload obsidian. Note: if you update the mod, the custom changes will be overwritten.
Second way
The second way is to use a flag for captions at the end. This will look for a specific call of “-cap” followed by a space. Anything that comes after that is your caption. That includes flags so put the -cap call at the end.
To do this, replace the same original text as the previous method, but use this code instead:
const alt = mutation.target.getAttribute("alt");
const pattern = new RegExp('\-[cC][aA][pP]\s');
const alt_array = alt.split(pattern);
const caption_text = alt_array[1];
Note: you can modify the flag you use by editing the RegEx variable which is currently set to \-[cC][aA][pP]\s.