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.

4 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 "
2 Likes

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.

1 Like

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 Download PopClip.

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 copies it to the clipboard. (By holding ⌥⇧ you can get it to try to paste the result in place 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.

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

17 Sep 2022

  • Change default behaviour to Copy.

13 Apr 2022

  • Initial test release.
6 Likes

I can’t wait to try this. Thanks!

This is FANTASTIC and I use it all the time! I write most everything in Obsidian.md or in Drafts, and so it’s great to convert the markdown to RTF and paste it into a Mail email or a Word document, when that’s needed.

One request: could you add an option to default to Copy the RTF output instead defaulting to convert in place? I always use it that way, and often forget to use the ⇧ key.

1 Like

Thanks the the feedback! I’m glad it’s working well. Any thoughts on the choice of of fonts, sizes, etc.?

Rather than add an option, I’ve gone ahead and changed the default behaviour to Copy. You’ll need to redownload from the same link above. Thinking about it, this makes more sense to me.

You can still override it to Paste in place by holding ⌥⇧.

3 Likes

Thanks so much! Works so smoothly now. The text style you’ve selected seems fine.

BTW: You might want to add an edit to the original post about this, indicating the change you’ve made.