View on GitHub

scriv-git-pages

Writing in Scrivener for GitHub Pages

Prev, Top, Next Top Image References Alternative

Image References Fail

In all the excitement, I didn’t mention above that there was a problem with my references to images. I fixed them up by hand in the previous release. The problem is this:

When you put an image into a Scrivener document, you just drag it in, and there it goes. It compiles correct MultiMarkdown for it automatically, as part of the MMD compilation features. If you’ve dragged in image_file_name.png, for example, it compiles:

\![][image_file_name]

right in place, and then at the very end of the compile, it compiles in the reference definitions, in this case:

\[Image_file_name]: image_file_name.png

Now, I’d have preferred it to compile the image into one line:

\![](image_file_name.png)

Anyway, it doesn’t. I’ve asked if there’s a way to set it to compile that way, or at least put the reference line right near the image line but I’m expecting no joy on that. And had I read AmberV’s solution, referenced above in Splitting, more carefully, I’d have seen how it was handled there. I’ll edit in a link to the writeup on the Scrivener forum in that chapter, in case you want more information.

Note: That will perhaps be the first external reference I’ve put into this booklet, and it may suffer from the same fate as images, or some other fate. We’ll see. If so, another learning experience and another section for the booklet.

We’ll do a version of Amber’s solution, but more consistent with the somewhat simpler approach in my Ruby program. Right now, it just assigns the file names numerically, except that the first file is named index.md rather than 00.md, to make a home page for GitHub Pages. Because I’m using the default separator line, —— and because Scrivener just dumps the references at the end without a separator, I’ll have to either go to using a file “suffix”, or use some other hack to make sure I can identify the final file.

Then, we’ll copy AmberV’s trick, which is just to append that file to each of the others, so that each one knows all the references. That’s redundant, but harmless: the translator doesn’t use any references it doesn’t need. (Or so we are led to believe.)

AmberV’s solution includes a file name in each separator, and there is a special one hammer’d in at the end of the file. There’s a document suffix you can supply, in this option in the compile format:

AmberV uses a hand-crafted version of the standard separator. We could just put in our simpler one, and then use that file separately on the basis of it being last. The script keeps all the files open until the end, saving them in a dictionary, then when the references finally show up, loops over all the other files and appends the references to the end of each one and closes it. Perfectly reasonable solution.

I’m not sure what approach I’ll take just now. I’ll work on that over the next few sessions. With any luck it should only take one session. Maybe tomorrow.

A small issue is that I really don’t want to publish a version until the images are fixed. It’s a bit of a pain fixing them by hand. Well, let’s say that I’ll publish tomorrow, one way or the other. Agreed? Thanks.

Prev, Top, Next Top Image References Alternative