Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 1 | from docutils import nodes |
| 2 | |
| 3 | from sphinx.util.compat import Directive, make_admonition |
| 4 | |
| 5 | |
| 6 | DANGER_MESSAGE = """ |
| 7 | This is a "Hazardous Materials" module. You should **ONLY** use it if you're |
| 8 | 100% absolutely sure that you know what you're doing because this module is |
| 9 | full of land mines, dragons, and dinosaurs with laser guns. """ |
| 10 | |
Alex Gaynor | b8be0e9 | 2013-10-29 18:10:03 -0700 | [diff] [blame] | 11 | |
Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 12 | class HazmatDirective(Directive): |
| 13 | def run(self): |
| 14 | ad = make_admonition( |
| 15 | Hazmat, |
| 16 | self.name, |
| 17 | [], |
| 18 | self.options, |
| 19 | nodes.paragraph("", DANGER_MESSAGE), |
| 20 | self.lineno, |
| 21 | self.content_offset, |
| 22 | self.block_text, |
| 23 | self.state, |
| 24 | self.state_machine |
| 25 | ) |
| 26 | ad[0].line = self.lineno |
| 27 | return ad |
| 28 | |
| 29 | |
| 30 | class Hazmat(nodes.Admonition, nodes.Element): |
| 31 | pass |
| 32 | |
| 33 | |
| 34 | def visit_hazmat_node(self, node): |
| 35 | return self.visit_admonition(node, "danger") |
| 36 | |
| 37 | |
| 38 | def depart_hazmat_node(self, node): |
| 39 | return self.depart_admonition(node) |
| 40 | |
| 41 | |
| 42 | def setup(app): |
| 43 | app.add_node( |
| 44 | Hazmat, |
| 45 | html=(visit_hazmat_node, depart_hazmat_node) |
| 46 | ) |
| 47 | app.add_directive("hazmat", HazmatDirective) |