in a markdown doc I created in DT I select a word.
right-click the highlighted word
choose insert > item link…
double-click the doc I want to link to
now, what happens is the highlighted word is deleted. the name of the doc I choose to link to is inserted in square brackets followed by DT item link in round brackets.
I thought it would put the highlighted word in square brackets, omit the linked to doc’s name, and put the DT item link in round brackets. so I expect to get my chosen word as a link anchor, and not the linked to doc’s name (I can get this using wikilcnks, can’t I?).
so am I doing anything wrong?
any suggestions on how to fix this?
I don’t know if this is how it should work but that’s what I’d expect too.
In case it’s no bug here’s a script that saves some steps. Place the cursor behind the word you want to use as link name, insert the link, then select the link and the word and run the script.
tell application id "DNtp"
try
set selectedText to selected text of window 1
try
set selectedText to selectedText as string
on error
display alert "Please select some text." buttons {"Ok"} default button 1 message "" as informational
return
end try
set newLinkName to characters 1 thru ((offset of "[" in selectedText) - 1) in selectedText as string
set oldLinkName to characters ((offset of "[" in selectedText) + 1) thru ((offset of "](" in selectedText) - 1) in selectedText as string
set newLink to characters ((length of newLinkName) + 1) thru -1 in my replace_String(selectedText, oldLinkName, newLinkName) as string
set selected text of window 1 to newLink
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
on replace_String(theText, oldString, newString)
local ASTID, theText, oldString, newString, lst
set ASTID to AppleScript's text item delimiters
try
considering case
set AppleScript's text item delimiters to oldString
set lst to every text item of theText
set AppleScript's text item delimiters to newString
set theText to lst as string
end considering
set AppleScript's text item delimiters to ASTID
return theText
on error eMsg number eNum
set AppleScript's text item delimiters to ASTID
error "Can't replaceString: " & eMsg number eNum
end try
end replace_String
Hey @pete31, Thank you for your response.
Unfortunately I know nothing about AppleScript, so I’m not sure how to use your solution.
Still I’d like very much to get a certified answer whether or not this is a bug or misunderstanding on my behalf.
Anyone?
You are inserting an item link, i.e., you are adding a link to the file. In the case of selected text, it replaces it with the inserted link.
Link to from the contextual menu is not available in Markdown files, though it is supported in rich text. Development would have to assess the feasibility of supporting it in Markdown.
Hey @pete31,
So it did worked like a charm…
and then it stoped
But also other scripts stoped working correctly.
I even reinstalled devonthink trying to sort the problem - with no luck.
Do you have any idea?