Noah Hoffman <noah.hoff...@gmail.com> 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/

Reply via email to