comparison env/lib/python3.7/site-packages/docutils/transforms/components.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400 (2020-06-01)
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 # $Id: components.py 4564 2006-05-21 20:44:42Z wiemann $
2 # Author: David Goodger <goodger@python.org>
3 # Copyright: This module has been placed in the public domain.
4
5 """
6 Docutils component-related transforms.
7 """
8
9 __docformat__ = 'reStructuredText'
10
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
18
19
20 class Filter(Transform):
21
22 """
23 Include or exclude elements which depend on a specific Docutils component.
24
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.
34
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 """
41
42 default_priority = 780
43
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)