diff options
author | Joris | 2023-09-17 15:12:36 +0200 |
---|---|---|
committer | Joris | 2023-09-17 15:12:36 +0200 |
commit | f1eee98bb5144efc1aa242bad0e5676e12d882a5 (patch) | |
tree | 48374cac3a808fa9219c6338c8ac11d2a7f1935b /cli/new/format.py | |
parent | 61abb0a9a05bec2ce2ce58e2943eb1458b6b25c3 (diff) |
Test formatting
Diffstat (limited to 'cli/new/format.py')
-rw-r--r-- | cli/new/format.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/cli/new/format.py b/cli/new/format.py index c004f82..7f66f44 100644 --- a/cli/new/format.py +++ b/cli/new/format.py @@ -2,15 +2,15 @@ import pathlib import re import unicodedata -def format_list(xs): - return '[ ' + ', '.join([f'"{x}"' for x in xs]) + ' ]' +def list(xs): + return '[' + ', '.join([f'"{x}"' for x in xs]) + ']' def path_part(name): simplified = ''.join([alnum_or_space(c) for c in unaccent(name.lower())]) return '-'.join(simplified.split()) def unaccent(s): - return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn') + return ''.join(c for c in unicodedata.normalize('NFD', s) if unicodedata.category(c) != 'Mn') def alnum_or_space(c): if c.isalnum(): @@ -23,9 +23,9 @@ def extension(path): def cleanup_text(s, lang): s = re.sub('\'', '’', s) - s = re.sub('\.\.\.', '…', s) - s = re.sub('\. \. \.', '…', s) - s = cleanup_quotes(s, lang) + s = re.sub(r'\.\.\.', '…', s) + s = re.sub(r'\. \. \.', '…', s) + s = cleanup_double_quotes(s, lang) if lang == 'fr': s = re.sub('“', '«', s) @@ -36,7 +36,10 @@ def cleanup_text(s, lang): s = re.sub('« ', '« ', s) # Add missing insecable spaces - s = re.sub(r'([^ ])([:?\!»])', r'\1 \2', s) + s = re.sub(r'([^ ]):', r'\1 :', s) + s = re.sub(r'([^ ])\?', r'\1 ?', s) + s = re.sub(r'([^ ])\!', r'\1 !', s) + s = re.sub(r'([^ ])»', r'\1 »', s) s = re.sub(r'«([^ ])', r'« \1', s) elif lang == 'en': @@ -45,7 +48,7 @@ def cleanup_text(s, lang): return s -def cleanup_quotes(s, lang): +def cleanup_double_quotes(s, lang): res = '' quoted = False for c in s: @@ -65,4 +68,3 @@ def cleanup_quotes(s, lang): else: res += c return res - |