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

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

How did you execute my example? Via the Script Editor.app? This works as expected on Catalina & Big Sur, nothing’s escaped afterwards.

Via Script Debugger and now also via Script Editor. Both yield escaped links when pasted via CMD + V.

I have an idea how to work around. Let me try

-- Set clipboard to plain text

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

set theStr to "[Markdown Test](x-devonthink-item://3C86525C-B290-48CD-ACD6-9BF5918C8EAE)"

set thePasteboard to current application's NSPasteboard's generalPasteboard()
thePasteboard's clearContents()
(thePasteboard's setString:(theStr) forType:(current application's NSPasteboardTypeString))


This works.

As it seems it’s not possible to set the clipboard only to plain text in Mojave and setting the clipboard via script isn’t the general way to use it I think it will be fine to use AppleScriptObjC for this edge case. :slight_smile:

Thanks!


Edit:

@cgrunenberg I still think the automatic conversion should be made optional. Altering the copied text should be an explicit choice made by the user, not the default.

It puts cognitive load on the user to always be aware from where text was copied and makes such a simple thing like pasting unnecessary complicated, at least over here.

So please consider to add an option that disables the automatic conversion.

2 Likes

Although I understand the use case where a user may wish to have DT alter what they’re pasting into a Markdown document, it’s not my preferred behaviour. I paste a lot of code snippets into Markdown notes and I always forget it’s not ⌘-V any longer unless I want a bunch of escaped gibberish. And I don’t want to have to use the four mystery keys to get “Paste and Match Style” (I can play complicated Bach fugues on the piano, but getting my fingers around the Paste and Match Style shortcut is somehow beyond my digital agility!)

So I changed changed the keyboard shortcut in DT for “Paste and Match Style” to command-V in System Preferences → Keyboard → Shortcuts. Now ⌘-V gives me the expected unescaped content from the clipboard.

If the use wants to the flexibility to Paste vs Paste and Match Style, then obviously some other solution is required…

1 Like

Exactly. Changing the shortcut is no option over here as I also want to paste rich text … There really shouldn’t be an automatic conversion without an option to disable it.

I understand that automatic conversion might be handy for some users but it obviously makes it very hard for others. It’s a bad decision.

I’ve found I only have an issue with this if I have PlainTextIsMarkdown set to TRUE. I had to turn that off (even though I work almost exclusively in Markdown), because as has been mentioned the pasteboard in DT3 does not paste what is copied to it. Until I worked out that it seemed to be linked with the above hidden setting, I was doing my Markdown work elswhere.

For the record, I don’t believe any app should alter what is on the pasteboard, unless explicitly requested. That request should be via another command not the CMD+V that is in everyone’s muscle memory. Muscle memory requires things to be the same or workflows suffer.

1 Like