How to export images to MMD with full paths?

Hello all, I have a workflow of exporting my Scrivener document to an md file, and then converting that to Word so that Scrivener can play nicely with Zotero. On the whole I’m very happy with it, but there is one thing that I’ve been hoping to fix for quite a while. I write with images, and every time I compile the text, the images get exported with relative paths, like so:

[ScreenShot2023-01-29at91309AM]: ScreenShot2023-01-29at91309AM.png

However, in order for the image to show up in Word, I find that I need to change this to the full path of the file, i.e.

[ScreenShot2023-01-29at91309AM]: /Users/MyName/Desktop/Scriv compiles/Document

Is there any way to get Scrivener to export the full path to image files, rather than the relative path? I would be grateful for any help here!

Could you describe your workflow, beyond Markdown and into Microsoft Word, in a little more detail? I presume you are using Pandoc to get there, but that has me a bit confused since the address to the image in the .md file only matters to the conversion engine up to the point of it embedding the graphic into the .docx container format. Word would have no clue what the original address was, nor would it need to, because the image is inside the .docx.

Perhaps you are using a flag or extension I am not aware of, though, or another conversion engine entirely.

Otherwise there is no setting for this, but one is of course free to source their images somewhere on the disk and refer to them by absolute paths in Scrivener, rather than having Scrivener generate the images into a folder every time and create the image reference. Some who use such methods do still prefer the convenience of having a thumbnail in the editor, and it is a simple matter to “comment it out” with an inline annotation.

Another approach would be to use the Processing pane (§24.21, Processing, in the user manual PDF) to invoke sed, or whatever scripting tool you prefer to add the path to lines that resemble image reference lines. A script may also be able to automate where the compile path is, so that the adjustment isn’t static text you have to change for every project.

1 Like

Thank you so much for this helpful reply. I would be glad to explain my workflow in more detail. First I export to md (“Use Pandoc syntax” checked under Processing, no post-processing). To convert the file to word, I use an Automator app to run Pandoc that I put together following the guide here. That code is as follows:

title=$(basename "$@" .md)
/usr/local/bin/pandoc -s --lua-filter=zotero.lua --reference-doc /Users/MyName/.pandoc/reference_new.docx -f markdown+smart -t docx -o /Users/MyName/Desktop/"$title".docx "$@"
open /Users/MyName/Desktop/"$title".docx

It’s pretty important to me to have the images present while I am writing, so if I did decide to link to an absolute path in the text, I would still want to include the image there. I have a fairly high tolerance for wonkiness, but that doesn’t sound so ideal to me; it was always my hunch that the best solution would be to use the Processing pane to add a script of some sort. I don’t have a lot of programming skill but can at least try to root around online, and even knowing to look into sed is a help. Thanks.

I don’t know if this is relevant at all, but I’ll note it here anyway. When I went to poke around the files a bit more, I noticed that a lot of the images have scaling attributes, i.e. they look like this:

[phone-detail]: phone-detail.png {width=522 height=419}

Just to be clear, that is how the image appears at the very end of the document. It is called in the document with


In any case, when I open up the md file in an editor, none of my images with scaling attributes appear there. If I go and manually remove the scaling attributes, then they appear in the md editor. Again, no idea if this means anything. It certainly doesn’t matter to the word conversion, as long as the image is given with an absolute path.

1 Like

No edit feature, so just adding this here for reference in case it’s helpful to people down the road, but this stackoverflow post looks promising…

(You should be able to edit your recent posts now, I bumped your forum level up to “known human”. :slight_smile: Bots like to post one thing that sounds vagualy plausible and then edit spam into the post a week or two later, hence the automatic restriction on new accounts.)

So yes, with a little alteration you could throw all of what you’re doing with Automator into the Processing pane and just have that execute as part of clicking the Compile button. There is little reason not to do that (unless your .md files tend to come from multiple sources, not just Scrivener), as there are flags for keeping the source files around in case you tend to make modifications between compile and final output, or just want to skip the whole re-compile phase (the slowest part) to fix typos you spot. But with the removal flags enabled the output is very clean: you get only the .docx file.

The main tweak you would want to make is to how the output name and input .md file are referred to. I’ve attached a simple little demonstration of how that can be done.

Pandoc (DOCX).scrformat (22.6 KB)

Drop the .scrformat file into your project’s compile Format sidebar to import it, double-click to edit, and then in the Processing pane, click the edit button to examine the script. It’s just your basic Bash stuff here, using $1 and $2 as taken from the arguments we provide in the text field below the scripting area.

That should also solve your image path problem as well, as Scrivener will be running your script from the output location, where the images will also be.

I suspect that if you were to break your process down into manually run steps, doing things exactly as Automator would, that when you run the Pandoc script you’ll be getting a bunch of errors about missing images. That’s because it is where Pandoc runs from that matters, not where the .md file is located relative to the resources. Kind of weird if you aren’t expecting it (though it is fairly normal for shell commands), but it does allow for some interesting use-cases, like running Pandoc from different resource folders to build different documents (maybe B&W for laser print, small-res for online distribution, high-res calibrated CMYK for print, etc.).

In any case, when I open up the md file in an editor, none of my images with scaling attributes appear there. If I go and manually remove the scaling attributes, then they appear in the md editor.

Your Markdown editor may not be capable of parsing Pandoc syntax, but you should check the options to see if it has a switch somewhere for that. At any rate it appears to be unrelated since they start working once you remove the Pandoc-specific scaling information.


Haha, love to be recognized as a human! :cowboy_hat_face:

And, wow! Yes, this has absolutely done the trick. Thank you so much, you are a wizard! You have saved me so much time and effort, plus stress to boot – thinking about when I should be manually adding in the filepaths, etc. This is really fantastic. Now, can you write the last two chapters of my dissertation? :sweat_smile:

I really appreciate this explanation, it makes sense to me why things weren’t working before – yes, I definitely had no idea that pandoc could be run from different locations. Sending you all the best!!