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