I would like to use DT3 Web clipper for Obsidian as well

I would like to use DevonThink Web clipper to clip websites into Obsidian. The main reason is that a lot of sites that I am interested contain programming code and it does a very good job retaining the code.

The problem is in terms of how it creates the markdown for images.

Here is an example

![You can use ChatGPT for code generation questions to increase productivity.][11]

and at the end of document it has

[11]: [https://www.avanderlee.com/wp-content/uploads/2024/05/chatgpt\_swift\_code\_generation-1024x605.png](https://www.avanderlee.com/wp-content/uploads/2024/05/chatgpt_swift_code_generation-1024x605.png)

This image does not appear in Obsidian

And here is an example what happened in the same site when I used the MarkDownload - Markdown Web Clipper

![You can use ChatGPT for code generation questions to increase productivity.](https://www.avanderlee.com/wp-content/uploads/2024/05/chatgpt_swift_code_generation-1024x605.png)

This image appears properly in Obsidian

I don’t like how the mark and Web clipper handles program code so I would prefer not to use it.

Does anybody have any suggestions. Can I get Obsidian to recognize the markdown that is generated in Devonthink? Can I somehow have DT3 Web clipper work with what Obsidian expects?

You might want to have a Smart Rule that runs a script that (1) replaces each [xx] in the main body with the corresponding (URL), and then (2) delete the footnote-style links. Perform the Smart Rule On Clipping.

1 Like

@meowky Thanks for the advice.

However, that is probably beyond my scripting abilities

The main reason for this is that this is valid Multimarkdown syntax which is what Devonthink supports. Obsidian have their own ‘flavour’ of markdown based roughly on Common Mark with other additions. From their help:

Obsidian strives for maximum capability without breaking any existing formats. As a result, we use a combination of flavors of Markdown.

Obsidian supports CommonMark, GitHub Flavored Markdown, and LaTeX. Obsidian does not support using Markdown formatting or blank lines inside of HTML tags.

I would like to use DevonThink Web clipper to clip websites into Obsidian.

That is not technically feasible. It is Clip To DEVONthink.

Can I get Obsidian to recognize the markdown that is generated in Devonthink?

That would be an Obsidian question. This is what happens in Obsidian…

That’s not something we control.

Can I somehow have DT3 Web clipper work with what Obsidian expects?

No, you can’t modify the clipping behavior of the browser extension.

I’m aware of existing solutions available elsewhere. As a coding exercise I wrote the following simple script to convert reference-style links to inline ones. Tested successfully on 2 news clippings.

on performSmartRule(theRecords)
	tell application id "DNtp"
		repeat with theRecord in theRecords
			if (type of theRecord is markdown) then
				set thisText to plain text of theRecord
				set plain text of theRecord to my ReplaceLinks(thisText)
			end if
		end repeat
	end tell
end performSmartRule

on run
	tell application id "DNtp"
		set theRecords to selected records of think window 1
		repeat with theRecord in theRecords
			if (type of theRecord is markdown) then
				set thisText to plain text of theRecord
				set plain text of theRecord to my ReplaceLinks(thisText)
			end if
		end repeat
	end tell
end run

on ReplaceLinks(theText)
	local pTID
	set pTID to AppleScript's text item delimiters
	set paragraphList to (paragraphs of theText)
	set fnFlag to false
	repeat with i from 1 to (length of paragraphList)
		set tp to item i of paragraphList
		if tp begins with "[1]:" then
			set fnFlag to true
			set AppleScript's text item delimiters to linefeed
			set mainText to (paragraphs 1 thru (i - 1) of theText) as text
		end if
		if (fnFlag is true) and (tp begins with "[") then
			set AppleScript's text item delimiters to ": "
			set theLabel to text item 1 of tp
			set theURL to "(" & (text item 2 of tp) & ")"
			set mainText to my ReplaceText(mainText, theLabel, theURL)
		end if
	end repeat
	set AppleScript's text item delimiters to pTID
	return mainText
end ReplaceLinks

on ReplaceText(theText, searchStr, replaceStr)
	local prevTID
	set prevTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to searchStr
	set theItemList to text items of theText
	set AppleScript's text item delimiters to replaceStr
	set theText to theItemList as string
	set AppleScript's text item delimiters to prevTID
	return theText
end ReplaceText

This relies on the reference numbers starting at [1].

I came up with this smart rule script (in JavaScript). Tried it only with your example, as I don’t have others. It hoists the end-note images into the text and removes the end notes. I suggest you duplicate some of your MD files to a group, build a smart group from them, and add an execute script action to it with this script.

Do NOT run this script on your originals unless you’re sure that it does what you want!

If it works – good. If not, you can PM me, preferably with some sample MDs.

function performsmartrule(records) {
  /* Regular expression to find end notes:
     Number in square brackets, followed by a colon and at least a space. Followed by something in square brackets, supposedly the URL. The number and the URL are collected in capturing groups 1 and 2 */
  const endNoteRE = /\[(\d+)\]:\s+\[(.*?)\].*?\)/g;

/* Loop over all markdown records */
  records.filter(r => r.type() === 'markdown').forEach(r => { 

    /* Get the record's text in a local variable */
    let txt = r.plainText();
    
    /* Get all end notes in an array where each element is an array whose
       - first element is the whole match ("[1]: [URL](URL)
       - 2nd element is the 1st capturing group, i.e. the end note's number
       - 3rd element is the 2nd capturing group, i.e. the URL
    */
    const endNoteMatches = [...txt.matchAll(endNoteRE)];
    
    /* Loop over all end notes */
    endNoteMatches.forEach(match => {
      const referenceNo = match[1];

      /* Build a new regular expression to find the image in the text:
       Exclamation mark followed by something in square brackets followed by the referenceNo in square brackets */
      const replacementRE = new RegExp(`(!\\[.*?\\])\\[${referenceNo}\\]`, 'g');
      
      /* replace the reference to the end note with the URL */
      txt = txt.replaceAll(replacementRE, `$1(${match[2]})`);

      /* Remove the end note */
      txt = txt.replaceAll(match[0],"");
    })
    
    /* All images are fixed, update the record's text */
    r.plainText = txt;
  }) 
}

Sorry, should have been clearer. The Obsidian vault is in Devonthink3.

@meowky, thanks for going out of your way and putting together the script. I will get back after I tried it out.

@chrillek Thanks for putting this together, much appreciated. let me try it and get back to you.

Thanks @meowky, this is how i set it up. Is it correct.


I will not be able to test until later Sunday.

This is how I set it up.


I won’t be able to test until Sunday. Thanks

You should select documents in your rule (below the “all of the following are true”, using the plus button at the very right).

That’s true for both scripts.

@chrillek sorry I don’t follow

Not sure where? I looked and could not find.

Stephen

1 Like