Markdown as first-class citizen & networked knowledge

Yes! I’ve been trying out the WikiLinks feature, it works quite well (though it’s auto suggest can be a bit “dumb” at times suggesting longer item names when a shorter one will do).

A big difference however is backlinks - Roam automatically creates backlinks to every file that another references. This would be very useful in DT and currently requires a slow and janky scripting process. Roam also supports atomized linking - each paragraph inside its markdown-style files is given a unique UUID to allow for granular linking (and back-linking). Creates a lot of interesting knowledge-management possibilities.

As far as Markdown is concerned, for sure not looking for a full do-everything editor (can use other apps for that). More just asking for Markdown to be equal with RTF as a first-class citizen, EG for templates and defaults to be equal between them. For example, right now if I want to use markdown in the daily journal workflow I have to hand-build my own template. No big deal for one workflow… but added up to all the possibilities in DT and there’s a lot of places where RTF is the default and markdown has to be manually edited.

And prism - yes! Understood, it’s just for rendered formatting. Still can’t get it to work though :man_shrugging: and something like this which is a common use case for markdown (code snippets etc) seems like a good candidate as a possible built-in option for a knowledge management app with as much power as DT

More just asking for Markdown to be equal with RTF as a first-class citizen, EG for templates and defaults to be equal between them. For example, right now if I want to use markdown in the daily journal workflow I have to hand-build my own template. No big deal for one workflow… but added up to all the possibilities in DT and there’s a lot of places where RTF is the default and markdown has to be manually edited.

RTF is a far more mature and popular format used by the majority of our user base (which incidentally is not primarly coders, but often academics, office personnel, and people running apps that natively support rich text (Word, TextEdit, etc.). RTF is far more prevalent and embedded in the user experience of many, many of our customers (even some people in here :P).

As far as extra templates, etc., part of the beauty of DEVONthink is the ability to extend it by adding your own templates, etc. With some know-how and ingenuity, you can roll many of your own solutions.

(though it’s auto suggest can be a bit “dumb” at times suggesting longer item names when a shorter one will do)

I am not sure what you’re referring to here.

Still can’t get it to work though

You need to make sure to load both resources properly and denote the language on the first line of a codeblock…

<link href="resources/prism.css" rel="stylesheet">
<script src="resources/prism.js"></script>

```language-applescript
tell application id "DNtp"
beep
end tell
```…

Multiple issues here. The Markdown is I guess a question of priorities. If knowledge workers and programers are to be a big focus going forward, Markdown is an obvious place to invest—but it’s not my software! I can just make the request as I see so many issues referenced on these forums that would be solved. Would love to see it in the future.

For the other two—I’m trying to figure out how to fork this conversation in Discourse—any tips?

For prism.js I’ve done as you’ve suggested (originally following the instructions from the primary thread on the topic) but I can’t tell why it’s not working. I’ve tried every style of reference—put the files inside a group named assets and then link at “assets/prism.css” (and .js); using the x-link URLs; hard-coding a link on my file system… None seem to work. It’s hard to debug if DT is seeing the files.

For WikiLinking, for example if I have two pre-existing documents:
“DEVONThink is awesome, everyone should use it”
“DEVONThink’s limitations for networked knowledge and how to get around it”
… and then in a new note try to type [[DEVONThink Notes]] to create a Wiki link to a new document, it’s damn near impossible to overcome the fervent efforts of the autofill system to fill with the longer item names.

Noticed a bug here: this works properly for Markdown files loaded in the main view, but it doesn’t work properly for markdown-formatted annotations. It just inserts the title of the document rather than the link.

“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]