HTML stylesheet expander?

R

Roger Binns

Does anyone have any code or pointers to something
that can take some HTML with CSS style information
and expand it into HTML that works pre-CSS.

For example, say I had a style like this:

.citation { font-style: italic }

And had HTML like this:

<p class="citation>foo bar</p>

Then the results produced are:

<p><i>foo bar</i></p>

This does get somewhat complicated as the styles can be
"nested", apply to contained elements, expand to attributes
or new tags etc.

I generate the HTML and "own" the stylesheets.

The reason behind this is that the wxWidgets HTML control
doesn't support styles, and so something like this has to
be done to get the same kind of effect.

I do have a current solution that uses HTMLParser and
hierarchical style information that works, but really don't
like it. It requires every HTML tag to be perfectly closed
and is very hacky.

There is talk on the wxPython group of using Mozilla or KHTML
but these aren't available on Windows, Linux and Mac, and/or
you get an entire tabbed browser etc in the deal.

Roger
 
S

Simon Brunning

Does anyone have any code or pointers to something
that can take some HTML with CSS style information
and expand it into HTML that works pre-CSS.

I'm not sure such a thing would be possible. You could convert some
CSS styling into roughly equivalent HTML, but you can do things with
CSS that simply aren't possible with HTML alone. What would you expect
to be done with that?
 
D

Duncan Booth

Roger said:
Does anyone have any code or pointers to something
that can take some HTML with CSS style information
and expand it into HTML that works pre-CSS.

It can't be done in general since CSS has far more control over the styling
than HTML ever gave you. However, if you are willing to restrict yourself
to simple cases I would suggest you might be best loading the HTML into a
browser and manipulating it there to find out what styles everything has.

If you are using Windows then there is no problem: just drive IE remotely
through COM and use Python to iterate over the document and pick out the
runtime style attributes that you are interested in.

If you are not using Windows, or you want portability, then you are
probably best doing this in Javascript.
 
R

Roger Binns

Duncan Booth said:
to simple cases I would suggest you might be best loading the HTML into a
browser and manipulating it there to find out what styles everything has.

This is in a program that runs on Windows, Linux and Mac and I am
generating the HTML, and supply the stylesheet.
If you are using Windows then there is no problem: just drive IE remotely
through COM and use Python to iterate over the document and pick out the
runtime style attributes that you are interested in.

My problem is that I want to display the HTML in the HTML widget
supplied with wxPython (which doesn't understand styles). If I
could use a different widget then that is fine, but at the moment
there are no alternatives (short of me spending many months of
working porting something to wxWidgets).
If you are not using Windows, or you want portability, then you are
probably best doing this in Javascript.

How exactly would I do that? There is no Javascript in Python and if
I had a way of displaying HTML then this is a non-issue.

Have a look at this screenshot: http://bitpim.org/screenshots/phonebook.jpg

The green backgrounded pane on the right is the wxPython HTML widget and
I use my current hacky scheme to apply styles for the various areas.

Roger
 
D

Duncan Booth

Roger said:
How exactly would I do that? There is no Javascript in Python and if
I had a way of displaying HTML then this is a non-issue.

What I meant was that you do the conversion once and then use the converted
HTML in your program. Obviously if I misunderstood and the HTML is
dynamically generated that won't be possible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top