Hey Brett — Is the above still the best way to handle pre-processing wikilink formatting? I'm having trouble getting it to work. Should I have the code above in a .rb file? I've got that dropped into my documents folder. Do I need to include an argument? Permissions are enabled. Not sure what I'm missing. Any help is much appreciated.
Brett on 21 May, 2021 04:43 PM
@theredhype Yes, it needs to go in a .rb file, and you need to make it executable by running chmod a+x path/to/file on the script. In Preferences->Advanced you need to make sure you have the full path to the script. Assuming all of that is in place, check the Custom Processor logs under the Help menu and see if you're getting any errors.
I've now made the file executable, and confirmed by running ls -l which returns -rwxr-xr-x as expected.
In the advanced preference of Marked 2, I'm using the path selector to select the .rb file as my pre-processor (assuming that satisfies ensuring the path is perfect and full). I get a little green OK next to the file. I'm leaving the args field blank. updating permissions. refreshing. But no change.
I've turned Debug mode on for all, and opened the log file. However, while fiddling with all the settings I'm unable to get the log to show anything at all in either processor or pre, stdout or stderr. All remains blank.
Brett on 21 May, 2021 05:26 PM
Do you have the pre-processor turned on in the preview window? At the
bottom right side of the window there should be a yellow "light" if the
preprocessor is enabled. (If "Automatically enable for new windows" is
checked, this should be on by default when you open the preview).
If it's definitely running and you're still getting no log messages, try
adding an `echo "TESTING"` line to the script and see if it shows up in
the log. At least that would indicate it's running. The log will only
update after a refresh, so be sure to hit ⌘R when testing.
You caught me! I did not have it enabled. It is now enabled. Checkmarked. And yellow lit. I had checked "Automatically enable for new windows, but it's possible I had not closed and re-opened a new window. I did not realize I needed to turn it on.
Still not quite there though. I'm getting the following error:
ERROR: Custom processor is not executable
Please ensure that your user has permission to execute markedwikilinks.rb
Due to sandboxing restrictions, some binaries are not accessible from the Mac App Store version of Marked 2. To crossgrade to the (non-sandboxed) Paddle version of Marked for free, use Help->Crossgrade.
Also, Marked 2 has started crashing now, as it tries to preprocess I suppose. I've saved the crash report, in case that becomes helpful.
I checked my file permissions again, and they appear correct... I think. (ref. screenshot)
`-rwxr-xr-x@ 1 mrno staff 219 May 21 09:14 markedwikilinks.rb
I've got this file in my documents folder, and have refreshed permissions, and also accepted the system dialogue about accessing files which pops up. A peek at the system prefs seems to confirm access. (ref. screenshot).
Thanks for confirming.
Crossgrading has solved the issue.
Thanks for the alternative notes. If there's no other practical difference in functionality, the crossgraindg solution works great for me. I'm assuming the versions released through each channel are essentially the same.
Brett on 21 May, 2021 09:41 PM
Yep, the only difference between versions is the sandboxing, which means
the direct version is actually slightly more capable than the MAS
As far as previewing links within Marked, if you change the links to
just be file:// urls to markdown files, you can open them in the current
window or a new window, you should get an option. Marked doesn't have a
back button, though, so opening in the same window is a one-way street.
You can also make them `x-marked://open/?file=...` links to force them
to open new windows.
I may be making this harder than it needs to be. But I'm trying to keep my markdown simple with double brackets around file names. And then use the preprocessing script to render the docs linkable, so I can click around between them. Kind of like a choose your own adventure
I've got that working nicely by using a hard path to the folder I'm in, like this:
Brett on 22 May, 2021 04:31 PM
Ok, let me revise my suggestion. You don't need the file:// part for a Markdown link, it will work to just point it to the filename and it will assume it's in the same directory as the current file. I did realize that for this to work you need to use URI.encode rather than CGI.escape (URI will use percent encoding, CGI adds plus signs for spaces which won't work as links). I also added a little regex to add .md if it's not already there, which you might need to adjust if your default file extension isn't .md.
# encoding: utf-8
input = STDIN.read.force_encoding('utf-8')
puts input.gsub(/\[\[(.*?)\]\]/) do |m|
match = Regexp.last_match
Happy to report file names with spaces are working well! Thanks for noticing that.
Wikilinks are still visually pretty in the Marked 2 preview, but they're not linking to the files. When I hover over the links in Marked 2, I see the notification "Missing File: Hypothesis.md" pop up at the bottom, and clicking on a link does nothing.
If I add the file:///Users/user/Documents/folder/ path back in everything works perfectly. But of course, that will only work for the hard-coded folder of documents, rather than being relative to whichever folder I'm working in.
Is there something else that needs to be there in place of the file:// ? I can't seem to get Marked 2 to see the files in the folder without including the full file path.
Note: In my .rb file, I did swap out the do and end from the above code block for brackets, otherwise Marked 2 was simply displaying <Enumerator:0x00007fa233094ea8>
Brett on 23 May, 2021 07:36 PM
What OS version are you on? The version of the script above was tested
and working fine on Big Sur with the bundled Ruby. Bracket syntax and
do/end are just two variations of the same block syntax, there shouldn't
be any operational difference between the two.
But anyway, since that's working now, right click on a link showing
Missing File and choose Inspect. Tell me what the actual URL it shows in
the link markup is. As long as it doesn't have any prefix and is just
the filename, it should work. The only thing I can think to double check
is that the actual file has the same `.md` extension the link is looking
Yes, it's in the same folder and named precisely the same.
Brett! I think I've found a big clue to the mystery.
I've been pointing Marked 2 at a parent folder — it's watching a folder called nvUltra, inside of which I have a dozen project based folders.
When I tell Marked 2 to watch the lower level project folders, the relative paths created by the preprocessing .rb file all work perfectly as expected. I'm able to click back and forth between them without problems. No missing files, etc. I have tested this with several of my project folders and the interlinking wiki links all work great!
Then, when I switch Marked 2 back to watching the parent, those files go missing.
Ideally, I'd be able to leave Marked 2 pointed at the parent, so that as I move between projects (which I'm experiencing as tabs in nvUltra), it just automatically switches with me.
But I'm guessing, if I've found the issue, this is something I can't fix on my end.
Brett on 25 May, 2021 10:16 AM
Yep, in a folder preview Marked treats all paths as if they were in the
base folder, so it's not looking in subfolders for relative paths. I
should probably change that, but I actually forgot that Marked could
even read subfolders in folder view mode.
I think that the MARKED_ORIGIN environment variable should be correct,
though, so it would be simple to adjust the preprocessor to include an
absolute (or more correct relative) path. Will have to test, though.
Brett on 25 May, 2021 11:23 AM
Yep, environment variable works. The following gets the full path to the folder of the file containing the link and applies it to the substitution. If you export a file using this, the paths won't be relative and will likely break when viewed anywhere else, but it will work for previewing.
This error only appears AFTER I have clicked on a wiki link in the Marked 2 preview. Never before that. If I don't click on a wiki link in Marked 2, I can continue editing any doc in any sub-directory and Marked 2 updates perfectly.
This error also appears even when I've pointed Marked 2 directly at the lowest level documents folders (and again, only after I've clicked a wiki link in Marked 2).
Brett on 25 May, 2021 09:30 PM
I think that's a bug on my end. When a preview that's watching a folder follows a link to a single file, it's now no longer a folder watcher (but it thinks it is). So when it detects a directory change and tries to load the most recent file, the folder it looks in is actually now a single file. Marked really wasn't designed to be a wiki navigator like this, so it might be a case where you're better off opening wiki links in new preview windows and leaving the folder preview as is.
Ah, yes. Fascinating. I can add a link which lets me return in Marked to watching the top level documents directory, but I'd have to add it to every doc, and always remember to click it in Marked after clicking wiki links, and before working in the text editor again. Ha!
I tried this with [Parent](file:///Users/User/Dropbox/nvUltra) which leads back to a top level folder I'm watching, and it appears to tell Marked to watch at that level again. I didn't get this to work with a relative path, but that wouldn't really matter for me, since all my work is ultimately in one parent folder; hard coding that path here is fine.
Not sure whether I'd add this to my workflow. But it's an interesting workaround.
Brett on 25 May, 2021 11:28 PM
Just a thought, but it would be entirely possible to have the custom processor embed that link in the output, perhaps just appending it at the end. Wouldn’t be able to dynamically determine what the top level you wanted was, but even if it were hardcoded, at least you wouldn’t have to edit into all your notes.
Is there an easy way to modify the script posted in the first reply by @Brett to make it work generically, beyond just Nvalt? Specifically I’m interested in making it work with the [[wiki links]] I use in the applocations DEVONthink and Notebooks.
Brett on 27 Mar, 2022 11:25 AM
@daniel, do you mean while previewing in Marked, or from within those other applications? To do it outside of Marked you would need to create a System Service or similar (maybe Keyboard Maestro) version of the script. The same concept applies, but the implementation would be different.