simov / markdown-viewer

Markdown Viewer / Browser Extension
MIT License
1.05k stars 133 forks source link

file on google drive #113

Closed iplasma closed 1 year ago

iplasma commented 4 years ago

File stored on google drive can be downloaded from link like this

https://drive.google.com/uc?export=download&id=FILEID

I tried to use this for path matching

\/uc\?export\=download&id\=(.*?)$

but Chrome still prompted to download the file instead.

Any idea why?

simov commented 4 years ago

The Google Drive server sets specific headers to instruct the browser that the file have to be downloaded. The path matching regexp and the extension in general, only works when the browser opens up the raw markdown file in a tab.

iplasma commented 4 years ago

Yes, found out this too. With other extension, such as Modify Content-Type, I was able to view the file in browser. Another trick is that the URL above will lead to multiple redirections, this tip below is helpful as there is no redirection when export to txt.

https://learninginhand.com/blog/google-document-url-tricks

But, if this extension can handle the content-type, that will be fantastic!

simov commented 4 years ago

Actually the content-disposition header have to be removed.

Once you load https://drive.google.com/uc?export=download&id= the browser redirects to https://doc-00-2g-docs.googleusercontent.com/... so for that response the content-disposition have to be stripped resulting in the browser rendering the raw markdown file instead of prompting to download it. At that stage a correct path matching regexp will be able to pick it up and render it as HTML.

However I don't think such functionality like removing arbitrary headers from arbitrary sites is in the scope for this extension. Probably a combination between extension that removes headers and this one is going to work, the only question in this case is how are you going to guarantee that the extension that removes the header will be executed before the markdown viewer one.