Markdown as first-class citizen & networked knowledge

“assets/prism.css”

This would only work if the assets group was in a subfolder of the location of the Markdown file.
Anywhere else it needs a prefixing forward slash.

This is noted in the Help > Documentation > Documents > Markdown Documents.

it’s damn near impossible to overcome the fervent efforts of the autofill system to fill with the longer item names.

?… you can just keep typing or press Escape to dismiss the suggestion.

it doesn’t work properly for markdown-formatted annotations. It just inserts the title of the document rather than the link.

Development will have to look into this.

I just had an “aha” moment that links together several ideas across several forum threads.

MultiMarkdown supports links to anchor tags. This can take the form of an internal link within the same markdown file (headings automatically create an anchor tag), or an external link to a standard URL with an anchor tag. However, anchor tags don’t seem to work in DEVONthink for x-callback URLs.

For example:

# Link to Headers via Anchor Tags

## Examples

With MultiMarkdown, I can do [internal links][] to other headings in the same markdown document.

If I link to an [external page](https://github.com/fletcher/MultiMarkdown-6-Syntax-Guide/#building) with ```https://url#anchor``` it will also work.

However, if I link to a markdown file's [heading](x-devonthink-item://XXXCALLBACKXXX#anchor) with an internal DEVONthink x-callback URL using an anchor tag, it doesn't work.

## Internal Links

The first item in the [Examples][] will link here.

If DEVONthink supported the MMD anchor-tag format for internal x-callback URLs, it would enable the specific “knowledge block” addressing needed for true networked knowledge management. This would open up a whole new world of workflows within DT without requiring any other change as far as I can see. And it’s already supported within MultiMarkdown.

What do you think?


Here are some of the other forum threads for reference:

1 Like

Not sure I understand the need to specifically link to headers within a MD file. You can link to any line or word you want by using the x-callback url scheme. E.g.: x-devonthink-item://...?line=NUMBER or x-devonthink-item://...?search=WORD. Lines can change if you edit the document, so it is simply a matter of choosing a unique ID for any given header and link there.

1 Like

Ah that’s very useful, thank you! I didn’t know about that functionality. Is it documented anywhere?

Named anchor is still a good addition I think. It uses the MultiMarkdown spec, it’s less fragile (named anchors can remain consistent in MMD even as text changes and moves). It also translates well to other systems, EG if a bunch of notes are converted to HTML. And it’s already built-in… just not for x-callbacks

I’ve been trying this and the ?search=WORD syntax appears to have no effect.

It’s also not very useful in a lot of cases—EG words in headings are found in the body, or headings are included in a {{TOC}} table of contents block.

That syntax is for searching a specific document. Like this…

x-devonthink-item://FD49FF28-9473-4A12-86C6-3650585B65C4?search=ipsum

yields…

It’s also not very useful in a lot of cases

This is not quite accurate. It is very useful in a lot of cases, especially RTF or PDF, which are easily the most common formats in general.

Hence my suggestion to use a unique ID.

# Header 1 [id001]

x-devonthink-item://itemUUID?search=id001

Ah, ok - so in the context of this thread about Markdown, this syntax doesn’t work. So the situation remains of desiring a way to link to a specific section of a markdown document.

Using the MMD spec for linking to anchor tags via x-callback would be ideal. If not, enabling the ?search=name for markdown documents would also be a way to go. I’d prefer anchor tags but if development @cgrunenberg or anyone has a chance to make it work I’ll be happy!

# Header 1 [id001]

Do you use this syntax in practice?

Why do you say it does not work?

It does work for MD documents.

I have no need to create links to headers in other MD files. EDIT: Of course, this would work for the header only if you are using edit-mode. Not sure if this is why you’re asking. (One could always simply place the id in the following line, if one prefers to use preview-mode).

I have no need to create links to headers in other MD files.

Understood. Thanks.

It’s working for you? In my testing with markdown files clicking a link with this syntax loads the referenced file but doesn’t go to or highlight the search term.

Are you testing on macOS or iOS? I haven’t tried it on macOS, but on iOS I get the same results (loads the document, doesn’t highlight the search term).

Testing on macOS so far. It appears to be a bug in the logic. To click the link, the document containing the link has to be in preview mode. With DT prefs set to “Markdown Display: Preview Documents” the behaviour is:

  • with [id: xxxx] and search term: xxxx, no result
  • with Header (or any text) set to xxxx and search term: xxxx, highlights the search term in the text

With DT set to “Markdown Display: Edit Documents” the behaviour is:

  • no result from search term, either for ID or text

By manually opening the “side-by-side” markdown view, I can get the expected behaviour where the search term is highlighted (both ID and text) but only in the “edit” side of the window.

I’d label this as a bug? It’s certainly not expected or consistent behaviour.

Did you make sure that the search term in the x-callback-url is exactly the same as the term that should be highlighted?

Notice that if you have id001 you need ?search=id001, not ?search=001.
If you have funnylittlebear, you need ?search=funnylittlebear.

Spaces must be html encoded, so funny little bears should be funny%20little%20bears.

Here is a script you can use:

tell application id "DNtp"
	try
		
		set currentRecord to (content record of think window 1)
		set theTerm to the selected text of think window 1 as string
		set theTerm to my replaceText(theTerm, " ", "%20")
		set theURL to the reference URL of currentRecord & "?search=" & theTerm
		
		
		set the clipboard to theURL
		
	end try
end tell

on replaceText(theString, old, new)
	set {TID, text item delimiters} to {text item delimiters, old}
	set theStringItems to text items of theString
	set text item delimiters to new
	set theString to theStringItems as text
	set text item delimiters to TID
	return theString
end replaceText
1 Like

That’s a handy script! Thank you! Also helpful to know it has to be exactly the same string.

However it’s still not working (or, working inconsistently as I detailed above). Here’s the sample markdown:

[search link](x-devonthink-item://XXXCALLBACKXXX?search=id18008)

## Destination text [id18008]

Try placing the idkey in the line below, as this could prevent the link from working if you’re in preview mode.

This works… but then this is the same as searching for any text as the ID appears in the rendered Markdown.

Wait a second… if you’re expecting DEVONthink to find and highlight Destination Text, it won’t as that’s not the search term. Also, it won’t highlight a hidden object in the rendered HTML.

Here it works when opening in edit mode (set by the Media preferences)

OK interesting. I’m not getting that behaviour here - it doesn’t highlight the search term in edit mode, it loads the page in preview mode (even though the preference is set to open in edit mode)

I’m not expecting it to find the other text, just the search term