Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline (with base64 data-uri) externally linked images and resolved path fix #16

Merged
merged 6 commits into from
Oct 10, 2017

Conversation

liuq
Copy link

@liuq liuq commented Oct 7, 2017

I succeeded in inlining also externally linked images (with ad-hoc code). Now they are rendered in a data:base64 uri that is inlined in the markdown (and eventually in the remark.js generated html).

Moreover, I fixed relative paths for export also in html template and sass style (if they do not need to be inlined).

The only added dependency is mime, which is already included by inliner. I didn't make it explicit in the package.json file, so feel free to do it.

sinedied and others added 5 commits October 7, 2017 15:31
…ed, i.e., if not inlined).

- Images included in the markdown (either as specified with markdown syntax or with the \<img\> tag) are now inlined in a data:base64 uri. This makes the output html file really self-contained.
@sinedied
Copy link
Owner

sinedied commented Oct 9, 2017

Thanks for the PR!

I have a few questions on this:

  • It only inline local images (file://) images from the markdown, right?
  • Why manually inline images/css in HTML? It should be taken care of by inliner?

@liuq
Copy link
Author

liuq commented Oct 10, 2017

In principle it downloads and inlines any kind of url (besides data:). Moreover, as for the <img> images in the markdown, if the source is included as a string in the call to remark.create(), inliner ignores it.

@sinedied
Copy link
Owner

sinedied commented Oct 10, 2017

In principle it downloads and inlines any kind of url (besides data:).

Did you try it with http resources? I think that fs.readFileSync only works with local files, not HTTP urls.

@liuq
Copy link
Author

liuq commented Oct 10, 2017

No, I admit I didn't. I will check whether it works also with http URLs but in case I will switch to the asynchronous file read (adapting the code).

If it is ok with you I will first proceed with sync including only file:/// urls and then I will take care of http.

@liuq
Copy link
Author

liuq commented Oct 10, 2017

Apparently it will not work with http urls, therefore I changed the regular expression so that now only images having file:/// urls will be inlined.

@sinedied
Copy link
Owner

Perfect!
By the way, you should add the email used in your git config to github (additional email adresses), so you can be listed on the project contributors list if you like. 😉

@sinedied sinedied merged commit fd581d3 into sinedied:master Oct 10, 2017
@liuq
Copy link
Author

liuq commented Oct 10, 2017

I did it, now I listed it on github config. :-)

Next PR of mine will include also the inline inclusion of external (http) Images! Keep in touch!

@sinedied
Copy link
Owner

If found an edge case on this, when using CSS or Remark statements directly in the markdown files (like background-image: url(./img/img.gif)) the images are not inlined. This should be easy to fix as the code is already there :)

@sinedied
Copy link
Owner

I just fixed that edge case and published a new 2.3.0 version with your changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants