OliverBalfour / obsidian-pandoc

Pandoc document export plugin for Obsidian (https://obsidian.md)
MIT License
707 stars 59 forks source link

[BUG] Pandoc cannot find image file unless full relative path is used #81

Open wychwitch opened 3 years ago

wychwitch commented 3 years ago

Hello! I was trying to convert one of my files to PDF, I received the following error

Obsidian_H4jAWcObZZ

The thing is, that picture isn't in the root folder, it's in a nested folder called __Assets.

The full path is C:\Users\Username\Documents\[[Obsidian]]\Folks and Tales\Ash In The Snow\PCs\__Assets

If the full relative path (Ash In The Snow/PCs/__Assets/Axiom.png) is specified, then works. The only way to do this in obsidian (that I know of?) is by having multiple files by the same name, which forces obsidian to have a full relative link to that exact file.

Is there any way to work around this issue? I can provide any files or my exact file structure if needed.

luckman212 commented 2 years ago

Came here to report the same issue. Hope it can be solved!

Alkaceq commented 2 years ago

subscribing to this one. when in Obsidain Options, Files and Links, I have defined a subfolder name for images, "attachments" for example, all pictures are in /attachments folder. Obsidian sees them and displays render them correctly. Pandoc plugin cannot see them and complains those binaries do not exist.

ndegroot commented 2 years ago

I had a similar problem on Macos. Hope my solution translates to Windows... I tried to specify the image folder by using the parameter in the plugin settings:

--resource-path='[abs_path_name_containing_spaces]'

but it failed with the (no such file or directory) error. Even when I escaped the spaces. Using the same parameter on commandline with pandoc it did work. The problems seems to be that parameters cannot contain spaces when you specify them in the settings for this plugin. The path to the Obsidianvault when placed in iCloud allways contains at least one space. So removing the spaces in the path is impossible. I discovered a pandoc parameter so worked around it by specifying instead:

--defaults=[path_to_yaml_file_no_spaces]

I put an .pandoc-obs.yaml file (you can use any filename withoud spaces) in my homedir (no spaces in the path there). And the yaml-file contains the parameter in YAML syntax:

resource-path: ["/Users/ncdegroot/Library/Mobile Documents/iCloud~md~obsidian/Documents/Notes/00-Meta/03-Attachments"] That worked. At least after I changed the ![[image_file_name_no_path]] links to the more MD standard !()[image_filename_no_path] to get the image to appear in the generated .docx file. To create .PDF I still need to install some more latex stuff, but thats another story.

Hope its helps!

DawnPaladin commented 2 years ago

Your solution works on Windows, thank you! Here's what we did:

After following these steps, Pandoc was able to export Markdown files into .docx. Only image links that specified a size at the end (image.png|300) wouldn't work; we'll just clean those out manually.

Thanks for your help with this workaround!

mistune commented 2 years ago

While Obsidian is currently not able to copy images from a note, I am currently using this Pandoc plugin to export the images from a note so I am able to publish it on a different platform, in my case Confluence.

A recent extension was added to Pandoc to be able look files relative to the note. To implement this on this plugin I modified line 11286 in main.js file file: inputFile, format: 'markdown', to file: inputFile, format: 'markdown+rebase_relative_paths',. Next, all new links format are set to "Absolute path in vault". This is a very rough workaround. If someone familiar concatenating the links in this plugin to avoid messing with the new links format setting please add it to this plugin. Thanks.

FynnFreyer commented 1 year ago

Adding --from markdown+rebase_relative_paths to the "Extra Pandoc arguments", and setting "Export files from HTML or markdown?" to markdown as (implicitly) suggested by @ZeroCommits, solved it for me!

Gewerd-Strauss commented 1 year ago

I have completely left behind ObsidianPandoc specifically because of this issue, and because it is way beyond my level of knowledge, and I simply don't have the time to learn it for this issue alone.

As an alternative workaround, I am now using ObsidianHTML to compile a standard markdown file from a note. This I then convert to R-Markdown (just changing file type to .rmd), use my own (windows-only) script to convert the image src's created by ObsidianHTML to valid knitr-compatible image-embeds for RMarkdown and optionally auto-knit it to the desired output formats.*

It's an arguably weird workaround, but I can now ditch ObsidianPandoc completely with minimal overhead (exporting to standard md can take a few seconds, running the script can take a few seconds) and have the side-advantage of being able to leverage R in my manuscripts - which I regularly have to do anyways.


*Not completely done with the project yet sadly, a few niceties are left on the list.

danieltomasz commented 1 year ago

I have a latex hack (to be added in yaml) for compiling from various folders, I often using includes for figures and move files, you need to adjust it to your paths accordingly, you can add as many path variations as you want, you could also experiment with relative folders using dots notation

header-includes: |
  \graphicspath{{figures}{chapters/figures}{../figures}{chapters}}
museloki commented 10 months ago

I had a similar problem on Macos. Hope my solution translates to Windows... I tried to specify the image folder by using the parameter in the plugin settings:

--resource-path='[abs_path_name_containing_spaces]'

but it failed with the (no such file or directory) error. Even when I escaped the spaces. Using the same parameter on commandline with pandoc it did work. The problems seems to be that parameters cannot contain spaces when you specify them in the settings for this plugin. The path to the Obsidianvault when placed in iCloud allways contains at least one space. So removing the spaces in the path is impossible. I discovered a pandoc parameter so worked around it by specifying instead:

--defaults=[path_to_yaml_file_no_spaces]

I put an .pandoc-obs.yaml file (you can use any filename withoud spaces) in my homedir (no spaces in the path there). And the yaml-file contains the parameter in YAML syntax:

resource-path: ["/Users/ncdegroot/Library/Mobile Documents/iCloud~md~obsidian/Documents/Notes/00-Meta/03-Attachments"] That worked. At least after I changed the ![[image_file_name_no_path]] links to the more MD standard !()[image_filename_no_path] to get the image to appear in the generated .docx file. To create .PDF I still need to install some more latex stuff, but thats another story.

Hope its helps!

Also MacOS, but these method does not work for me.

Sa1ToBob commented 8 months ago

Works without this yaml too. only convert links to relative pathes. (![[../../../Extra/Attachments/Pasted image 20240228172709.png]]) With the plugin "Link Converter" can help here. oneclick on your file, to set all links to realtive path... perfect.

BahneGork commented 1 month ago

Works without this yaml too. only convert links to relative pathes. (![[../../../Extra/Attachments/Pasted image 20240228172709.png]]) With the plugin "Link Converter" can help here. oneclick on your file, to set all links to realtive path... perfect.

This worked for me, however, it does not pick up the size argument in the link.