# HG changeset patch # User cmlenz # Date 1149465823 0 # Node ID f9001cd6785b0f16b945afa920d9a27a7677fa99 # Parent 97423376736e44e3a70a861439d843c43e1a084f Match directives should now also be applied when included indirectly. For example, a match directive defined in `a.html`, which is included by `b.html`, which in turn is included by `c.html` should now also be applied to `c.html`. diff --git a/markup/filters.py b/markup/filters.py --- a/markup/filters.py +++ b/markup/filters.py @@ -87,13 +87,16 @@ _NAMESPACE = 'http://www.w3.org/2001/XInclude' - def __init__(self, loader): + def __init__(self, loader, template): """Initialize the filter. @param loader: the `TemplateLoader` to use for resolving references to external template files """ self.loader = loader + self.template = template + if not hasattr(template, '_included_filters'): + template._included_filters = [] def __call__(self, stream, ctxt=None, ns_prefixes=None): """Filter the stream, processing any XInclude directives it may @@ -138,9 +141,13 @@ # If the included template defines any filters added at # runtime (such as py:match templates), those need to be # applied to the including template, too. - for filter_ in template.filters: + filters = template.filters + template._included_filters + for filter_ in filters: stream = filter_(stream, ctxt) + # Runtime filters included need to be propagated up + self.template._included_filters += filters + except TemplateNotFound: if fallback_stream is None: raise diff --git a/markup/template.py b/markup/template.py --- a/markup/template.py +++ b/markup/template.py @@ -770,7 +770,7 @@ fileobj = file(filepath, 'rt') try: tmpl = Template(fileobj, filename=filepath) - tmpl.pre_filters.append(IncludeFilter(self)) + tmpl.pre_filters.append(IncludeFilter(self, tmpl)) finally: fileobj.close() self._cache[filename] = tmpl