2014-11-16 17:08:42 +00:00
|
|
|
# This file is dual licensed under the terms of the Apache License, Version
|
|
|
|
|
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
|
|
|
|
|
# for complete details.
|
2014-03-08 16:32:56 +00:00
|
|
|
|
2013-10-30 00:07:24 +00:00
|
|
|
from docutils import nodes
|
2018-02-13 15:31:05 +00:00
|
|
|
from docutils.parsers.rst import Directive
|
2013-10-30 00:07:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
DANGER_MESSAGE = """
|
|
|
|
|
This is a "Hazardous Materials" module. You should **ONLY** use it if you're
|
|
|
|
|
100% absolutely sure that you know what you're doing because this module is
|
2013-12-20 21:51:42 +00:00
|
|
|
full of land mines, dragons, and dinosaurs with laser guns.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
DANGER_ALTERNATE = """
|
|
|
|
|
|
|
|
|
|
You may instead be interested in :doc:`{alternate}`.
|
|
|
|
|
"""
|
|
|
|
|
|
2013-10-30 00:07:24 +00:00
|
|
|
|
|
|
|
|
class HazmatDirective(Directive):
|
2013-12-20 21:51:42 +00:00
|
|
|
has_content = True
|
|
|
|
|
|
2013-10-30 00:07:24 +00:00
|
|
|
def run(self):
|
2013-12-20 21:51:42 +00:00
|
|
|
message = DANGER_MESSAGE
|
|
|
|
|
if self.content:
|
|
|
|
|
message += DANGER_ALTERNATE.format(alternate=self.content[0])
|
|
|
|
|
|
2017-05-17 21:55:21 +00:00
|
|
|
content = nodes.paragraph("", message)
|
|
|
|
|
admonition_node = Hazmat("\n".join(content))
|
|
|
|
|
self.state.nested_parse(content, self.content_offset, admonition_node)
|
|
|
|
|
admonition_node.line = self.lineno
|
|
|
|
|
return [admonition_node]
|
2013-10-30 00:07:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Hazmat(nodes.Admonition, nodes.Element):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2013-11-19 22:06:18 +00:00
|
|
|
def html_visit_hazmat_node(self, node):
|
2013-10-30 00:07:24 +00:00
|
|
|
return self.visit_admonition(node, "danger")
|
|
|
|
|
|
|
|
|
|
|
2013-11-19 22:06:18 +00:00
|
|
|
def latex_visit_hazmat_node(self, node):
|
|
|
|
|
return self.visit_admonition(node)
|
|
|
|
|
|
|
|
|
|
|
2013-10-30 00:07:24 +00:00
|
|
|
def depart_hazmat_node(self, node):
|
|
|
|
|
return self.depart_admonition(node)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def setup(app):
|
|
|
|
|
app.add_node(
|
|
|
|
|
Hazmat,
|
2013-11-19 22:06:18 +00:00
|
|
|
html=(html_visit_hazmat_node, depart_hazmat_node),
|
|
|
|
|
latex=(latex_visit_hazmat_node, depart_hazmat_node),
|
2013-10-30 00:07:24 +00:00
|
|
|
)
|
|
|
|
|
app.add_directive("hazmat", HazmatDirective)
|
2017-09-20 14:14:56 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
"parallel_read_safe": True,
|
|
|
|
|
}
|