2 # Author: Lea Wiemann <LeWiemann@gmail.com>
3 # Copyright: This module has been placed in the public domain.
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
15 __docformat__
= 'reStructuredText'
17 from docutils
import nodes
, languages
18 from docutils
.transforms
import Transform
21 class Admonitions(Transform
):
24 Transform specific admonitions, like this:
30 into generic admonitions, like this::
32 <admonition classes="note">
38 The admonition title is localized.
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
,
54 title
= nodes
.title('', language
.labels
[node_name
])
55 admonition
.insert(0, title
)
56 node
.replace_self(admonition
)