Skip to content

Commit

Permalink
Improve diffing (#58)
Browse files Browse the repository at this point in the history
* remove all double spaces

* escape markdown special characters from raw legifrance text when diffing
  • Loading branch information
rprimet authored Aug 18, 2023
1 parent 5c85956 commit 3f61c51
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/catleg/find_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def find_changes(f: TextIO, *, file_path: Path | None = None):

diff, retcode = wdiff(
_reformat(article.text),
_reformat(ref_article.text_and_nota()),
_reformat(_escape_ref_text(ref_article.text_and_nota())),
return_exit_code=True,
line_offset=article.start_line,
)
Expand All @@ -62,4 +62,11 @@ def _reformat(paragraph: str):
Catala has a 80-char line limit, so law texts will often be manually reformatted.
We attempt to remove extra line breaks before comparison.
"""
return paragraph.replace("\n", " ").strip().replace(" ", " ")
paragraph = paragraph.replace("\n", " ")
while " " in paragraph:
paragraph = paragraph.replace(" ", " ")
return paragraph.strip()


def _escape_ref_text(paragraph: str):
return paragraph.replace("[", r"\[").replace("]", r"\]").replace("*", r"\*")

0 comments on commit 3f61c51

Please sign in to comment.