souvikinator / notion-to-md

Convert notion pages, block and list of blocks to markdown (supports nesting and custom parsing)
https://www.npmjs.com/package/notion-to-md
MIT License
1.08k stars 89 forks source link

Create Feature image to base64 #81

Closed that-ambuj closed 1 year ago

that-ambuj commented 1 year ago

Hi @souvikinator, I have built the image link to base64 feature as we discussed in #60 with unit tests too but there are a few issues that I have faced:

I think it is understandable how base64 does not work with major markdown parsers because of how tricky and error prone this method of rendering images is(in case of point 2, it would produce a corrupted image, and the data is not guaranteed to be from an actual image) and the amount of challenge this feature produces is not worth the effort and a very small community trying to use this feature. Instead, I propose you that we work on temporary s3 links and already unsupported base64 data being emitted by this library.

souvikinator commented 1 year ago

the javascript code gets encoded to base64

That doesn't sound good and may lead to certain vulnerabilities. However I agree with your proposal, we can make it Notion's temporary s3 links exclusive and parse other links to regular markdown images syntax.

that-ambuj commented 1 year ago

Hi, the last two commits fix the base64 not being rendered by the markdown parsers and base64 images are now working. I'll also add a similar fix for the base64 data(coming from notion) that does not need conversion. To my surprise, the redirected images are now working as I've tested the base64 conversion with a picsum.photos link. I don't think there'll be any javascript embedded or executed in the base64 image data as node-fetch handles redirects very well.

that-ambuj commented 1 year ago

Hey @souvikinator, I've merged the latest changes in the feature branch. There are no merge conflicts, everything is tested and ready to merge!

that-ambuj commented 1 year ago

For reference, there is a page on MDN about everything you need to know about base64 images and data: prefixed urls: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs . Keep in mind this is a modern feature(with respect to IE) and the support for this is listed at the bottom of the aforementioned page.

souvikinator commented 1 year ago

Awesome! Thanks for the contribution. This really is an amazing feature. Should be live in upcoming major update.

that-ambuj commented 1 year ago

It was my pleasure to work on this project! I'm looking forward to adding many more features to this project which you'll see in the future issues and PRs that I open.

Please also update the issues mentioning this PR and #60.