From a9d17aa0ccff405caf18cac45341ebdfe52c4e62 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Tue, 7 Jan 2020 05:55:39 +0100 Subject: [PATCH] doc: add sphinx directives/roles for sub-cmd and modulefile cmd --- doc/source/conf.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doc/source/conf.py b/doc/source/conf.py index ee3bc686..491ef691 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -239,3 +239,31 @@ man_pages = [ # dir menu entry, description, category) texinfo_documents = [ ] + + +# -- Extension interface -------------------------------------------------- + +from sphinx import addnodes +def parse_cmd_args_node(env, sig, signode): + try: + cmd, args = sig.strip().split(' ', 1) + except ValueError: + cmd, args = sig, None + # distinguish cmd from its args + signode += addnodes.desc_name(cmd, cmd) + if args: + args = ' ' + args + signode += addnodes.desc_addname(args, args) + return cmd + +# define new directive/role that can be used as .. subcmd::/:subcmd: and +# .. mfcmd::/:mfcmd: +def setup(app): + app.add_object_type('subcmd', 'subcmd', + objname='module sub-command', + indextemplate='pair: %s; module sub-command', + parse_node=parse_cmd_args_node) + app.add_object_type(directivename='mfcmd', rolename='mfcmd', + objname='modulefile command', + indextemplate='%s (modulefile command)', + parse_node=parse_cmd_args_node)