evbacher / gd2md-html

Convert a Google Doc to Markdown or HTML. This Docs add-on converts a Google Doc to simple Markdown and/or HTML.
Apache License 2.0
653 stars 58 forks source link

Names of images in markdown #49

Open JonathanCrossland opened 5 years ago

JonathanCrossland commented 5 years ago

Hi. thanks for working on this :)

When you export to HTML from google docs, they name the files image1.jpg, image2.jpg etc. We get a nice folder of images.

If you output ![images/image1.jpg] - etc instead of title + index + jpg, it would make life a lot easier when mapping image files.

we could simply copy the folder into the relative path and it should work.

if you then suppress all the error warning, it would help us make this process a bit cleaner.. what do you think?

evbacher commented 5 years ago

Yes, that's a good suggestion. I can change the way the image link is output.

It is possible to save the image files, but that requires excessive permissions.

JonathanCrossland commented 5 years ago

excessive permissions would be bad, I agree and thanks for considering the change.

SergiosKar commented 4 years ago

+1 on changing the name. it will indeed make the mapping much much easier

evbacher commented 4 years ago

I can easily change the name. However, the order of the images in the zip file is not the same as the order in the Google Doc. So there may be some manual rejiggering required, unless there's some obvious but as-yet undiscovered scheme for ordering the images in the zip file.

hllorens commented 4 years ago

Hi, this seems a great addon, but for me to be useful I need the original images (the path can just be the original one pointing to google server)

evbacher commented 4 years ago

As of today's update (1.0β25), the image path is now in the form images/image1.png, images/image2.jpg, etc. However, beware that the exported zip file from Google Docs does not always have the images in the same order, so you'll still need to check that the images are referenced in the correct place in your converted doc. There does not seem to be any rhyme nor reason about the order in the exported zip file that you get from Download > Web Page.

SergiosKar commented 4 years ago

fyi I'm 90% sure that the order of the exported images is the same with the order that they been added to the docs.. not sure if there is something you can do about though

evbacher commented 4 years ago

I wish this were so, but I just tested it again: I added 4 images, and they came out in the zip file as image1, image2, image4, image3. I've only done a few experiments, but each time I've seen them come out in a different order than they appear in the doc (and in this case, I made sure to add them in that order, top to bottom of the doc). So, it looks like you'll still need to proofread the doc to make sure you get the images in the right spots.

SergiosKar commented 4 years ago

oooh. it just looks so weird that google has enforced no order in that.. anyway thanks for spending time on it

sjovanovic commented 2 years ago

This issue should be open. It basically downgrades the entire add-on to a toy.

evbacher commented 2 years ago

If you find out the scheme that Google uses to name the images (it's not the order in the Doc), let me know and we can fix that. Otherwise, I don't know of any way to guarantee that the image names correspond to the correct images as Google exports them into the zip file.

evbacher commented 2 years ago

Reopening in hopes that Google will (someday) export the images in a reproducible order.

sjovanovic commented 2 years ago

Thanks for reopening.

I don't think Google cares about this. Random order is probably side effect of some optimization. Better bet in my opinion is to create a zip from within the script. Something like this...

In your gdc.handleImage function add inline image blobs inside of a global array i.e.:

imgBlob.setName('image' + gdc.imageCounter + fileType)
if(!Array.isArray(gdc.imageBlobList)) gdc.imageBlobList = []
gdc.imageBlobList.push(imgBlob)

Then after everything is done, create a ZIP file and save to Drive i.e.:

let zip = Utilities.zip(gdc.imageBlobList);
let newFile = DriveApp.createFile(zip, "inline_images.zip");

Also, I wonder if just setting imgBlob.setName('image' + gdc.imageCounter + fileType) would affect google's export to name the files accordingly.

evbacher commented 2 years ago

The original version of this did export images to a zip file stored in Drive, but it requires very intrusive permssions (read all Drive files, write to Drive) that most people do not want to grant to an add-on. So I'm not planning to do that. It would be possible to do in a separate add-on, but it would still require lots of permissions.

I will check out your suggestion that imgBlob.setName might affect Google's export to name the files in the correct order (though I doubt it).