46 lines
1 KiB
Python
Executable file
46 lines
1 KiB
Python
Executable file
#!/bin/env python
|
|
|
|
# Simple text-wrapping script for email.
|
|
# Preserves code blocks, quotes, and signature.
|
|
# Author: Daniel Fichtinger
|
|
# License: MIT
|
|
|
|
import textwrap
|
|
import sys
|
|
|
|
paragraph = []
|
|
skipping = False
|
|
|
|
def flush_paragraph():
|
|
if paragraph:
|
|
joined = " ".join(paragraph)
|
|
wrapped = textwrap.wrap(joined, width=74, break_long_words=False, replace_whitespace=True)
|
|
print("\n".join(wrapped))
|
|
paragraph.clear()
|
|
|
|
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:
|
|
flush_paragraph()
|
|
print(line)
|
|
elif skipping:
|
|
print(line)
|
|
else:
|
|
paragraph.append(line)
|
|
else:
|
|
flush_paragraph()
|