HTML stylesheet expander?

Discussion in 'Python' started by Roger Binns, Nov 24, 2004.

  1. Roger Binns

    Roger Binns Guest

    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
     
    Roger Binns, Nov 24, 2004
    #1
    1. Advertising

  2. On Tue, 23 Nov 2004 19:51:08 -0800, Roger Binns <> wrote:
    > 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?

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/
     
    Simon Brunning, Nov 24, 2004
    #2
    1. Advertising

  3. Roger Binns

    Duncan Booth Guest

    Roger Binns wrote:

    > 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.
     
    Duncan Booth, Nov 24, 2004
    #3
  4. Roger Binns

    Roger Binns Guest

    "Duncan Booth" <> wrote in message news:Xns95AB5E981A615duncanrcpcouk@127.0.0.1...
    > 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
     
    Roger Binns, Nov 24, 2004
    #4
  5. Roger Binns

    Duncan Booth Guest

    Roger Binns wrote:

    >> 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.
    >


    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.
     
    Duncan Booth, Nov 24, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Ungerer

    Simple I2C slave model (IO expander)

    Alex Ungerer, Oct 3, 2003, in forum: VHDL
    Replies:
    1
    Views:
    2,812
    Paul Baxter
    Oct 3, 2003
  2. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    591
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  3. Steven An
    Replies:
    1
    Views:
    512
    Martin Honnen
    Nov 23, 2004
  4. David Blickstein
    Replies:
    3
    Views:
    1,052
    David Blickstein
    Aug 2, 2005
  5. David Blickstein
    Replies:
    14
    Views:
    6,376
    Harrie
    Oct 16, 2005
Loading...

Share This Page