Obsidian and link support

Angus McIntyre's Avatar

Angus McIntyre

20 Feb, 2021 06:10 PM

There's an interesting open-source project called Obsidian that allows users to create a kind of personal wiki based on a simple directory of Markdown files.

To allow linking between different files, Obsidian uses a syntax that looks like [[foo]] (for links within a document) and ![[foo]] for links to other documents.

Even if it's not possible to extend Marked 2 to handle linking, it might be nice if the Marked 2 renderer could present Obsidian links in a slightly more attractive way (currently, they're simply rendered as literal text).

Obsidian does include its own preview renderer for Markdown, but Marked 2's rendering is more attractive, so sometimes it might be nice to be able to read Obsidian documents using Marked 2.

  1. Support Staff 1 Posted by Brett on 21 Feb, 2021 01:11 PM

    Brett's Avatar

    Hi Angus,

    Marked does not function well as a wiki, but it's entirely possible to extend it to recognize the link syntax using custom preprocessors. It's unlikely I'll make the additional syntax part of the core installation, though.

    nvUltra, my upcoming notes app, also recognizes Wiki links, as does nvALT before it. But they make sense in apps like that which can handle them internally. Marked would never know for sure what to do with them. Add an MD extension? Assume a rendered HTML file? Is the target relative to the document? What if we're in a streaming preview without base url? Too many inconsistencies between implementations to make any assumptions.

    As I mentioned, though, a few lines in a custom preprocessor script could not only make them look better, but render them to link in just the way you expect them to. If I find time, I'll write one up, but if you have any scripting knowledge, it's just a simple regex replacement.

    - Brett

  2. 2 Posted by Maz on 22 Apr, 2021 04:54 AM

    Maz's Avatar

    "Obsidian does include its own preview renderer for Markdown, but Marked 2's rendering is more attractive, so sometimes it might be nice to be able to read Obsidian documents using Marked 2." Strongly second that, and request to create a simple solution to stream from obsidian to Marked 2,( for those not into coding :))

  3. Support Staff 3 Posted by Brett on 23 Apr, 2021 02:15 PM

    Brett's Avatar

    A streaming solution from Obsidian to Marked would have to be implemented on the Obsidian side. It's easy to set up, but requires that the developer of the source app add it: https://marked2app.com/help/Streaming_Preview

    I would point out a great Keyboard Maestro macro from Bruno Conte that I'll be writing about on my blog soon, but if you're a KM user, feel free to try it out.

    Keyboard Maestro: Copy And Stream to Marked

  4. 4 Posted by Angus McIntyre on 28 Apr, 2021 01:58 AM

    Angus McIntyre's Avatar

    Having learned from Brett's post that pre-processors were an option in Marked (I should really read the manual), I did a little playing around. The following trivial Python3 script doesn't add any hyperlinking functionality, but it makes the output look a little nicer.

    #!/usr/bin/env python3
    
    import sys
    import re
    
    linkre = re.compile(r"\[\[(.*)\]\]")
    for line in sys.stdin:
        print(linkre.sub(r"<u>\1</u>", line.rstrip()))
    

    Save it somewhere, make it executable, and then set it up as a custom preprocessor through the Advanced tab in Preferences.

  5. Support Staff 5 Posted by Brett on 28 Apr, 2021 12:06 PM

    Brett's Avatar

    Nicely done @Angus.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac