From f80ed46bdda21c2bfc6c6fbeb1b1999372a366cd Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Sun, 3 Sep 2023 13:02:30 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20creation=20of=20need=20tit?= =?UTF-8?q?le=20nodes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the logic was mistakenly looping over every character of the string, and so creating a `Text` node per character, rather than a single `Text` node for the full title string. --- sphinx_needs/layout.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/sphinx_needs/layout.py b/sphinx_needs/layout.py index b8547b28a..4bc206285 100644 --- a/sphinx_needs/layout.py +++ b/sphinx_needs/layout.py @@ -493,7 +493,6 @@ def meta(self, name: str, prefix: Optional[str] = None, show_empty: bool = False :param show_empty: If false and requested need-value is None or '', no output is returned. Default: false :return: docutils node """ - data_container = nodes.inline(classes=["needs_" + name]) if prefix: prefix_node = self._parse(prefix) @@ -513,16 +512,16 @@ def meta(self, name: str, prefix: Optional[str] = None, show_empty: bool = False if isinstance(data, str): if len(data) == 0 and not show_empty: return [] - # data_node = nodes.inline(classes=["needs_data"]) - # data_node.append(nodes.Text(data) - # data_container.append(data_node) + needs_string_links_option: List[str] = [] for v in self.needs_config.string_links.values(): needs_string_links_option.extend(v["options"]) - if name in needs_string_links_option: - data = re.split(r",|;", data) - data = [i.strip() for i in data if len(i) != 0] + data_list: List[str] = ( + [i.strip() for i in re.split(r",|;", data) if len(i) != 0] + if name in needs_string_links_option + else [data] + ) matching_link_confs = [] for link_conf in self.string_links.values(): @@ -530,7 +529,7 @@ def meta(self, name: str, prefix: Optional[str] = None, show_empty: bool = False matching_link_confs.append(link_conf) data_node = nodes.inline(classes=["needs_data"]) - for index, datum in enumerate(data): + for index, datum in enumerate(data_list): if matching_link_confs: data_node += match_string_link( text_item=datum, @@ -544,7 +543,7 @@ def meta(self, name: str, prefix: Optional[str] = None, show_empty: bool = False ref_item = nodes.Text(datum) data_node += ref_item - if (isinstance(data, list) and index + 1 < len(data)) or index + 1 < len([data]): + if (name in needs_string_links_option and index + 1 < len(data)) or index + 1 < len([data]): data_node += nodes.emphasis("; ", "; ") data_container.append(data_node)