From 475f7a9603b76fe93962b4ef027f98b6d3eecc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0pa=C4=8Dek?= Date: Tue, 10 May 2022 16:00:57 +0200 Subject: [PATCH] Render optional statement metadata in the ARM Optional values :short: and :tags: are now rendered right after the statement heading. --- doc/arm/_ext/iscconf.py | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/doc/arm/_ext/iscconf.py b/doc/arm/_ext/iscconf.py index d1ec5702cb..4a09ee023d 100644 --- a/doc/arm/_ext/iscconf.py +++ b/doc/arm/_ext/iscconf.py @@ -34,6 +34,17 @@ from sphinx.util.nodes import make_refnode from sphinx.util.docutils import SphinxDirective +def split_csv(argument, required): + argument = argument or "" + outlist = list(filter(len, (s.strip() for s in argument.split(",")))) + if required and not outlist: + raise ValueError( + "a non-empty list required; provide at least one value or remove" + " this option" + ) + return outlist + + # pylint: disable=too-many-statements def domain_factory(domainname, domainlabel, todolist): """ @@ -72,7 +83,7 @@ def domain_factory(domainname, domainlabel, todolist): has_content = True required_arguments = 1 option_spec = { - "tags": directives.unchanged_required, + "tags": lambda arg: split_csv(arg, required=False), # one-sentece description for use in summary tables "short": directives.unchanged_required, } @@ -83,11 +94,27 @@ def domain_factory(domainname, domainlabel, todolist): def add_target_and_index(self, _name_cls, sig, signode): signode["ids"].append(domainname + "-statement-" + sig) - tags = [x.strip() for x in self.options.get("tags", "").split(",")] - short = self.options.get("short") iscconf = self.env.get_domain(domainname) - iscconf.add_statement(sig, tags, short) + iscconf.add_statement(sig, self.isc_tags, self.isc_short) + + @property + def isc_tags(self): + return self.options.get("tags", []) + + @property + def isc_short(self): + return self.options.get("short", "") + + def transform_content(self, contentnode: addnodes.desc_content) -> None: + """autogenerate content from structured data""" + if self.isc_short: + contentnode.insert(0, nodes.paragraph(text=self.isc_short)) + if self.isc_tags: + tags = nodes.paragraph() + tags += nodes.strong(text="Tags: ") + tags += nodes.Text(", ".join(self.isc_tags)) + contentnode.insert(0, tags) name = domainname label = domainlabel