emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Xebar Saram <zeltakc@gmail.com>
Cc: org mode <emacs-orgmode@gnu.org>
Subject: Re: export to single html file (like reveal_single_file:t) in regular html export
Date: Sat, 26 Nov 2016 07:56:13 -0500	[thread overview]
Message-ID: <m2vavapfgy.fsf@Johns-MacBook-Air.local> (raw)
In-Reply-To: <CAOQHXPoC67qJ_JqJOLj7fe=P=mENJDos2Luo4WQakooLNCEvaA@mail.gmail.com>

Here is some code lightly modified from a comment by Evgeny here:
http://kitchingroup.cheme.cmu.edu/blog/2016/10/29/Sending-html-emails-from-org-mode-with-org-mime/

It seems to do what you want. Of course, I only tested it with one
image, one time, so I hope it works for you too! It assumes png, but it
would not be too hard to generalize.

#+BEGIN_SRC emacs-lisp
(defun org-image-data-uri (path)
  (let ((data (with-temp-buffer (insert-file-contents path) (buffer-string))))
    (concat "<img src=\"" 
            "data:image/png;charset=utf-8;base64,"
	    (base64-encode-string (encode-coding-string data 'binary) t)
	    "\"/>")))

(defun my-link (link contents info)
  (let ((type (org-element-property :type link))
	(path (org-element-property :path link)))
    (if (and (string= type "file")
	     (f-ext? path "png"))
	(org-image-data-uri path)
      (org-html-link link contents info))))

(org-export-define-derived-backend 'my-html 'html
  :translate-alist '((link . my-link)))

(browse-url (org-export-to-file 'my-html "embedded-image.html"))
#+END_SRC

Xebar Saram writes:

> ping anyone :) gotta prepare new assignments for students next week :)
>
> On Sat, Nov 19, 2016 at 7:46 AM, Xebar Saram <zeltakc@gmail.com> wrote:
>
>> Hi all
>>
>> i love the option in org revel (reveal_single_file:t) that allows me to
>> export a presentation to my students with image support embedded in the
>> html file./
>>
>> ive searched for a way to do it in the normal org to html exporter with no
>> success. any clue how that can be done?
>>
>> best
>>
>> Z
>>


-- 
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

      reply	other threads:[~2016-11-26 12:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-19  5:46 export to single html file (like reveal_single_file:t) in regular html export Xebar Saram
2016-11-26  6:44 ` Xebar Saram
2016-11-26 12:56   ` John Kitchin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2vavapfgy.fsf@Johns-MacBook-Air.local \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=zeltakc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).