Embed Images, CSS, JS etc in a Single HTML File

Posted by:

Preamble

A single-file html presentation has been a welcome feature, Feature request: Export to single HTML · Issue #788. And org-reveal offers a convenient single-file option, but with Issues. Fortunately, there is a package called inliner converting a html file with everything inlined.

Convert the html to a single-file with inliner

What does inliner say about itself, adapted from remy/inliner: Node utility to inline images, CSS and JavaScript for a web page – useful for mobile sites ?

Turns your web page to a single HTML file with everything inlined.

What it does:

  1. Get a list of all the assets required to drive the page: CSS, JavaScript, images, videos and images used in CSS
  2. Minify JavaScript (via uglify-js)
  3. Strips white from CSS
  4. Base64 encode images and videos
  5. Puts everything back together as a single HTML file with a simplfied doctype

This method is applicable to any html file posthumous (not on-the-fly with org-reveal’s single-file option). So you have the liberty to use whatever method needed to achieve the desirable effects for presentation.

The following steps are for org-reveal export.

  1. generate a single-file html file with the following in Emacs org file.


  1. remove the file:// hard links, if any, in the script from the exported html file.
  2. Install the inliner utility via npm:


  3. convert the html file generated in step 1 to PDF with liner without compression using -n option.

    NOTES: --nocompress is crucial, also c true when using Markdown (https://github.com/hakimel/reveal.js/issues/788).


Other resources and notes

  1. Inliner with markdown conversion: hkdobrev/service-providers-slides: Slides for service providers presentation, more discussion Feature request: Export to single HTML · Issue #788 · hakimel/reveal.js.
  2. Another tool: html-inline – npm.
  3. convert html slides to PDF: GitHub – astefanutti/decktape: PDF exporter for HTML presentations issues: 774970 – Headless Print to PDF – entire image clipped when it overflows page – chromium
  4. PDF-export: PDF Export | reveal.js WORKS fine with normal reveal.js export with Chromium, NOT with the single-file version. Zoom out with Ctl+-, if needed, after appending ?print-pdf at the end of the url.
  5. Image embedding with base64: org mode – Embed Image as Base64 on HTML export from Orgmode – Emacs Stack Exchange.
  6. If you want Emacs org-mode export html (not just org-reveal) with inline images, use code from org-mode html export with inline images.


0

Add a Comment