Using some custom script I'm generating some markdown (because it is easy to write) content, maybe it is status report or something. fOR EXAMPLE this:
$ cat /tmp/report.md # Monday * Watching cat videos * Fixing what I broke at Fry
Now you want to paste it to, say, Google Document. First step is to convert to HTML:
$ cat /tmp/report.md | multimarkdown <h1 id="monday">Monday</h1> <ul> <li>Watching cat videos</li> <li>Fixing what I broke at Fry</li> </ul>
Or using Pandoc:
$ cat /tmp/report.md | pandoc --from=markdown --to=html <h1 id="monday">Monday</h1> <ul> <li>Watching cat videos</li> <li>Fixing what I broke at Fry</li> </ul>
Now to transfer it, very convinient way I was using is to copy it to the clipboard (and then just paste in in the editor with Ctrl+V
):
cat /tmp/report.md | multimarkdown | xclip -sel clip -t "text/html"
When I needed to paste into Altasian Confluence WYSIWYG editor, it did not worked for me for some reason - only plain text was copied and the formatting was lost. But copying from normal web page worked. What is the difference? Thanks to this great answer, I have examined how clipboard looks like when I copy snippet from a web browser and noticed this:
$ # Selected and copied something from the web browser $ xclip -o -selection clipboard -t TARGETS TIMESTAMP TARGETS MULTIPLE SAVE_TARGETS text/html text/_moz_htmlcontext text/_moz_htmlinfo UTF8_STRING COMPOUND_TEXT TEXT STRING text/plain;charset=utf-8 text/plain text/x-moz-url-priv $ xclip -o -selection clipboard -t text/html <meta http-equiv="content-type" content="text/html; charset=utf-8"><ol> <li>copy something from you web browser</li> <li>investigate available types</li> </ol>
So looks like I need that <meta http-equiv="content-type" content="text/html; charset=utf-8"><ol>
string, so let's add it:
$ (echo '<meta http-equiv="content-type" content="text/html; charset=utf-8">'; cat /tmp/report.md | multimarkdown) | xclip -sel clip -t "text/html"
And here we go, pasting to Conflence works now!
Note: For some reason I do not understand, it seems to work the old way now once I pasted the new way for a first time :-/ Maybe above is not needed at all, YMMW.