Skip to content

Commit 291507b

Browse files
committed
fix: .. code:: elements (indentations and new lines) + removing unknown caracters
1 parent 13491f4 commit 291507b

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/pyconverter/xml2py/ast_tree.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
",)": ")",
6666
"% ``": "``%", # Ansys variable names should be pulled inside literals
6767
"`` %": "%``", # same
68+
"\xa0": " ",
69+
"’": "``",
70+
"∗": "*",
6871
}
6972

7073
PY_ARG_CLEANUP = {
@@ -356,7 +359,6 @@ def resize_length(text, max_length=100, initial_indent="", subsequent_indent="",
356359
str or list
357360
Resized text.
358361
"""
359-
text = text.replace(" .", ".")
360362
while "\n\n\n" in text:
361363
text = text.replace("\n\n\n", "\n\n")
362364

@@ -685,22 +687,28 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No
685687
rst_list = item_lines
686688

687689
new_rst_list = []
688-
for line in rst_list:
689-
new_rst_list.extend(
690-
resize_length(
691-
line,
692-
max_length=max_length,
693-
initial_indent=indent,
694-
subsequent_indent=indent,
695-
list=True,
690+
691+
if ".. code::" in "\n".join(rst_list):
692+
lines.extend(rst_list)
693+
694+
else:
695+
for line in rst_list:
696+
new_rst_list.extend(
697+
resize_length(
698+
line,
699+
max_length=max_length,
700+
initial_indent=indent,
701+
subsequent_indent=indent,
702+
list=True,
703+
)
696704
)
697-
)
698705

699-
lines.extend(new_rst_list)
706+
lines.extend(new_rst_list)
700707

701708
# lists must have at least one line proceeding
702709
lines = ["", ""] + lines + [""]
703-
return "\n\n".join(lines)
710+
711+
return "\n".join(lines)
704712

705713

706714
class SimpleList(ItemizedList):
@@ -791,7 +799,6 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No
791799
items.append(rst_item)
792800

793801
rst_list_item = "\n".join(items)
794-
# rst_list_item = rst_list_item.replace("*", "\*")
795802
return rst_list_item
796803

797804

@@ -1064,9 +1071,7 @@ def source(self):
10641071
def to_rst(self, indent="", max_length=100):
10651072
"""Return a string to enable converting the element to an RST format."""
10661073
header = f"\n\n{indent}.. code:: apdl\n\n"
1067-
source_code = re.sub(r"[^\S\r\n]", " ", self.source) # Remove extra whitespaces
1068-
source_code = header + textwrap.indent(source_code, prefix=indent + " " * 3) + "\n\n"
1069-
1074+
source_code = header + textwrap.indent(self.source, prefix=indent + " " * 3) + "\n\n"
10701075
items = []
10711076

10721077
for item in self:
@@ -1080,7 +1085,6 @@ def to_rst(self, indent="", max_length=100):
10801085
items += item
10811086

10821087
rst_item = "".join(items)
1083-
10841088
return rst_item
10851089

10861090

@@ -3126,7 +3130,6 @@ def py_notes(self, custom_functions: CustomFunctions = None):
31263130
notes = self.notes.to_rst()
31273131

31283132
notes = replace_terms(notes, self._terms)
3129-
31303133
to_be_resized = re.findall(r"^[^\.\s].+(?=\n)|(?<=\n)[^\.\s].+(?=\n)", notes)
31313134

31323135
for item in to_be_resized:

0 commit comments

Comments
 (0)