I couple of years ago I wrote an HTML rendering library for Emacs so that I could read blogs in Gnus. And because I thought that Emacs should have a built-in method to display HTML. I mean, it was only about 20 years over-due.
Simple HTML Renderer (or shr, as the cool kids call it) was included in Emacs 24, and is based on the HTML capabilities of libxml2. So it parses HTML very quickly. The rendering, however, is in Emacs Lisp, so there’s a constant struggle between the impulse to IMPLEMENT IT ALL and not having it be so slow that you wouldn’t want to use it.
shr is fast enough to be usable on short, un-complicated pages. But point it to a page containing tables nested ten-deep, and it’s a dog. Mostly because I couldn’t come up with a table rendering algorithm that isn’t exponential. Or something.
So this Monday, I came up with the name of the browser while half-asleep: eww! I don’t quite know what the second w is supposed to stand for (Emacs Web Wowser?), but now that I had a name I just had to start programming.
It was only a couple day’s work (mostly implementing support), and here’s how eww renders the Wikipedia page on kittens, which we all consult daily. Probably.
Emacs has other, non-built-in browsers. I think the reason they haven’t been included are for copyright assignment reasons. But let’s compare.
Here’s emacs-w3m, which uses the external w3m program do generate a parse tree:
emacs-w3m is quite fast (much faster than shr on nested tables) and renders stuff nicely. The
Then there’s the venerable w3, which I only have for XEmacs. Let’s see how it does:
Oops. Perhaps it doesn’t like https links? Yup, the http version is better:
w3 is more fond of changing font size than both eww and emacs-w3m. My reasoning for disallowing font size changes is that Emacs has a pretty basic rendering model. If you have characters with different widths, lining stuff up is almost impossible. And since so many pages are table-based, it’s more important to make stuff readable than to vary text sizes and use different fonts. But perhaps shr could do font stuff outside of tables? There wouldn’t be much of an issue of lining stuff up outside of table contexts.
Anyway, there you go. There’s lots of stuff that could and possibly should be tweaked in eww (and shr), but I think it’s basically usable.
If you want to give it a twirl, the easiest (ahem) thing is probably to pull down the Emacs 24 bzr tree. Or, if you’re using Emacs 24, pull down the Gnus git tree. (I put it in the Gnus git repository, where it kinda doesn’t belong, but since shr is in there already, and they’re developed synchronously, it was easier to put it there. It’ll probably be removed from there after a while.)