Skip to content

Conversation

@Spydarlee
Copy link
Contributor

I noticed when using the option to automatically download remote images that Obsidian was complaining about invalid frontmatter. Currently the output I get looks like this:

image: 
  - - Attachments/Covers/game_Barbie Sparkling Ice Show (2002).jpg
image

Which is still readable by the new 'bases' core plugin, for instance, but by wrapping the output in quotation marks, Obsidian treats the local reference correctly as a string / local link:

image: "[[Attachments/Covers/game_Barbie Sparkling Ice Show (2002).jpg]]"
image

I'm not entirely sure why the output is being treated as (malformed?) list, so perhaps there is a better way to fix this?

@mProjectsCode mProjectsCode merged commit 0ddf266 into mProjectsCode:master Aug 30, 2025
@ltctceplrm
Copy link
Contributor

I think this latest change actually breaks the formatting for downloaded images, it's now listing images as image: '"[[Attachments/Covers/game_Barbie Sparkling Ice Show (2002).jpg]]"', see this YAML:
image

Which does not result in a link when viewing it in preview mode:
image

If we remove the extra single quotes then it appears correctly in the preview mode:
image

I'm not sure why you had the original issue but I believe it may have been a problem on your device and not a universal one, most likely image was listed as an array somewhere in your vault?

The previous code already included the double quotes but now it has a combination of double and single quotes which breaks the formatting.

I've tested this with a fresh vault

@Spydarlee
Copy link
Contributor Author

Damn, you're right @ltctceplrm - my apologies!

I dug a little deeper and found the root cause of my issue. I was testing in a vault with custom templates and the Use default front matter setting set to false, so I was bringing in the image with image: {{ image }} which initially resolves to something like image: [[Media DB/images/media_name.jpg]] (no quotes) for downloaded files.

Without quotes, when the template is processed by getMetaDataFromFileContent it goes through Obsidian's parseYaml which sees the square brackets and treats them as an array instead of a string, hence my initial issue. But in the default frontmatter case it's treated as a string already, hence the double quoting you noticed.

Intuitively, I think I would expect {{ image }} in a custom template to return a quoted value by default so that it "works out of the box", so to speak, in which case we could potentially handle this in the code with something like:

// Update model to use local image path
if (this.settings.useDefaultFrontMatter) {
    mediaTypeModel.image = `[[${imagePath}]]`;
} else {
    mediaTypeModel.image = `"[[${imagePath}]]"`;
}

But perhaps it would be best to simply rollback my change entirely and let the end user handle this by wrapping their custom frontmatter in quotes image: "{{ image }}" which works fine, too. Do you have a preference, @mProjectsCode?

@mProjectsCode
Copy link
Owner

Yeah, I will revert this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants