Skip to content

Commit 337627a

Browse files
committed
fix: removing italic feature and fixing . . . characters
1 parent 71584a4 commit 337627a

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/pyconverter/xml2py/ast_tree.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ def replace_asterisks(initial_text):
398398
text = re.sub(
399399
r"([^\*])(\*\*)(\*)(.*?)(\*\*)([^\*])", r"\1\2" + r"\*" + r"\4\5\6", text
400400
) # Replace ``***DIM**`` configurations into ``**\*DIM**``
401-
text = re.sub(
402-
r"([^\*])(\*)(\*)([A-Z]+)(\*)([^\*])", r"\1\2" + r"\*" + r"\4\5\6", text
403-
) # Replace ``**DIM*`` configurations into ``*\*DIM*``
401+
# text = re.sub(
402+
# r"([^\*])(\*)(\*)([A-Z]+)(\*)([^\*])", r"\1\2" + r"\*" + r"\4\5\6", text
403+
# ) # TODO: Replace ``**DIM*`` configurations into ``*\*DIM*``
404404

405405
return text
406406

@@ -791,6 +791,7 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No
791791
items.append(rst_item)
792792

793793
rst_list_item = "\n".join(items)
794+
# rst_list_item = rst_list_item.replace("*", "\*")
794795
return rst_list_item
795796

796797

@@ -941,15 +942,14 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None):
941942
"""Return a string to enable converting the element to an RST format."""
942943
content = str(self[0])
943944
if self.role == "bold":
944-
# TODO: this isn't the correct way of making text bold
945945
content = f"**{content}** "
946-
elif self.role == "italic":
947-
# TODO: this isn't the correct way of making text itallic
948-
content = f"*{content}* "
946+
# elif self.role == "italic":
947+
# # TODO: this isn't the correct way of making text itallic
948+
# content = f"{content} "
949949
# elif self.role == 'var':
950950
# content = f"``{self[0]}`` "
951951
else:
952-
content = f"{self[0]} "
952+
content = f"{content} "
953953

954954
items = []
955955
for item in self[1:]:
@@ -1042,12 +1042,13 @@ def content_equals(self):
10421042

10431043
def to_rst(self, indent="", max_length=100):
10441044
"""Return a string to enable converting the element to an RST format."""
1045+
rst_replaceable = f"``{self.content[0]}`` {self.tail}"
10451046
if isinstance(self.prev_elem, Command):
10461047
if any([self.content[0] in arg for arg in self.prev_elem.args]):
1047-
return f"{self.tail}"
1048+
rst_replaceable = f"{self.tail}"
10481049
if self.is_equals:
1049-
return self.content_equals
1050-
return f"``{self.content[0]}`` {self.tail}"
1050+
rst_replaceable = self.content_equals
1051+
return rst_replaceable
10511052

10521053

10531054
class ProgramListing(Element):
@@ -1064,7 +1065,22 @@ def to_rst(self, indent="", max_length=100):
10641065
"""Return a string to enable converting the element to an RST format."""
10651066
header = f"\n\n{indent}.. code:: apdl\n\n"
10661067
source_code = re.sub(r"[^\S\r\n]", " ", self.source) # Remove extra whitespaces
1067-
rst_item = header + textwrap.indent(source_code, prefix=indent + " " * 3) + "\n\n"
1068+
source_code = header + textwrap.indent(source_code, prefix=indent + " " * 3) + "\n\n"
1069+
1070+
items = []
1071+
1072+
for item in self:
1073+
if isinstance(item, Element):
1074+
items += item.to_rst(indent=indent, max_length=max_length)
1075+
else: # if isinstance(item, str):
1076+
item_in_source = re.search(r"\S+", item).group()
1077+
if item_in_source and item_in_source in source_code:
1078+
items += source_code
1079+
else:
1080+
items += item
1081+
1082+
rst_item = "".join(items)
1083+
10681084
return rst_item
10691085

10701086

@@ -3046,8 +3062,6 @@ def trail_replacer(match):
30463062
else:
30473063
lines[i] = lines[i].replace(l, name_link)
30483064

3049-
docstr = "\n".join(lines)
3050-
30513065
# remove repeated line breaks
30523066
while "\n\n\n" in docstr:
30533067
docstr = docstr.replace("\n\n\n", "\n\n")
@@ -3073,6 +3087,7 @@ def trail_replacer(match):
30733087
docstr = re.sub(r"_cellfont Shading=\S\S\S\S\S\S\S\S", "", docstr)
30743088
docstr = re.sub(r"Caret.+\?", "", docstr)
30753089
docstr = docstr.replace("–", "-")
3090+
docstr = docstr.replace(". . .", "...")
30763091
docstr = replace_asterisks(docstr)
30773092
docstr = ponctuaction_whitespace(docstr, ".") # Remove extra whitespace before period
30783093
docstr = ponctuaction_whitespace(docstr, ",") # Remove extra whitespace before comma
@@ -3112,7 +3127,7 @@ def py_notes(self, custom_functions: CustomFunctions = None):
31123127

31133128
notes = replace_terms(notes, self._terms)
31143129

3115-
to_be_resized = re.findall(r"^[^\.\s]?.+(?=\n)|(?<=\n)[^\.\s].+(?=\n)", notes)
3130+
to_be_resized = re.findall(r"^[^\.\s].+(?=\n)|(?<=\n)[^\.\s].+(?=\n)", notes)
31163131

31173132
for item in to_be_resized:
31183133
resized_item = resize_length(item, self._max_length)

0 commit comments

Comments
 (0)