How to convert markdown link to item link

Thank you for your response. However, I am still experiencing difficulties with the “Convert WikiLinks to Item Links” feature. When I select a Markdown document that contains relative links to images in the assets folder, the menu option remains grayed out. Could you please clarify if there’s a specific condition under which this feature should work? It’s possible that I may not fully understand how to properly use this function. Any additional guidance would be greatly appreciated.

Sorry. I am sick and missed you were writing about relative links.

Note there is a preference to always use item links when adding images to Markdown…

Dear Jim, I wish you a speedy recovery. I am familiar with the feature that allows for the creation of item links when dragging and dropping an image into a markdown document. However, I would like to know if there is a way to convert relative links in existing markdown documents into item links. From what I understand, this is currently not possible, but it might be achievable through a script, which I unfortunately lack the skills to program myself. Take care of you!

I can’t suggest a script really now as I’m traveling without access to DT.
Here’s what I’d do for every selected record:

  • get its outgoing links using the record’s corresponding property
  • for each outgoing link whose primary location is the Assets group
    • get its name and reference URL
    • built a regex from the name (`]\\(Assets/${name}`), using the global flag
    • replace all occurrences of this RE with the reference URL record.plainText().replaceAll(RE,`](${referenceUrl}`)
    • set the record’s plainText attribute to the new b text

The pseudo code is in JavaScript. I’m sure one could use a similar approach with AS, but the replacement step might be a tad more awkward.

Some of the steps after present in the past I linked to above. I retrained from posting a script here since I can’t test anything at the moment.

Unfortunately, outgoing references refers to item links, not relative/absolute links.

Bummer. In that case, we’d have to go over the content of all the files and get the reference URLs from the linked documents.

And images are not links (although they reference other items in some way).

Does that mean that at the moment it is not possible technically to write a script for markdown documents to convert “relative links” (that apparently are not relative links) for images to item links? Or just more tricky? For the future I will switch to item links in the markdown settings, but I have the hope that sooner or later I can convert the links in my older MD documents to item links, as I prefer their usability when moving files between groups.

No, that’s not what it means. The script would just have to look at the MD content itself and modify it, instead of using the outgoing references property.
Technically, it’s the URL you’re going to change, not a “link”. But for a script, there’s no big difference.