aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRapptz <[email protected]>2017-09-21 21:15:37 -0400
committerRapptz <[email protected]>2017-09-21 21:15:37 -0400
commite3d69ce83ddb5d84c680e76a2b3efb21a2d46731 (patch)
treed8594060df149fdf67c0d9bacaa61436311cf101 /docs
parentMore CSS fixes. (diff)
downloaddiscord.py-e3d69ce83ddb5d84c680e76a2b3efb21a2d46731.tar.xz
discord.py-e3d69ce83ddb5d84c680e76a2b3efb21a2d46731.zip
Add custom details directive.
Diffstat (limited to 'docs')
-rw-r--r--docs/conf.py4
-rw-r--r--docs/extensions/details.py55
2 files changed, 58 insertions, 1 deletions
diff --git a/docs/conf.py b/docs/conf.py
index 436fcdfb..f0af548f 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -22,6 +22,7 @@ on_rtd = os.getenv('READTHEDOCS') == 'True'
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
+sys.path.append(os.path.abspath('extensions'))
# -- General configuration ------------------------------------------------
@@ -34,7 +35,8 @@ sys.path.insert(0, os.path.abspath('..'))
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.extlinks',
- 'sphinxcontrib.asyncio'
+ 'sphinxcontrib.asyncio',
+ 'details'
]
if on_rtd:
diff --git a/docs/extensions/details.py b/docs/extensions/details.py
new file mode 100644
index 00000000..96f39d5b
--- /dev/null
+++ b/docs/extensions/details.py
@@ -0,0 +1,55 @@
+from docutils.parsers.rst import Directive
+from docutils.parsers.rst import states, directives
+from docutils.parsers.rst.roles import set_classes
+from docutils import nodes
+
+class details(nodes.General, nodes.Element):
+ pass
+
+class summary(nodes.General, nodes.Element):
+ pass
+
+def visit_details_node(self, node):
+ self.body.append(self.starttag(node, 'details', CLASS=node.attributes.get('class', '')))
+
+def visit_summary_node(self, node):
+ self.body.append(self.starttag(node, 'summary', CLASS=node.attributes.get('summary-class', '')))
+ self.body.append(node.rawsource)
+
+def depart_details_node(self, node):
+ self.body.append('</details>\n')
+
+def depart_summary_node(self, node):
+ self.body.append('</summary>')
+
+class DetailsDirective(Directive):
+ final_argument_whitespace = True
+ optional_arguments = 1
+
+ option_spec = {
+ 'class': directives.class_option,
+ 'summary-class': directives.class_option,
+ }
+
+ has_content = True
+
+ def run(self):
+ set_classes(self.options)
+ self.assert_has_content()
+
+ text = '\n'.join(self.content)
+ node = details(text, **self.options)
+
+ if self.arguments:
+ summary_node = summary(self.arguments[0], **self.options)
+ summary_node.source, summary_node.line = self.state_machine.get_source_and_line(self.lineno)
+ node += summary_node
+
+ self.state.nested_parse(self.content, self.content_offset, node)
+ return [node]
+
+def setup(app):
+ app.add_node(details, html=(visit_details_node, depart_details_node))
+ app.add_node(summary, html=(visit_summary_node, depart_summary_node))
+ app.add_directive('details', DetailsDirective)
+