rehtml: render html strings and ElementTrees

4 views
Skip to first unread message

Eduardo O. Padoan

unread,
Nov 15, 2007, 2:07:45 PM11/15/07
to reint...@googlegroups.com
I wrote an extension to render html strings and ElementTrees (or
ElementTree.Element) using gtkhtml2.
Is there any interest in adding DOM or beautfullsoup support to it?
And what about using gtkhtml2? Was this the best choice for such an
extension? Embeded Mozilla would be overkill, I think.
It does not support opening links or posting forms . It is not a
browser. But it could open links in the X/GNOME default browser, if
anyone think it is wort to implement it :)
Also, it doesnt *really* require ElementTree if all you want t do is
render html strings, and Python2.5 comes with it already.

Owen, can you take some minutes to review it? Thanks!

(If there is interest, I donate this code under the same licence of Reinteract.
BTW, what a wonderfull piece of code!)

--
http://www.advogato.org/person/eopadoan/
Bookmarks: http://del.icio.us/edcrypt

rehtml.py

Owen Taylor

unread,
Nov 15, 2007, 5:13:12 PM11/15/07
to reint...@googlegroups.com

Nice work! I could imagine using this as a "rendering engine" for
displaying structured data resulting from a computation with markup
and formatting.

Can you create:

http://ww.reinteract.org/trac/wiki/Extensions

And list it there?

There's one reason I don't think Reinteract is quite ready to have
this included with the distribution ... it doesn't handle ElementTree
very well. Look at the following sequence (this is in standard Python
interactive mode not in Reinteract, so as not to confuse things)

>>> import xml.etree.ElementTree as ET
>>> e = ET.Element("foo")
>>> import copy
>>> e2 = copy.copy(e)
>>> e.append(ET.Element("bar"))
>>> ET.tostring(e)
'<foo><bar /></foo>'
>>> ET.tostring(e2)
'<foo><bar /></foo>'

So actually, copy.copy() doesn't work as expected on
ElementTree.Element. And if we did work, we'd have a separate set of
problems. Here's what you would get in reinteract:

>>> e = ET.Element("foo")
>>> t = ET.ElementTree(e)
>>> e.append(ET.Element("bar"))
>>> print ET.tostring(e)
<foo><bar /></foo>
>>> print ET.tostring(t.getroot())
<foo></foo>

So, you'd need some ability to tell Reinteract "here's how you handle
xml.etree.ElementTree.Element". Actually, even with a hook like that,
it's still not obvious how to handle ElementTree.Element correctly,
since (unlike a DOM element) it has no parent pointer, so you can't
walk up and figure out what parent elements or element trees to copy.

I certainly expect people to find Reinteract useful in situations
where it can't manage to do the "re-edit" 100% properly, but for now
I'd like to emphasize the things where it can provide a more seamless
experience.

Other than that, the code in rehtml.py looks fine to me. I don't have
a strong opinion on the gtkhtml2 question ... my feeling on extensions
is that they can pull in lots of whacky dependencies (like sox, say
:-), and if those dependencies don't work for someone else, they can
write their own version or submit a patch.

- Owen

Eduardo O. Padoan

unread,
Nov 15, 2007, 7:40:36 PM11/15/07
to reint...@googlegroups.com
On Nov 15, 2007 8:13 PM, Owen Taylor <owta...@gmail.com> wrote:
> Nice work! I could imagine using this as a "rendering engine" for
> displaying structured data resulting from a computation with markup
> and formatting.

The first thing I thought when I saw the screencast was, "wow - It can
help me with my work!"

> Can you create:
>
> http://ww.reinteract.org/trac/wiki/Extensions
>
> And list it there?

Done.

Ok. I haven't noticed this problem, and I will study it a litle more,
as I think it is worth having a good re-edit experience with
Elemetree.Element, if I want to support it at all in the extension.

> Other than that, the code in rehtml.py looks fine to me. I don't have
> a strong opinion on the gtkhtml2 question ... my feeling on extensions
> is that they can pull in lots of whacky dependencies (like sox, say
> :-), and if those dependencies don't work for someone else, they can
> write their own version or submit a patch.

Agreed. Thank you for the feedback!

Reply all
Reply to author
Forward
0 new messages