view 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
line wrap: on
line source
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys

from markup.input import HTMLParser
from markup.template import Context, Template

def transform(html_filename, tmpl_filename):
    tmpl_fileobj = open(tmpl_filename)
    tmpl = Template(tmpl_fileobj, tmpl_filename)
    tmpl_fileobj.close()

    html_fileobj = open(html_filename)
    html = HTMLParser(html_fileobj, html_filename)
    print tmpl.generate(Context(input=html)).render('xhtml')
    html_fileobj.close()

if __name__ == '__main__':
    basepath = os.path.dirname(os.path.abspath(__file__))
    tmpl_filename = os.path.join(basepath, 'template.xml')
    html_filename = os.path.join(basepath, 'index.html')
    transform(html_filename, tmpl_filename)
Copyright (C) 2012-2017 Edgewall Software