As it turns out, the link in the question hinted at a working solution in the form of xclip
:
pandoc -S file.mkd | xclip -t text/html
...and then I can paste it straight into the document in libreoffice, properly formatted. This works with the versions of the programs in the Ubuntu 13.04 repositories (pandoc 1.10.1 and xclip 0.12) -- the -t
option for xclip especially is only in version 0.12 or above. The -S
option of pandoc makes it produce 'typographically correct output', so --
is turned into an en-dash, ---
is turned into an em-dash, and a few other things.
If you want to use the ctrl-v
clipboard, use:
pandoc -S file.mkd | xclip -t text/html -selection clipboard
Edit: if you're running OS X (with pbcopy
rather than xclip
), use:
pandoc -S file.mkd | textutil -stdin -format html -convert rtf -stdout | pbcopy
To transform selected text without creating a file, you can use:
xclip -o | pandoc -S | xclip -t text/html
...this can, of course, be mapped to a keyboard shortcut.
This can work well with a number of text markup formats as input, see the pandoc guide for some more information on how to accomplish this (you might need to use the -f/--from/-r/--read
option, especially if you're using the xclip|pandoc|xclip
version).
As a side note, you can also read an already-existing HTML file into xclip
:
xclip -t text/html <file.html
or
<file.html xclip -t text/html
This sort of syntax is typical for a wiki engine, but they mostly propose similar syntaxes other than Markdown. However,
you can try MDwiki:
MDwiki is a CMS/Wiki completely built in HTML5/Javascript and runs 100% on the client. No special software installation or server side processing is required. Just upload the mdwiki.html shipped with MDwiki into the same directory as your markdown files and you are good to go!
It really is that simple. Follow the tutorial. This is a renderer, not an in-page editor.
Best Answer
With a recent version of
xclip
(the-t
option was added in 2010 but not released yet AFAICT, so you'd need to get it from subversion, or use the one packaged in Debian).And if you want to make that back into the clipboard:
Which you can do in a loop with:
The second
xclip
, with-quiet
will block until something else claims the CLIPBOARD selection, that is until you select something else somewhere.That way, you can copy back and forth between your browser and whatever you're pasting the markdown in.
@tink also has a useful link to a similar question on StackOverflow where you can find how to implement it in python.