From ccc90ab1f3bff87ec43864ccbfab5d7bfaaa7bb6 Mon Sep 17 00:00:00 2001 From: Camille <78221213+clatapie@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:31:17 +0100 Subject: [PATCH] fix: enabling bold emphasis --- src/pyconverter/xml2py/ast_tree.py | 41 +++++++++++++++++++----------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/pyconverter/xml2py/ast_tree.py b/src/pyconverter/xml2py/ast_tree.py index c734454ec..8b2a68b88 100644 --- a/src/pyconverter/xml2py/ast_tree.py +++ b/src/pyconverter/xml2py/ast_tree.py @@ -738,7 +738,10 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No ) items.append(rst_item) - return "\n".join(items) + + rst_list_item = "\n".join(items) + rst_list_item = rst_list_item.replace("*", "\*") + return rst_list_item class FileName(Element): @@ -889,7 +892,7 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None): if self.role == "bold": # TODO: this isn't the correct way of making text bold - content = f"{self[0]} " + content = f"**{self[0]}** " elif self.role == "italic": # TODO: this isn't the correct way of making text itallic content = f"{self[0]} " @@ -1074,7 +1077,8 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No ) active_items.append(rst_item) - return "\n".join(active_items) + "\n" + rst_varlist = "\n".join(active_items) + "\n" + return rst_varlist @property def terms(self): @@ -1107,7 +1111,8 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No items.append(item.to_rst(indent=indent)) else: items.append(str(item)) - return "\n".join(items) + rst_refsection = "\n".join(items) + return rst_refsection class VarlistEntry(Element): @@ -1247,7 +1252,8 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No py_term = self.py_term(links=links, base_url=base_url) if "``" in py_term: py_term = py_term.replace("``", "") - lines = [f"* ``{py_term}`` - {self.py_text(links=links, base_url=base_url, fcache=fcache)}"] + py_text = self.py_text(links=links, base_url=base_url, fcache=fcache) + lines = [f"* ``{py_term}`` - {py_text}"] text = "\n".join(lines) # if 'ID number to which this tip belongs' in text: # breakpoint() @@ -1666,7 +1672,8 @@ def to_rst(self, indent="", links=None, base_url=None): if len(rst_tbody) > 0: rows += rst_tbody - return "\n".join(rows) + rst_tgroup = "\n".join(rows) + return rst_tgroup class Table(Element): @@ -2121,7 +2128,8 @@ def to_rst(self, l_head, indent="", links=None, base_url=None): if type(row[1][0]) == Command: command = f" * - :ref:`{row[1][0].py_cmd}`" rst_rows.append(command) - strg = " - " + str(row[2][0]) + row_content = str(row[2][0]) + strg = f" - {row_content}" rst_rows.append(strg) return rst_rows @@ -2145,11 +2153,14 @@ def to_rst(self, indent="", links=None, base_url=None, fcache=None): for item in self: if isinstance(item, Element): if item.tag in item_needing_links_base_url: - items.append(item.to_rst(indent, links=links, base_url=base_url)) + entry_item = item.to_rst(indent, links=links, base_url=base_url) else: - items.append(item.to_rst(indent)) + entry_item= item.to_rst(indent) else: - items.append(str(item)) + entry_item = str(item) + # entry_item = entry_item.replace("*", "\*") + + items.append(entry_item) if self.morerows is not None: entry = f":rspan:`{content}` " + " ".join(items) @@ -2855,12 +2866,12 @@ def py_docstring(self, custom_functions: CustomFunctions) -> str: items += [""] + custom_functions.py_examples[self.py_name] docstr = "\n".join(items) - # final post-processing - def replacer(match): - return match.group().replace("*", r"\*").replace(r"\\*", r"\*") + # # final post-processing + # def replacer(match): + # return match.group().replace("*", r"\*").replace(r"\\*", r"\*") - # sphinx doesn't like asterisk symbols - docstr = re.sub(r"(?<=\S)\*|(\*\S)", replacer, docstr) + # # sphinx doesn't like asterisk symbols + # docstr = re.sub(r"(?<=\S)\*|(\*\S)", replacer, docstr) for key, value in CONST.items(): docstr = docstr.replace(key, value)