Challenges with the automatic “RTF to Markdown” converter [solved in DEVONthink 3.8]

I’m copying urls dnd pasting them in DEVONthink in a markdown document. However the pasted url escapes the “:” character with a slash. How do I stop this occurring?

Which version of DEVONthink do you use and how did you copy the URL? E.g. I couldn’t reproduce this with a URL copied in Safari. If the clipboard contains rich text, then it’s converted to Markdown. Edit > Paste & Match Style or Cmd-Shift-V can be used to avoid this.

Thank you! Paste and Match style works. How can I make the default that what I paste remains what I copied with no coversion?

This is not possible but usually copied URLs do not contain style and are therefore not converted (see my tests with Safari). Which app did you use to copy them?

The URLS were links from apples messages app.

The next release will improve this.

@cgrunenberg Why is it necessary to use menu Edit > Paste and Match Style when pasting into a Markdown record?

It shouldn’t be this way, I want to paste with ⌘+V without any modification

Does the clipboard contain rich text? Then it’s converted to Markdown (e.g. certain styles are retained and characters escaped)

Nope. Clipboard is set via script.

At least internally the clipboard seems to contain rich text (or AppleScript automatically copied it too?), pasting definitely converts only rich text but not plain text.

Indeed. Using this script after using the linked one …

-- Get RTF Clipboard  as string

use AppleScript version "2.7"
use framework "AppKit"
use scripting additions

set theNSClipboard_RTF to current application's NSPasteboard's generalPasteboard's stringForType:("public.rtf")
set theNSClipboard_RTF_string to theNSClipboard_RTF as string

… results in
{\rtf1\ansi\ansicpg1252\cocoartf1671\cocoasubrtf600
{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
{\colortbl;\red255\green255\blue255;}
{\*\expandedcolortbl;;}
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0

\f0\fs24 \cf0 Why is it necessary to use menu Edit > Paste and Match Style? ([Test PDF.pdf](x-devonthink-item://7D58680E-726C-4107-8DE0-CDE0295AF06C?page=0))}

So the clipboard seems to be automatically set to RTF with some default style.

Would it be possible to only use the RTF clipboard (and conversion) if the clipboard contains any style attributes that differ from this default style? This way we could use ⌘ V the normal way. It really shouldn’t be necessary to use an extra menu just to paste.

Paste and Match Style is not an uncommon paste method, frequently used in rich text, Word, Pages, etc.
People also wanted the ability to convert between rich text content and Markdown. The current mechanism does just that and rather conveniently.

Paste and Match Style is an uncommon paste method in Markdown.

What a user puts on the clipboad shouldn’t be changed unless the user explicitly tells an app to change it. Period.

Understood. But

  • if users want RTF to Markdown conversion then they should have to use an extra shortcut for that.

  • if users don’t want to change anything while pasting then they shouldn’t be forced to remember a new shortcut, i.e. they should be able use the same shortcut as they did for years.

I know no other app that replaced the behavior of a shortcut for a new feature.

This reminds me of removing the ability to search the whole Markdown source as discussed in this very interesting thread DT3 searching markdown footnotes fails. In this thread we were told:

It seems that again some users requested a new behavior and again DEVONthink replaced the old behavior instead of adding the new one.

And again this seems to have happened without knowing how users use DEVONthink or without thinking through the new behavior.

No problem if new features are added, but simply replacing old behavior without an option to get the old behavior back is a no go.

@cgrunenberg please add an extra shortcut for RTF to Markdown conversion or make the automatic conversion optional. I really don’t understand why DEVONthink started to replace well established behavior with some fancy things.

1 Like

I’m not sure that I understand the argument. It seems to me that someone (a script?) copied RTF content to the Pasteboard (which is an OS feature, not a DT one, I think?). Under this assumption: In the Pasteboard, the data is RTF. On pasted into a MD file, you want the RTF stuff removed and only the bare text pasted?
I don’t know enough about NextStep and all these APIs, but on other systems, one could possibly provide a target “format” (like a MIME-type) on pasting. Then the OS would do The Right Thing™ (or nothing at all, e.g. if you try to paste a JPEG with a target format of text ;-).
However, on MacOS it seems to be very common that attributes of data (e.g. the font/style from an HTML, spread sheet or word document) are preserved in pasting (if that’s at all possible in the target).

The problem is that DEVONthink changed behavior, nothing else.

I want to be able to use CMD + V to paste a clipboard that was set via script without changing the pasted content. This worked for years. Now with this fancy new automatic „RTF to Markdown“ conversion it doesn’t work anymore.

Please try the script I linked above to see what I mean.


Edit:

That’s how it works on macOS too.

Setting the clipboard via plain AppleScript also includes a RTF version (that’s something I wasn’t aware of before and it seems @cgrunenberg also wasn’t aware).

Pasting into a Markdown record used to paste without any modification.

But now, with the automatic “RTF to Markdown” conversion, the pasted content is escaped for Markdown. That’s obviously not what a user wants if the clipboard contains a Markdown link because escaped links won’t work.

1 Like

That’s true. But usually rich text (copied from websites, emails or documents) doesn’t contain raw Markdown code and therefore it’s nice to have some basic styling converted and that you don’t have to worry about special characters. In this case the clipboard seems to work as expected:

tell application id "DNtp"
	set theStr to "[Markdown Test](x-devonthink-item://3C86525C-B290-48CD-ACD6-9BF5918C8EAE)"
	set the clipboard to theStr as string
end tell
1 Like

Pasting this script’s result into a Markdown record yields an invalide Markdown link, so it just shows the problem again :slight_smile:

I understand the idea and in fact like it.

However, the problem remains that the normal pasting behavior was replaced and there’s no option to get it back.

I know this wasn’t intended but it’s the result of the decision to automatically escape the RTF clipboard when pasting into a Markdown record.

Again, I like the idea of making it easier for some users, however this results in making it unnecessary complicated for other users. That’s why it should be optional. Especially such a basic thing like pasting shouldn’t force users to think about it.

Please add an option that stops the automatic conversion.

Which version of macOS do you use?

10.14.6 Mojave

The code posted by @cgrunenberg works ok on my Big Sur: It writes something to the clipboard that gets pasted exactly as an MD link in DT and another app. Maybe Apple did fix something after all in Big Sur :wink:

1 Like