Skip to content

Commit 3553425

Browse files
committed
fix: cleaning code and adding new line for ProgramListing.to_rst()
1 parent b5032dc commit 3553425

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/pyconverter/xml2py/ast_tree.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ def to_rst(self, indent="", max_length=100):
10651065
"""Return a string to enable converting the element to an RST format."""
10661066
header = f"\n\n{indent}.. code:: apdl\n\n"
10671067
source_code = re.sub(r"[^\S\r\n]", " ", self.source) # Remove extra whitespaces
1068-
rst_item = header + textwrap.indent(source_code, prefix=indent + " " * 3) + "\n"
1068+
rst_item = header + textwrap.indent(source_code, prefix=indent + " " * 3) + "\n\n"
10691069
return rst_item
10701070

10711071

@@ -1929,7 +1929,7 @@ def args(self):
19291929
if isinstance(self.next_elem, Replaceable):
19301930
cmd_args += str(self.next_elem[0]) # no tail
19311931
elif len(self.tail) > 1 and self.tail[1] == " ":
1932-
# possible not coded as replacable
1932+
# possible not coded as replaceable
19331933
for word in words[1:]:
19341934
if word.upper() == word or is_numeric(word):
19351935
if not (word[-1].isalnum() or word[-1].isdigit()):
@@ -2994,19 +2994,6 @@ def trail_replacer(match):
29942994
lines.insert(i + 1, "")
29952995
i += 1
29962996

2997-
# ensure that lists end with a blank line
2998-
i = 0
2999-
while i < len(lines):
3000-
j = 1
3001-
if lines[i].lstrip().startswith("* -"):
3002-
while i + j < len(lines) - 1 and lines[i + j].lstrip().startswith("-"):
3003-
j += 1
3004-
if not lines[i + j].lstrip().startswith("* -"):
3005-
if i + j == len(lines) - 1:
3006-
j += 1
3007-
lines.insert(i + j, "")
3008-
i += j
3009-
30102997
# ensure that two similar links are not in a similar file.
30112998
i = 0
30122999
link = []
@@ -3060,12 +3047,26 @@ def trail_replacer(match):
30603047
else:
30613048
lines[i] = lines[i].replace(l, name_link)
30623049

3063-
docstr = "\n".join(lines)
3064-
30653050
# remove repeated line breaks
30663051
while "\n\n\n" in docstr:
30673052
docstr = docstr.replace("\n\n\n", "\n\n")
30683053

3054+
lines = docstr.splitlines()
3055+
3056+
# ensure that lists end with a blank line
3057+
i = 0
3058+
while i < len(lines):
3059+
j = 1
3060+
if lines[i].lstrip().startswith("* -"):
3061+
while i + j < len(lines) - 1 and lines[i + j].lstrip().startswith("-"):
3062+
j += 1
3063+
if not lines[i + j].lstrip().startswith("* -"):
3064+
if i + j == len(lines) - 1:
3065+
j += 1
3066+
lines.insert(i + j, "")
3067+
i += j
3068+
docstr = "\n".join(lines)
3069+
30693070
docstr = re.sub(r"bgcolor=\S\S\S\S\S\S\S\S\S\S? ", "", docstr)
30703071
docstr = re.sub(r"bgcolor=\S\S\S\S\S\S\S\S\S\S?", "", docstr)
30713072
docstr = re.sub(r"_cellfont Shading=\S\S\S\S\S\S\S\S", "", docstr)

src/pyconverter/xml2py/load_xml_doc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ def term_replacer(match):
6666
if key not in terms:
6767
terms[key] = text
6868

69-
if "angcycsym" in terms:
70-
print(terms["angcycsym"])
71-
7269
return terms
7370

7471

0 commit comments

Comments
 (0)