Method to add WikiText for an external local image file (with the relative path to the image)

I have been thinking about solving a problem that one might argue does not need solving.

It has been on my todo list for months… and I was about to ask if someone had a solution. Then I thought of one… this is my first attempt.

Problem:

Determine a quick method of inserting WikiText reference to a local image file. Currently, as a Windows user, I would use Windows Explorer to get the full path of an image file. Aside: I always ensure all external file references are relative; more specifically, in a subfolder under my TW HTML file. I would then paste that text into TW followed by removing the first part of the path to ensure the path is relative and then add the necessary WikiText needed to show the image.

Solution:

The problem with this solution is I’m not sure it’s much faster. The user still copies the full path of the file to the clipboard (In Explorer, the user holds the SHIFT key while right-mouse clicking on the file and selecting “Copy as path”). Then in TW the user invokes the macro, in my example clicks a button. The macro attempts to get the text from the clipboard, causing the Browser to prompt the user to ACCEPT or BLOCK the request. Upon acceptance, the macro parses the path on the clipboard against the full path found (for the TW solution) in tiddler $:/info/url/pathname

If the path to the HMTL file cannot be parsed out of the clipboard content the macro simply exits. However, if it parses the clipboard content, it appends a specified field with appropriate WikiText.

The macro needs cleaning and some sort of reporting to the user if the clipboard content cannot be parsed (the clipboard could contain almost anything). Currently, there is a message on the console (not exactly ideal).

Also, not ideal use for the text field, as the macro always appends to a specific field.

See example usage:

GetRelativePath

Does this help? Or is there a better way?

2 Likes