Pasting Markdown Follow-Up

In a prior post, I was looking for a way to copy text formated in Markdown into the clipboard, and paste it as formatted text. I came up with a way to leverage pandoc and pbcopy on my MacBook:

pandoc --standalone -f markdown -t rtf | pbcopy

The output was Rich Text Format (RTF). While it did help retain the appearance of the formatting (text I wanted to be bold was bold), there was a gap.

One thing I try to use that Markdown, Microsoft Word, and Apple Pages does, is have styles. Most text would be in a “Normal” style. Headings would each be in their own style, as would code. If I convert among Markdown, Word, and Pages, these are retained–text I mark as # Heading 1 would be assinged the “Heading One” style in the Word Processor. If my destination is Word, I can go in and redefine what Heading One is: maybe the typeface is different, or it’s centered, or something else. Then, everything assigned the Heading One style gets that change.

My ideal solution would be for those styles to be retained when pasting into Word, so I can then make these bulk adjustments. Both have support for “Merge Styles,” so the formatting takes on whatever the style’s characteristics are in the destination document.

Unfortunately, it does not appear that RTF supports styles. The text looks like how I want it to look–“Heading One” is bigger than “Heading Two,” and distinct from normal text. However, everything gets pasted in as “Default Text.” I can’t do the sort of across-the-board tweaks I would want to.

How This Isn’t a Big Deal

On one hand, I’m still getting a high percentage of my desired functionality, nor the only use case. I can still get bold and italic text to show up, and lists do just fine. Headings are still reflected with differences between “Heading One” and “Heading Two.” Tables even work well. The basic look of the output is retained.

Truth be told, this is fine for a lot instances. Before I really came to appreciate styles, it’s how I used a word processor. If I just want some light formatting on a note I’m leaving for the cat sitter or to go into an email, it’s adequate.

Where It Fails

The big difference comes if I’m using Markdown as the first draft of something more important, like a resume or formal paper. I’m not able to tweak my styles dynamically. If I want “Heading Two” to be different than whatever is pasted, I have to find each string of text that should be Heading Two, and reformat it. In short, this scheme, while a convient toolset in other ways, loses a lot relative to just typing in the word processor natively.

The two main reasons I like my EMACS/Markdown/Pandoc scheme is I can use EMACS to create a document, and have all sorts of macros and key bindings that work for me regardless of system or keyboard. I can then output it to a variety of formats: it could be the start of a Word document, an email, or a web page, and it does so fairly cleanly. Using a different tool for each is not the end of the world, but a lot less convienent.

I can still output right from EMACS to a Word document, retain the styles, and modify them to my heart’s content. It just doesn’t feel as clean as just pasting into my destination.

What’s Next

I haven’t given up.

First, I can check into RTF to see if there is some easy way to make it work the way I want it to. Perhaps there is some markup language I can use, and write my own filter. Or, there is some tool other than Pandoc that will create some universal style I can output.

Second, I can see if there is some altneratitve to pbcopy that can take the output from Pandoc and retain styles. It may also be that it’s not Pandoc I want.

Finally, I can lower my expectations. While copying some flat text and pasting it pretty is a neat trick, it really only makes a difference for email. Pasting in to Word is cool, but, at the end of the day, I will want the file. Having Pandoc create one is no big deal. I’m also finding increasing cases where I need to output needs to be HTML. Putting that in the clipboard is handy.

…In Other News

I gave in to my frustration.

While I have no specific love of Microsoft Word and Excel, they are what I know best. I tried to use Apple Pages and Numbers. I gave them a fair shake. But I always felt like I was using the also-ran. I could make it work, but it never felt right.

So, for now, I’m back on Word and Excel. I’m not saying I won’t try again, and its entirely likely their time as the dominate players make come to a close. But, for now, I’m using what I know, and know well.