0

I'm generating some formatted content that I'd like to paste into a google doc. Think links & tables. I'll use whatever format works, but I think HTML is the only one Google Docs will support enough (Google Docs does not support tables in markdown, as near as I can tell).

What makes this a mac-specific question is the pasteboard data type. I've discovered that if I set the pasteboard type as HTML, then I can paste into the google doc and its interpreted. (If I just regular copy-paste raw html, it shows up as the html source in the google doc, it does not get formatted).

But, even setting that pasteboard data type is a headache. pbcopy does not provide a way to set the data type. pbpaste has a -Prefer argument to let you choose what data type to paste, but (a) I'm trying to set the type for the copy, not the paste and (b) even pbpaste doesn’t list html as an option.

(I found an answer via a python lib which works for now, but I'm asking anyway in case there better options, and to help anybody else that might try this)

1 Answer 1

1

I was able to put text into the pasteboard as html using the pasteboard python library. So it looks something like:

html = '''\
<style>
...
</style>
<table>
 <thead> ...
</table>'''

import pasteboard
pb = pasteboard.Pasteboard()
pb.set_contents(html, pasteboard.HTML)

I will add that while this does let me paste a table into Google Docs, the support is pretty limited, esp for CSS. I can't get any css to work on thead or tr, (not in the separate <style>, nor as a style="..." attribute on the elements themselves). But I can at least set border-collapse on the table, and style the border of individual td elements.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .