From: Eric Schulte <eric.schulte@gmx.com>
To: Noah Hoffman <noah.hoffman@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: embed base64 encoded images in exported html
Date: Mon, 23 Apr 2012 12:35:41 -0400 [thread overview]
Message-ID: <878vhmxv6q.fsf@gmx.com> (raw)
In-Reply-To: <CANZRKX12qf+Q-3k2JVi0TUzC8DKYBCHjrFrD4hnm2mfZt1VZ9A@mail.gmail.com> (Noah Hoffman's message of "Mon, 23 Apr 2012 10:33:24 -0700")
Noah Hoffman <noah.hoffman@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/
next prev parent reply other threads:[~2012-04-23 18:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-23 17:33 embed base64 encoded images in exported html Noah Hoffman
2012-04-23 16:35 ` Eric Schulte [this message]
2012-04-23 18:48 ` Noah Hoffman
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=878vhmxv6q.fsf@gmx.com \
--to=eric.schulte@gmx.com \
--cc=emacs-orgmode@gnu.org \
--cc=noah.hoffman@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).