Skip to content

Commit 99cae8b

Browse files
committed
fix: filename rendering
1 parent 040532f commit 99cae8b

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/pyconverter/xml2py/ast_tree.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -905,15 +905,29 @@ def to_rst(self, indent="", max_length=100, links=None, base_url=None, fcache=No
905905
class FileName(Element):
906906
"""Provides the filename element."""
907907

908+
def __init__(self, element, parse_children=True):
909+
super().__init__(element, parse_children)
910+
self._tail = self.children[-1] if len(self) > 1 else None
911+
self._filename = self.get_filename()
912+
913+
def get_filename(self):
914+
"""Get the filename."""
915+
filename = []
916+
for element in self:
917+
filename.append(str(element))
918+
filename = "".join(filename)
919+
filename = filename.replace(str(self._tail), "")
920+
if "*" in filename:
921+
filename = filename.replace("*", r"\*")
922+
return filename
923+
908924
def to_rst(self, indent="", max_length=100):
909925
"""Return a string to enable converting the element to an RST format."""
910-
content = self[0]
911-
if "*" in content:
912-
content = content.replace("*", r"\*")
913-
output = f":file:`{content}` {self.tail}"
914-
# TODO: needs to fix the issue with the ``nnn.jpg`` file name
915-
if "nnn.jpg" in output:
916-
pass
926+
if self._tail and self._tail[0] in [",", ".", " "]:
927+
output = f":file:`{self._filename}`{self._tail}"
928+
else:
929+
output = f":file:`{self._filename}` {self._tail}"
930+
print(output)
917931
return output
918932

919933

0 commit comments

Comments
 (0)