[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] embed base64 encoded images in exported html
From: |
Eric Schulte |
Subject: |
Re: [O] embed base64 encoded images in exported html |
Date: |
Mon, 23 Apr 2012 12:35:41 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) |
Noah Hoffman <address@hidden> writes:
> Hello -
>
> I am trying to export a monolithic html file by embedding
> base64-encoded images, and I can't quite figure out how to prevent the
> output from being escaped in one way or another... here's an example
> of one permutation that doesn't do exactly what I want:
>
> #+BEGIN_SRC R :results output
> png('plot.png')
> plot(1:10)
> invisible(dev.off())
> list.files(pattern = '*.png')
> #+END_SRC
>
> #+RESULTS:
> : [1] "plot.png"
>
> #+BEGIN_SRC python :results output raw :exports results
> with open('plot.png', 'rb') as image:
> data = image.read()
> print '<img src="data:image/png;base64,%s">' % data.encode("base64")
> #+END_SRC
>
> #+RESULTS:
> <img
> src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeAAAAHgCAMAAABKCk6nAAACuFBMVEUAAAABAQEDAwMEBAQHBwcJ
> CQkKCgoMDAwNDQ0ODg4PDw8QEBARERESEhITExMUFBQVFRUWFhYXFxcYGBgZGRkaGhobGxscHBwf
> Hx8gICAhISEiIiIjIyMkJCQlJSUmJiYnJycoKCgqKiorKyssLCwtLS0uLi4vLy8wMDAxMTEyMjI0
> NDQ4ODg5OTk6Ojo7Ozs8PDw9PT0+Pj4/Pz9AQEBBQUFCQkJDQ0NERERFRUVGRkZHR0dISEhJSUlK
> SkpLS0tMTExNTU1OTk5PT09QUFBRUVFSUlJTU1NUVFRVVVVXV1dYWFhZWVlaWlpbW1tcXFxdXV1e
>
> <remainder truncated>
>
> Here the "results" block is not exposed as raw html in the exported
> file. Can anyone suggest how I might do this? I'm using emacs 23.4.1,
> org-mode 7.8.03
>
Hi Noah,
To include raw html in an Org-mode file you can use either the single
line #+HTML: escape or wrap it in a being/end html block, so adjusting
your example above would yield
#+BEGIN_SRC python :results output raw :exports results
with open('plot.png', 'rb') as image:
data = image.read()
print '#+HTML: <img src="data:image/png;base64,%s">' % data.encode("base64")
#+END_SRC
or
#+BEGIN_SRC python :results output html :exports results
with open('plot.png', 'rb') as image:
data = image.read()
print '<img src="data:image/png;base64,%s">' % data.encode("base64")
#+END_SRC
Best,
>
> Thanks a lot,
> Noah
>
--
Eric Schulte
http://cs.unm.edu/~eschulte/