From a110c200e86d2325af07167531fac0f61d9681a0 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Fri, 26 Dec 2025 18:41:26 +0100 Subject: Switch to GUI to manage the library Allow to regroup the CLI and the view into one unique tool. --- cli/new/format.py | 70 ------------------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 cli/new/format.py (limited to 'cli/new/format.py') diff --git a/cli/new/format.py b/cli/new/format.py deleted file mode 100644 index 7f66f44..0000000 --- a/cli/new/format.py +++ /dev/null @@ -1,70 +0,0 @@ -import pathlib -import re -import unicodedata - -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') - -def alnum_or_space(c): - if c.isalnum(): - return c - else: - return ' ' - -def extension(path): - return pathlib.Path(path).suffix - -def cleanup_text(s, lang): - s = re.sub('\'', '’', s) - s = re.sub(r'\.\.\.', '…', s) - s = re.sub(r'\. \. \.', '…', s) - s = cleanup_double_quotes(s, lang) - - if lang == 'fr': - s = re.sub('“', '«', s) - s = re.sub('”', '»', s) - - # Replace space by insecable spaces - s = re.sub(r' ([:?\!»])', r' \1', s) - s = re.sub('« ', '« ', s) - - # Add missing insecable spaces - 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': - s = re.sub('«', '“', s) - s = re.sub('»', '”', s) - - return s - -def cleanup_double_quotes(s, lang): - res = '' - quoted = False - for c in s: - if c == '"': - if quoted: - quoted = False - if lang == 'fr': - res += '»' - elif lang == 'en': - res += '”' - else: - quoted = True - if lang == 'fr': - res += '«' - elif lang == 'en': - res += '“' - else: - res += c - return res -- cgit v1.2.3