diff --git a/docs/plugins/3dveins.rst b/docs/plugins/3dveins.rst index 86a00b51c..f1149eb98 100644 --- a/docs/plugins/3dveins.rst +++ b/docs/plugins/3dveins.rst @@ -4,8 +4,6 @@ .. dfhack-tool:: :tags: fort, mod, map -.. dfhack-command:: - :dfhack-keybind:`3dveins` :index:`Rewrite layer veins to expand in 3D space. diff --git a/docs/sphinx_extensions/dfhack/tool_docs.py b/docs/sphinx_extensions/dfhack/tool_docs.py index 35e4de700..28876c36a 100644 --- a/docs/sphinx_extensions/dfhack/tool_docs.py +++ b/docs/sphinx_extensions/dfhack/tool_docs.py @@ -3,8 +3,10 @@ # https://www.sphinx-doc.org/en/master/development/tutorials/recipe.html # https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#rst-directives +from typing import List + import docutils.nodes as nodes -# import docutils.parsers.rst.directives as rst_directives +import docutils.parsers.rst.directives as rst_directives import sphinx import sphinx.addnodes as addnodes import sphinx.directives @@ -22,27 +24,31 @@ class DFHackToolDirectiveBase(sphinx.directives.ObjectDescription): else: return self.env.docname.split('/')[-1] - def make_labeled_paragraph(self, label, content, label_class=nodes.strong, content_class=nodes.inline): + @staticmethod + def make_labeled_paragraph(label, content, label_class=nodes.strong, content_class=nodes.inline) -> nodes.paragraph: return nodes.paragraph('', '', *[ label_class('', '{}: '.format(label)), content_class('', content), ]) - def make_nodes(self): + @staticmethod + def wrap_box(*children: List[nodes.Node]) -> nodes.Admonition: + return nodes.admonition('', *children, classes=['dfhack-tool-summary']) + + def render_content(self) -> List[nodes.Node]: raise NotImplementedError def run(self): - return [ - nodes.admonition('', *self.make_nodes(), classes=['dfhack-tool-summary']), - ] + return [self.wrap_box(*self.render_content())] class DFHackToolDirective(DFHackToolDirectiveBase): option_spec = { 'tags': dfhack.util.directive_arg_str_list, + 'no-command': rst_directives.flag, } - def make_nodes(self): + def render_content(self) -> List[nodes.Node]: tag_nodes = [nodes.strong(text='Tags: ')] for tag in self.options.get('tags', []): tag_nodes += [ @@ -62,9 +68,15 @@ class DFHackToolDirective(DFHackToolDirectiveBase): nodes.paragraph('', '', *tag_nodes), ] + def run(self): + out = DFHackToolDirectiveBase.run(self) + if 'no-command' not in self.options: + out += [self.wrap_box(*DFHackCommandDirective.render_content(self))] + return out + class DFHackCommandDirective(DFHackToolDirectiveBase): - def make_nodes(self): + def render_content(self) -> List[nodes.Node]: return [ self.make_labeled_paragraph('Command', self.get_name_or_docname(), content_class=nodes.literal), ]