Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dogweather committed Jul 22, 2023
1 parent 1a9f38b commit 7f64de0
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions script/crs-txt-to-sgml.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"Uuml": 220,
}

ELEMENTS_TO_DELETE: Final = [
'IT',
'S1',
'T',
]


def fix_unencoded_text(line: str) -> str:
return (
Expand All @@ -54,7 +60,7 @@ def fix_unencoded_text(line: str) -> str:


def cleanup(line: str) -> str:
return line.replace("_", "-").replace("<T>", "").replace("<S1>", "").replace("<IT>", "").replace("</IT>", "")
return line.replace("_", "-")


def replace_entities(line: str) -> str:
Expand All @@ -64,8 +70,15 @@ def replace_entities(line: str) -> str:
return line


def delete_unwanted_elements(line: str) -> str:
for elem in ELEMENTS_TO_DELETE:
line = line.replace(f"<{elem}>", '').replace(f"</{elem}>", '')

return line


def fix_and_cleanup(line: str) -> str:
return replace_entities(cleanup(fix_unencoded_text(line)))
return delete_unwanted_elements(replace_entities(cleanup(fix_unencoded_text(line))))


#
Expand Down

0 comments on commit 7f64de0

Please sign in to comment.