When I try to export the text from a Google Docs using the export_media
method, the result is a bloc of text (correct at least) but without newlines.
For exemple, if my file contains
Test
And another test
The display will looks like
Test And another test
Here is my code:
http = decorator.http()
service = discovery.build("drive", "v2", http=http)
docs = service.files().export_media(fileId=docs_key, mimeType="text/plain").execute()
docs = docs.decode('utf-8')
EDIT:
I also tried to export the file as html content instead of text. The problem is that I don't how to use this html as actual html instead of just a string. Here is my code :
http = decorator.http()
service = discovery.build("drive", "v2", http=http)
docs = service.files().export_media(fileId=docs_key, mimeType="text/html").execute()
docs = docs.decode('utf-8')
docs = docs.encode('ascii', 'xmlcharrefreplace')
h = HTMLParser()
docs = h.unescape(docs)
As you can see, docs
contains now the google document in an html format. But if I try to display docs
like this, my web page display this time the html code (still without newlines) :
<html><head><meta content="text/html; charset=UTF-8" http-equiv="content-type"><style type="text/css"> ul.lst-kix_yreqa03lukup-0{list-style-type:none}.lst-kix_yreqa03lukup-3 > li:before{content:"❏ "}.lst-kix_yreqa03lukup-4 > li:before{content:"❏ "}ul.lst-kix_yreqa03lukup-2{list-style-type:none}ul.lst-kix_yreqa03lukup-1{list-style-type:none}.lst-kix_yreqa03lukup-5 > li:before{content:"❏ "}.lst-kix_yreqa03lukup-1 > li:before{content:"❏ "}.lst-kix_yreqa03lukup-7 > li:before{content:"❏ "}.lst-kix_yreqa03lukup-0 > li:before{content:"✓ "}.lst-kix_yreqa03lukup-6 > li:before{content:"❏ "}.lst-kix_yreqa03lukup-8 > li:before{content:"❏ "}ul.lst-kix_yreqa03lukup-8{list-style-type:none}ul.lst-kix_yreqa03lukup-7{list-style-type:none}ul.lst-kix_yreqa03lukup-4{list-style-type:none}.lst-kix_yreqa03lukup-2 > li:before{content:"❏ "}ul.lst-kix_yreqa03lukup-3{list-style-type:none}ul.lst-kix_yreqa03lukup-6{list-style-type:none}ul.lst-kix_yreqa03lukup-5{list-style-type:none}</style></head><body style="background-color:#ffffff;padding:72pt 72pt 72pt 72pt;max-width:451.3pt"><p style="padding:0;margin:0;color:#000000;font-size:11pt;font-family:"Arial";orphans:2;widows:2"><span>First Online edit : 15h50</span></p></body></html>
Of course, I want to display the generate html as the webpage, and not the string it's actually showing.