If macro references is active output refuri always.
[docutils.git] / docutils / docutils / transforms / writer_aux.py
blob608fa07c62be4a9bf51ecefcb26f9acf4d0ae785
1 # $Id$
2 # Author: Lea Wiemann <LeWiemann@gmail.com>
3 # Copyright: This module has been placed in the public domain.
5 """
6 Auxiliary transforms mainly to be used by Writer components.
8 This module is called "writer_aux" because otherwise there would be
9 conflicting imports like this one::
11 from docutils import writers
12 from docutils.transforms import writers
13 """
15 __docformat__ = 'reStructuredText'
17 from docutils import nodes, languages
18 from docutils.transforms import Transform
21 class Admonitions(Transform):
23 """
24 Transform specific admonitions, like this:
26 <note>
27 <paragraph>
28 Note contents ...
30 into generic admonitions, like this::
32 <admonition classes="note">
33 <title>
34 Note
35 <paragraph>
36 Note contents ...
38 The admonition title is localized.
39 """
41 default_priority = 920
43 def apply(self) -> None:
44 language = languages.get_language(self.document.settings.language_code,
45 self.document.reporter)
46 for node in self.document.findall(nodes.Admonition):
47 node_name = node.__class__.__name__
48 # Set class, so that we know what node this admonition came from.
49 node['classes'].append(node_name)
50 if not isinstance(node, nodes.admonition):
51 # Specific admonition. Transform into a generic admonition.
52 admonition = nodes.admonition(node.rawsource, *node.children,
53 **node.attributes)
54 title = nodes.title('', language.labels[node_name])
55 admonition.insert(0, title)
56 node.replace_self(admonition)