# HG changeset patch # User cmlenz # Date 1154105543 0 # Node ID 8b6bd2d920c15c86474de751aca07ef2510d53b9 # Parent f9473bdc93b2e97fbad4248f728ff826862411c0 Add example that shows how to transform an HTML document. diff --git a/examples/transform/README.txt b/examples/transform/README.txt new file mode 100644 --- /dev/null +++ b/examples/transform/README.txt @@ -0,0 +1,3 @@ +This example shows how to transform some HTML input, while adding +elements such as headers, and using / instead of /. +The output is that a proper XTHML document. diff --git a/examples/transform/index.html b/examples/transform/index.html new file mode 100644 --- /dev/null +++ b/examples/transform/index.html @@ -0,0 +1,24 @@ + + + Aaarrgh + + + + +

Aaargh

+

+ Lorem ipsum dolor sit amet, consectetur
+ adipisicing elit, sed do eiusmod tempor incididunt ut
+ labore et dolore magna aliqua. Ut enim ad minim veniam,
+ quis nostrud exercitation ullamco laboris nisi ut
+ aliquip ex ea commodo consequat. +

+

+ Duis aute irure dolor in reprehenderit in voluptate velit
+ esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
+ occaecat cupidatat non proident, sunt in culpa qui officia
+ deserunt mollit anim id est laborum. +

+ + + diff --git a/examples/transform/run.py b/examples/transform/run.py new file mode 100644 --- /dev/null +++ b/examples/transform/run.py @@ -0,0 +1,23 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +import os + +from markup.input import HTMLParser +from markup.template import Context, TemplateLoader + +def run(): + basepath = os.path.dirname(os.path.abspath(__file__)) + loader = TemplateLoader([basepath]) + html_filename = os.path.join(basepath, 'index.html') + html_fileobj = open(html_filename) + try: + html = HTMLParser(html_fileobj, html_filename) + tmpl = loader.load('template.xml') + print tmpl.generate(Context(input=html)).render('xhtml') + finally: + html_fileobj.close() + + +if __name__ == '__main__': + run() diff --git a/examples/transform/template.xml b/examples/transform/template.xml new file mode 100644 --- /dev/null +++ b/examples/transform/template.xml @@ -0,0 +1,22 @@ + + + + + + + ${select('*')} + + + + ${select('*|text()')} + ${select('*|text()')} + + + ${input} + +