Idea: Markdown to RTF

This idea, emailed by a user, is to select some markdown source and invoke a PopClip action that will convert the Markdown to RTF to be pasted in another app, one that does not undertand Markdown e.g. Pages

I’m not sure if this is doable at the moment or not, it might need some more RTF handling support in PopClip itself.

3 Likes

Two thumbs up for this one.

I do most of my writing of all kinds in Drafts, and then move the text to its final destination one way or another. To be able to copy a snippet of text (formatted with Markdown) and paste into an email or Evernote would be wonderful.

1 Like

Agreed, this would be a game changer…

1 Like

would be really useful and interesting if copying Markdown as RTF helps to copy paste to Confluence.

I would certainly welcome that too. Drafts is fine for a whole document, but a PopClip action would be much better.

I would love something like this. I am not a markdown “creator” but I do copy things from editor that natively store in markdown. This would be fantastic! Please? :wink:

Without building a full on extension, can snippets check for external dependencies or run external commands? Markdown to RTF is pretty straightforward with pandoc -f markdown -t rtf -s

To run a shell script you need to make a “full”extension.
Either that or you can make an applescript one, and run the shell script within the AppleScript :slight_smile:

I’m close, but missing something here - this doesn’t paste the output.

# popclip
name: Markdown to RTF
icon: symbol:doc.richtext
description: Replace selected Markdown text with richtext
applescript: do shell script "echo " & quoted form of "{popclip text}" & " | /opt/homebrew/bin/pandoc -f markdown -t rtf "
1 Like

You need to add an after field to the snippet to tell PopClip what to do with the output

The thing is though, this will convert the markdown to RTF source code as plain text. But what people really want here is to place it on the pasteboard as an actual RTF data type, that is recognised by other apps as formatted. It is theoretically possible, but it’s a bit more complicated and I haven’t even actually tried to do it myself yet. I’ve put the code into PopClip, I haven’t used it :upside_down_face: It will require a JavaScript extension to do it.

Hello folks — I’ve been working on this extension idea and I’ve got something working.

To try it you’ll need to install the latest beta version of PopClip (Build 3835) from PopClip Downloads.

Then download the extension from: https://github.com/pilotmoon/PopClip-Extensions/raw/master/extensions/MarkdownToRichText.popclipextz (note: requires macOS 12.0)

This is very much a “test release” at the moment, so please let me know what you think!

Note that rather than “copy as RTF” I went for conversion in place, but you can make it copy instead, by holding Shift(⇧) key (which by the is available with all extensions that paste stuff).

Here is is in action:

CleanShot 2022-04-13 at 15.37.39

And some more info:

Markdown to Rich Text

It interprets the plain text of the selection as Markdown, and converts it to Rich Text Format (RTF) and pastes it over the selection. If pasting is not possible, it copies it to the clipboard instead.

By contrast with the Markdown to HTML extension, which produces HTML source code as plain text, this extension produces RTF content which is labelled as RTF on the clipboard. This means it is recognised by any Mac app which supports pasting RTF content.

By holding the Shift key you force it to copy to the clipboard instead of pasting.

A note on formatting

As part of the conversion process, decision had to baked in regarding font styles, indentation, spacing etc. The conversion tries use simple, sane choices for formatting. It also tries to match the existing font of the selection is possible, with fallback to the system default font.

Please send feedback to Nick if you have comments about the output formatting choices or notice any glitches.

Options

The Paragraph Separation option determines how paragraphs are separated in the output, as follows:

  • 0.5x Spacing (default) sets the paragraph spacing to half the line height;

  • Blank Line adds a full blank line between paragraphs instead.

Limitations

Not all markdown features are currently supported:

  • ---- to produce a horizontal separator will not work

  • HTML tags mixed into the Markdown will not be processed

TODO

  • Icon!

  • Testing/gather feedback.

About

This is an extension for PopClip.

Author

Nick Moore

Requirements

  • Requires PopClip Build 3835

  • Requires macOS 12.0

Changelog

v0 - 13 Apr 2022

  • Initial test release.
3 Likes

I can’t wait to try this. Thanks!