From af82d5eaeda02561b29adec38d40bf22c3a8e23b Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 29 Oct 2013 17:07:24 -0700 Subject: Made a sphinx extension which emits the hazardous materials danger admonition --- docs/cryptography-docs.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 docs/cryptography-docs.py (limited to 'docs/cryptography-docs.py') diff --git a/docs/cryptography-docs.py b/docs/cryptography-docs.py new file mode 100644 index 00000000..d6dc9d04 --- /dev/null +++ b/docs/cryptography-docs.py @@ -0,0 +1,46 @@ +from docutils import nodes + +from sphinx.util.compat import Directive, make_admonition + + +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 +full of land mines, dragons, and dinosaurs with laser guns. """ + +class HazmatDirective(Directive): + def run(self): + ad = make_admonition( + Hazmat, + self.name, + [], + self.options, + nodes.paragraph("", DANGER_MESSAGE), + self.lineno, + self.content_offset, + self.block_text, + self.state, + self.state_machine + ) + ad[0].line = self.lineno + return ad + + +class Hazmat(nodes.Admonition, nodes.Element): + pass + + +def visit_hazmat_node(self, node): + return self.visit_admonition(node, "danger") + + +def depart_hazmat_node(self, node): + return self.depart_admonition(node) + + +def setup(app): + app.add_node( + Hazmat, + html=(visit_hazmat_node, depart_hazmat_node) + ) + app.add_directive("hazmat", HazmatDirective) -- cgit v1.2.3