Website: add template and basic stylesheet with menu. Update buildhtml.py (and theref...
[docutils.git] / sandbox / gitpull / web_stylesheet_and_menu / docutils / transforms / components.py
bloba8a190dad6e99d2be28064eb53ff4fa6ff33e5f8
1 # $Id$
2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
5 """
6 Docutils component-related transforms.
7 """
9 __docformat__ = 'reStructuredText'
11 import sys
12 import os
13 import re
14 import time
15 from docutils import nodes, utils
16 from docutils import ApplicationError, DataError
17 from docutils.transforms import Transform, TransformError
20 class Filter(Transform):
22 """
23 Include or exclude elements which depend on a specific Docutils component.
25 For use with `nodes.pending` elements. A "pending" element's dictionary
26 attribute ``details`` must contain the keys "component" and "format". The
27 value of ``details['component']`` must match the type name of the
28 component the elements depend on (e.g. "writer"). The value of
29 ``details['format']`` is the name of a specific format or context of that
30 component (e.g. "html"). If the matching Docutils component supports that
31 format or context, the "pending" element is replaced by the contents of
32 ``details['nodes']`` (a list of nodes); otherwise, the "pending" element
33 is removed.
35 For example, the reStructuredText "meta" directive creates a "pending"
36 element containing a "meta" element (in ``pending.details['nodes']``).
37 Only writers (``pending.details['component'] == 'writer'``) supporting the
38 "html" format (``pending.details['format'] == 'html'``) will include the
39 "meta" element; it will be deleted from the output of all other writers.
40 """
42 default_priority = 780
44 def apply(self):
45 pending = self.startnode
46 component_type = pending.details['component'] # 'reader' or 'writer'
47 format = pending.details['format']
48 component = self.document.transformer.components[component_type]
49 if component.supports(format):
50 pending.replace_self(pending.details['nodes'])
51 else:
52 pending.parent.remove(pending)