* Base 64 inline images in html export
@ 2015-12-07 12:15 Greg Sexton
2015-12-08 18:47 ` Rasmus
2015-12-23 1:48 ` Grant Rettke
0 siblings, 2 replies; 4+ messages in thread
From: Greg Sexton @ 2015-12-07 12:15 UTC (permalink / raw)
To: emacs-orgmode
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Base 64 inline images in html export
2015-12-07 12:15 Base 64 inline images in html export Greg Sexton
@ 2015-12-08 18:47 ` Rasmus
2015-12-23 1:48 ` Grant Rettke
1 sibling, 0 replies; 4+ messages in thread
From: Rasmus @ 2015-12-08 18:47 UTC (permalink / raw)
To: emacs-orgmode
Hi Greg,
Thanks for your patch.
Do you intend to finish the patch for inclusion in Org? If so please have
a look at:
http://orgmode.org/worg/org-contribute.html
In particular, you need to assign the copyright of your changes to FSF.
You might also want to familiarize yourself with how comments are done in
Emacs. In particular, they should be prose and informative.
Greg Sexton <gsexton@amazon.co.uk> writes:
> 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?
I think it would be great. But how about external pictures? It seems
these will not work with your patch. How about SVGs in external files?
If your goal if a self-containing html what about external JS and CSS?
> (defun gs/b64-img (file-uri)
> (let ((file (s-replace "file://" "" file-uri)))
> (if (f-exists? file)
This does not warrant new
> ;; src="data:image/png;base64,iVBORw0KGgoAAAANSUh..."
I don’t get the point of this comment.
> (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."
You are removing features from an existing function.
> (org-html-close-tag
> "img"
> (org-html--make-attribute-string
> (org-combine-plists
> (list :src (gs/b64-img source) ; <-- interesting line is here
The comment is no good.
> :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))
Rasmus
--
Not everything that goes around comes back around, you know
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Base 64 inline images in html export
2015-12-07 12:15 Base 64 inline images in html export Greg Sexton
2015-12-08 18:47 ` Rasmus
@ 2015-12-23 1:48 ` Grant Rettke
2015-12-23 2:04 ` John Kitchin
1 sibling, 1 reply; 4+ messages in thread
From: Grant Rettke @ 2015-12-23 1:48 UTC (permalink / raw)
To: Greg Sexton; +Cc: emacs-orgmode@gnu.org
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 <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 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.
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Base 64 inline images in html export
2015-12-23 1:48 ` Grant Rettke
@ 2015-12-23 2:04 ` John Kitchin
0 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2015-12-23 2:04 UTC (permalink / raw)
To: Grant Rettke; +Cc: emacs-orgmode@gnu.org, Greg Sexton
[-- Attachment #1: Type: text/plain, Size: 2976 bytes --]
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 <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-transportable-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 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.
> >
> >
>
>
[-- Attachment #2: Type: text/html, Size: 4609 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-12-23 2:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-07 12:15 Base 64 inline images in html export Greg Sexton
2015-12-08 18:47 ` Rasmus
2015-12-23 1:48 ` Grant Rettke
2015-12-23 2:04 ` John Kitchin
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.