Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / scripts / filter_text.py
filter_text.py31 lines · 1.2 KiBRaw
| 1 | #!/usr/bin/env python3 |
| 2 | import sys, re |
| 3 | pat = re.compile(r'Text\s*\(\s*(?:text\s*=\s*)?"([^"]+)"') |
| 4 | # Skip legitimate decorative/single-char/icon previews |
| 5 | skip_exact = { |
| 6 | 'A','T', '\u0192', '\u270e', '\u2013', '\u2713', '\u2717', '\u00d7', '\u2192', '\u2190', '\u232b', '\u25cf', '\u25cb', '\u2014', '\u2022', '\u00b7', '.', '+', '\u2191', '\u2193', '\u25be', '\u2205', 'Aa', '\u21bb', '?' |
| 7 | } |
| 8 | skip_contains = ['font'] # lines containing 'font' and single-char A are preview |
| 9 | for line in sys.stdin: |
| 10 | m = pat.search(line) |
| 11 | if not m: |
| 12 | continue |
| 13 | lit = m.group(1) |
| 14 | s = lit.strip() |
| 15 | if s in skip_exact: |
| 16 | continue |
| 17 | if len(s) <= 2 and ' ' not in s and not re.search(r'[A-Za-z]{2,}', s): |
| 18 | continue |
| 19 | # office font-size preview A with bodySmall/headlineSmall |
| 20 | if s == 'A' and ('bodySmall' in line or 'headlineSmall' in line): |
| 21 | continue |
| 22 | if s == 'T' and ('sp' in line): |
| 23 | continue |
| 24 | # Remove interpolations like ${...}, $var, %1$s etc |
| 25 | stripped = re.sub(r'\$\{[^}]+\}|\$[A-Za-z_][A-Za-z0-9_\.]*|\\u[0-9A-Fa-f]{4}|%\d*\$?[sdif]|%[sdif]', '', lit) |
| 26 | stripped = stripped.strip() |
| 27 | if len(stripped) < 2: |
| 28 | continue |
| 29 | if not re.search(r'[A-Za-z]{2,}', stripped): |
| 30 | continue |
| 31 | print(line, end='') |