Edgewall Software

Changes between Version 5 and Version 6 of GenshiRecipes/HtmlTransform


Ignore:
Timestamp:
Jul 5, 2007, 3:45:54 PM (12 years ago)
Author:
athomas
Comment:

Chris's cleanups

Legend:

Unmodified
Added
Removed
Modified
  • GenshiRecipes/HtmlTransform

    v5 v6  
    132132from genshi.filters.transform import Transformer
    133133
    134 
    135 header = tag.div(tag.img(src="logo.png", alt="Bad Style"), id="header")
    136 
    137 insert_header = Transformer('body').prepend(header).end()
    138 apply_strong = Transformer('body//b').unwrap().wrap('strong').end()
    139 apply_em = Transformer('body//i').unwrap().wrap('em').end()
    140 
    141 
    142134def transform(html_filename):
    143135    html_fileobj = open(html_filename)
    144136    html_parser = HTMLParser(html_fileobj, html_filename)
    145137    html_stream = html_parser.parse()
    146     transformed_stream = html_stream | insert_header | apply_strong | apply_em
     138    transformed_stream = html_stream | Transformer('body') \
     139        .prepend(tag.div(
     140            tag.img(src="logo.png", alt="Bad Style"),
     141            id="header")) \
     142        .select('.//b').unwrap().wrap('strong').end() \
     143        .select('.//i').unwrap().wrap('em')
     144
    147145    print transformed_stream.render('xhtml', doctype='html')
    148146    html_fileobj.close()
     
    150148
    151149if __name__ == '__main__':
    152     transform(sys.argv[1])
     150    transform(sys.argv[1])}}}
    153151}}}
    154152