Mercurial > genshi > genshi-test
annotate examples/transform/run.py @ 169:ce0bfdff334c
Fix syntax error in `path` module.
author | cmlenz |
---|---|
date | Fri, 18 Aug 2006 11:37:40 +0000 |
parents | 9cf42fb6b21e |
children | 24757b771651 |
rev | line source |
---|---|
107
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
1 #!/usr/bin/python |
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
3 |
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
4 import os |
108 | 5 import sys |
107
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
6 |
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
7 from markup.input import HTMLParser |
108 | 8 from markup.template import Context, Template |
107
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
9 |
108 | 10 def transform(html_filename, tmpl_filename): |
11 tmpl_fileobj = open(tmpl_filename) | |
12 tmpl = Template(tmpl_fileobj, tmpl_filename) | |
13 tmpl_fileobj.close() | |
14 | |
107
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
15 html_fileobj = open(html_filename) |
108 | 16 html = HTMLParser(html_fileobj, html_filename) |
17 print tmpl.generate(Context(input=html)).render('xhtml') | |
18 html_fileobj.close() | |
107
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
19 |
5a9b6e0aa3cc
Add example that shows how to transform an HTML document.
cmlenz
parents:
diff
changeset
|
20 if __name__ == '__main__': |
108 | 21 basepath = os.path.dirname(os.path.abspath(__file__)) |
22 tmpl_filename = os.path.join(basepath, 'template.xml') | |
23 html_filename = os.path.join(basepath, 'index.html') | |
24 transform(html_filename, tmpl_filename) |