diff --git a/.config/mail/format.py b/.config/mail/format.py index ca87b44b..cc84184f 100755 --- a/.config/mail/format.py +++ b/.config/mail/format.py @@ -2,11 +2,14 @@ # Simple text-wrapping script for email. # Preserves code blocks, quotes, and signature. +# Automatically joins and re-wraps paragraphs to +# ensure even spacing & avoid ugly wrapping. # Author: Daniel Fichtinger # License: MIT import textwrap import sys +import re paragraph = [] skipping = False @@ -20,22 +23,15 @@ def flush_paragraph(): for line in sys.stdin: line = line.rstrip() - if line.startswith("```"): flush_paragraph() skipping = not skipping print(line) - elif line.startswith(">"): - flush_paragraph() - print(line) - elif line.startswith(("- ", "+ ", "* ", "\t", " ")): - flush_paragraph() - print(line) elif line.startswith("--"): flush_paragraph() skipping = True print(line) - elif not line: + elif not line or re.match(r"^(\s+|-\s+|\+\s+|\*\s+|>\s*)", line): flush_paragraph() print(line) elif skipping: