annotate examples/transform/run.py @ 113:d10fbba1d5e0 trunk

Removed the `sanitize()` method from the `Markup` class, and migrate the existing unit tests to `markup.tests.filters`. Provide a `Stream.filter()` method instead which can be used to conveniently apply a filter to a stream.
author cmlenz
date Mon, 31 Jul 2006 23:00:06 +0000
parents 61f58e3a123d
children 84168828b074
rev   line source
107
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
1 #!/usr/bin/python
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
2 # -*- coding: utf-8 -*-
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
3
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
4 import os
108
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
5 import sys
107
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
6
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
7 from markup.input import HTMLParser
108
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
8 from markup.template import Context, Template
107
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
9
108
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
10 def transform(html_filename, tmpl_filename):
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
11 tmpl_fileobj = open(tmpl_filename)
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
12 tmpl = Template(tmpl_fileobj, tmpl_filename)
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
13 tmpl_fileobj.close()
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
14
107
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
15 html_fileobj = open(html_filename)
108
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
16 html = HTMLParser(html_fileobj, html_filename)
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
17 print tmpl.generate(Context(input=html)).render('xhtml')
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
18 html_fileobj.close()
107
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
19
8b6bd2d920c1 Add example that shows how to transform an HTML document.
cmlenz
parents:
diff changeset
20 if __name__ == '__main__':
108
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
21 basepath = os.path.dirname(os.path.abspath(__file__))
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
22 tmpl_filename = os.path.join(basepath, 'template.xml')
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
23 html_filename = os.path.join(basepath, 'index.html')
61f58e3a123d Minor improvements to transform example.
cmlenz
parents: 107
diff changeset
24 transform(html_filename, tmpl_filename)
Copyright (C) 2012-2017 Edgewall Software