You can add images to nvALT notes with standard Markdown syntax (
![alt](image.jpg "title")). If you use images in nvALT, here are three tips to make life easier.
URLs to online images work as long as you’re connected to the net and the image still exists on the server, but both of those requirements can be a pain. Storing local images is handy, but there are some caveats (and workarounds).
Because nvALT’s preview is fed from the editor and not a file, it has no base reference for relative paths. That means you have to enter long (absolute) urls for local images when placing a
!(image.jpg) tag in your note. Here are a few solutions.
Drag and drop
First, in nvALT 2.2b, if you drag an image into the editor it will create an inline
file:// link for you automatically. This is great for one-off images.
Per-file base folders
If you’re using a lot of images in a single note and they’re all located in a certain directory, you can use a little metadata header to set a base url, then just use the filename of the image in the note (without the path or
file:// protocol). To do this, add a line at the very top of the note (no newlines before it, and 1 newline after it):
XHTML Header: <base href="file:///Users/username/path/to/folder">
That will add a
<base> tag to the output, and the line won’t show up in the preview. If you process a full document export of the note using MultiMarkdown, the base tag will persist. That will break the images if you post it online, so you’ll need to adjust it based on the new location (or just remove it). Saving from the preview window will strip it, so it’s not an issue for nvALT export.
All-purpose base folder
Lastly, if you use images across all your notes and you store them in the same folder (or subfolders of a single folder), you can add a permanent base url to your template. Look in
~/Library/Application Support/nvALT for a file called “template.html”1. If that file is edited, it will replace what nvALT uses for the display preview. Add the following right before the
</head> closing tag:
with your base path. If you use subfolders, you just need to include the relative path in your image tags. For example, if I had a base folder of
file:///Users/ttscoff/Dropbox/noteImages, and I had a folder inside of it called
work, I could then use the following in any note:
![a work image](work/picture.jpg)
If the images are all stored in the base folder, just use the image name in the tag.
The nice thing about the last solution is that if you move the image folder or need to relocate your whole notes collection, you can just change the one line in the template and all of your inline images will still be connected. And if you take a note elsewhere, you have a relative image path to make setting up a folder structure for it easy without having to do any search and replace.
if the Support folder wasn’t written to when you installed nvALT, you can find the templates inside the application bundle: /Applications/nvALT.app/Contents/Resources/template.html ↩