From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Base 64 inline images in html export Date: Tue, 22 Dec 2015 21:04:26 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7bae465c4cf9a90527872474 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aBYmz-0006wU-2G for emacs-orgmode@gnu.org; Tue, 22 Dec 2015 21:04:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aBYmx-0006n1-Jw for emacs-orgmode@gnu.org; Tue, 22 Dec 2015 21:04:28 -0500 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]:33469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aBYmx-0006mb-AF for emacs-orgmode@gnu.org; Tue, 22 Dec 2015 21:04:27 -0500 Received: by mail-wm0-x235.google.com with SMTP id p187so128586709wmp.0 for ; Tue, 22 Dec 2015 18:04:27 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Grant Rettke Cc: "emacs-orgmode@gnu.org" , Greg Sexton --047d7bae465c4cf9a90527872474 Content-Type: text/plain; charset=UTF-8 I can't recall if I pointed to this post before: http://kitchingroup.cheme.cmu.edu/blog/2015/05/09/Another-approach-to-embedding-org-source-in-html/ but it is similar to what you are trying to do. John ----------------------------------- 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 On Tue, Dec 22, 2015 at 8:48 PM, Grant Rettke wrote: > Since you too are exploring packaging, this might give you some test: > > > http://kitchingroup.cheme.cmu.edu/blog/2014/03/05/Creating-a-transportable-zip-archive-of-an-org-file/ > Sincerely, > > Grant Rettke > > > On Mon, Dec 7, 2015 at 6:15 AM, Greg Sexton wrote: > > Hi, > > > > I did find a post about this from around 2009 but I'm not sure it went > > anywhere. It's very useful for me to be able to export a single html > > file that I can distribute around. Base 64 encoding images directly in > > to the exported html makes this possible. > > > > The feature seems fairly well supported by browsers these days.[1] > > > > I've hacked up this ugly proof of concept. I guess it wouldn't take too > > much to productionize this and make the behavior configurable. Any > > thoughts? > > > > --8<---------------cut here---------------start------------->8--- > > (defun gs/b64-img (file-uri) > > (let ((file (s-replace "file://" "" file-uri))) > > (if (f-exists? file) > > ;; src="data:image/png;base64,iVBORw0KGgoAAAANSUh..." > > (s-concat "data:image/" > > (f-ext file) > > ";base64," > > (base64-encode-string (f-read-bytes file))) > > file-uri))) > > > > (defun org-html--format-image (source attributes info) > > "Return \"img\" tag with given SOURCE and ATTRIBUTES. > > SOURCE is a string specifying the location of the image. > > ATTRIBUTES is a plist, as returned by > > `org-export-read-attribute'. INFO is a plist used as > > a communication channel." > > (org-html-close-tag > > "img" > > (org-html--make-attribute-string > > (org-combine-plists > > (list :src (gs/b64-img source) ; <-- interesting line is here > > :alt (if (string-match-p "^ltxpng/" source) > > (org-html-encode-plain-text > > (org-find-text-property-in-string 'org-latex-src > source)) > > (file-name-nondirectory source))) > > attributes)) > > info)) > > --8<---------------cut here---------------end--------------->8--- > > > > > > [1]: http://stackoverflow.com/questions/1207190/embedding-base64-images > > > > -- > > Greg > > > > > > > > Amazon Development Centre (London) Ltd. Registered in England and Wales > with registration number 04543232 and which has its registered office at > Leadenhall Court, One Leadenhall Street, London EC3V 1PP, United Kingdom. > > > > > > --047d7bae465c4cf9a90527872474 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I can't recall if I pointed to this post before:=C2=A0= http://kitchingroup.cheme.cmu.edu/blog= /2015/05/09/Another-approach-to-embedding-org-source-in-html/

<= /div>
but it is similar to what you are trying to do.

=
John

------------------------= -----------
Professor John Kitchin=C2=A0
Doherty Hall A207F
Depart= ment of Chemical Engineering
Carnegie Mellon University
Pittsburgh, P= A 15213
412-268-7803

On Tue, Dec 22, 2015 at 8:48 PM, Grant Rettk= e <gcr@wisdomandwonder.com> wrote:
Since you too are exploring packaging, this might give you= some test:

http://kitchingroup.cheme.cmu.edu/blog/2014/03/05/Creating-a-transportabl= e-zip-archive-of-an-org-file/
Sincerely,

Grant Rettke


On Mon, Dec 7, 2015 at 6:15 AM, Greg Sexton <gsexton@amazon.co.uk> wrote:
> Hi,
>
> I did find a post about this from around 2009 but I'm not sure it = went
> anywhere. It's very useful for me to be able to export a single ht= ml
> file that I can distribute around. Base 64 encoding images directly in=
> to the exported html makes this possible.
>
> The feature seems fairly well supported by browsers these days.[1]
>
> I've hacked up this ugly proof of concept. I guess it wouldn't= take too
> much to productionize this and make the behavior configurable. Any
> thoughts?
>
> --8<---------------cut here---------------start------------->8--= -
> (defun gs/b64-img (file-uri)
>=C2=A0 =C2=A0(let ((file (s-replace "file://" "" fi= le-uri)))
>=C2=A0 =C2=A0 =C2=A0(if (f-exists? file)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0;; src=3D"data:image/png;base64,= iVBORw0KGgoAAAANSUh..."
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(s-concat "data:image/"
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(f= -ext file)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0&q= uot;;base64,"
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(b= ase64-encode-string (f-read-bytes file)))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0file-uri)))
>
> (defun org-html--format-image (source attributes info)
>=C2=A0 =C2=A0"Return \"img\" tag with given SOURCE and A= TTRIBUTES.
> SOURCE is a string specifying the location of the image.
> ATTRIBUTES is a plist, as returned by
> `org-export-read-attribute'.=C2=A0 INFO is a plist used as
> a communication channel."
>=C2=A0 =C2=A0(org-html-close-tag
>=C2=A0 =C2=A0 "img"
>=C2=A0 =C2=A0 (org-html--make-attribute-string
>=C2=A0 =C2=A0 =C2=A0(org-combine-plists
>=C2=A0 =C2=A0 =C2=A0 (list :src (gs/b64-img source)=C2=A0 =C2=A0; <-= - interesting line is here
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :alt (if (string-match-p &quo= t;^ltxpng/" source)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(org-html-encode-plain-text
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (org-find-text-property-in-string 'org-latex-src source))
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(f= ile-name-nondirectory source)))
>=C2=A0 =C2=A0 =C2=A0 attributes))
>=C2=A0 =C2=A0 info))
> --8<---------------cut here---------------end--------------->8--= -
>
>
> [1]: http://stackoverflow.com= /questions/1207190/embedding-base64-images
>
> --
>=C2=A0 Greg
>
>
>
> Amazon Development Centre (London) Ltd. Registered in England and Wale= s with registration number 04543232 and which has its registered office at = Leadenhall Court, One Leadenhall Street, London EC3V 1PP, United Kingdom. >
>


--047d7bae465c4cf9a90527872474--