Skip to content

Added HTML export #167

Closed
wants to merge 5 commits into from

3 participants

@markvoorhies

This is my first pass at adding HTML export to ipython. Here's the description that I'm
sending to ipython-dev:

I tried three approaches (available as three context menu options):

1) Export HTML (external PNGs):
This mimics Firefox's "Save as Web Page, complete" behavior.
Saving "mypath/test.htm" gives an HTML file with links to PNGs in
"mypath/test_files/". The PNGs are named relative to format.name()
to avoid collisions.

Works in Firefox 3.6.10, Konqueror 4.4.2/KHTML, and Konqueror 4.4.2/WebKit

2) Export HTML (inline PNGs):
Saves a single HTML file with images as inline base64 PNGs
(c.f. http://en.wikipedia.org/wiki/Data_URI_scheme#HTML)

Works in Firefox 3.6.10, Konqueror 4.4.2/KHTML, and Konqueror 4.4.2/WebKit

3) Export XHTML (inline SVGs):
Saves a single XHTML file with images as inline SVG. The "XML" is generated
by overwriting the Qt-generated document header, so it is not guaranteed to
be valid XML (but Firefox does validate my test case).

Works in Firefox 3.6.10 and Konqueror 4.4.2/WebKit.
Image placement is incorrect for Konqueror 4.4.2/KHTML.

(all tests run on a Dell Latitude D630 w/ Kubuntu Lucid:
mvoorhie@virgil:~$ uname -a
Linux virgil 2.6.32-24-generic #43-Ubuntu SMP Thu Sep 16 14:17:33 UTC 2010 i686 GNU/Linux)

It may be possible to link external SVG images via an or tag,
but I couldn't find a clean/portable way to do this.

Current issues:

  • I'm doing lots of string coercion in order to use re.sub on Qt's HTML. I mostly
    get away with it, but we wind up with a few bad character encodings in the
    output (e.g., the tabs for multi-line inputs). Would be good for someone who
    knows more about unicode to take a look at this...

  • The file name generation for "Export HTML (external PNGs)" is a bit hacky. Should
    probably be rewritten to use os.path.

  • Haven't tested with anything other than the Qt front end. In theory, other front
    ends will export HTML with the images stripped, unless they implement their own
    version of imagetag().

Feel free to take/hack what you like and ditch the rest.

Happy hacking,

--Mark

@markvoorhies markvoorhies Add HTML export options
Three export options (HTML w/ external PNGs, HTML w/ inline PNGs,
and XHTML w/ inline SVGs) are added to the context menu.
badeab1
@fperez

Is this method inherited from the parent Qt widget? If not, it should be named_with_underscores. We use PEP-8 names everywhere, except when overriding parent methods whose name we don't control.

Same applies to the rest below, I won't repeat it.

@fperez

Name image_tag? And does the format need to be all uppercased? If it's case insensitive, I'd prefer using 'png' for the format spec.

@fperez
IPython member
fperez commented Oct 11, 2010

Thanks a lot, Mark! I made some minor form comments, but I won't have time to give you more meaningful feedback or testing for a couple of days. But this looks great, and I promise to get back to it and test it.

One minor note: you may want to make a feature branch for this, in case it grows and your master picks up other things, so the html-print-specific work stays contained and we can review it in isolation. I think you can edit the source branch for the pull request after the fact. If not don't worry for this one, just keep it in mind for future proposals.

@ellisonbg
IPython member

Mark, this is a really nice go at this. I tested on my Mac with Firefox, Chrome and Safari and all worked fine for all formats. I do think we want all of these choices. The docstrings need to be cleaned up into our standard format. For examples, see a file like IPython/zmq/kernelmanager.py.

@markvoorhies

"One minor note: you may want to make a feature branch for this"

I've added a feature branch (htmlexport), but can't figure out how to switch the branch for the pull request
after the fact. I'll go ahead and have my master track htmlexport until this pull request is resolved (I'll
keep unrelated pulls on a separate local branch until then).

@markvoorhies markvoorhies Specify character encoding in HTML HEAD
This adds an explicit declaration of the UTF-8 character encoding
to the Qt generated HTML dump (since we've just explicitly requested
UTF-8 conversion from QString, this declaration should be correct),
c.f. http://www.w3.org/International/O-charset

This patch fixes incorrect characters (e.g., A-hat for tab) in, e.g.,
Firefox's default rendering of exported HTML.

Applying the same fix to both HTML and XHTML export even though
Firefox and WebKit appear to assume UTF-8 for XHTML even without
an explicit declaration.
f467f96
@markvoorhies

Hi Fernando,
I just pushed the UTF-8 fix that we discussed (f467f96). With this commit, the state of the pull request
branch (master == htmlexport) matches what I showed you at the Py4sci meeting.

@fperez
IPython member
fperez commented Oct 14, 2010

Merge branch 'master' of http://github.com/markvoorhies/ipython into markvoorhies-master

This adds HTML export of the entire buffer of the Qt console, with
option to save images either as inline PNG, PNGs in a separate folder,
or as inline SVG with all original metadata the SVG could have had
still intact.

Closed by aae8597 (pull request).

@jtriley jtriley pushed a commit to jtriley/ipython that referenced this pull request Jul 30, 2011
@fperez fperez Merge branch 'master' of http://github.com/markvoorhies/ipython into …
…markvoorhies-master

This adds HTML export of the entire buffer of the Qt console, with
option to save images either as inline PNG, PNGs in a separate folder,
or as inline SVG with all original metadata the SVG could have had
still intact.

Closes gh-167 (pull request).
aae8597
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
@fperez fperez Merge branch 'master' of http://github.com/markvoorhies/ipython into …
…markvoorhies-master

This adds HTML export of the entire buffer of the Qt console, with
option to save images either as inline PNG, PNGs in a separate folder,
or as inline SVG with all original metadata the SVG could have had
still intact.

Closes gh-167 (pull request).
09f0134
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.