44 lines
1 KiB
Python
Executable file
44 lines
1 KiB
Python
Executable file
#!/bin/env python
|
|
|
|
import textwrap
|
|
import sys
|
|
|
|
# with open(sys.argv[1], 'r') as f:
|
|
# lines = f.read().splitlines()
|
|
# print(lines)
|
|
|
|
# first pass: reflow paragraphs
|
|
# paragraph = []
|
|
# lines = []
|
|
# for line in sys.stdin:
|
|
# line = line.rstrip()
|
|
# if line:
|
|
# paragraph.append(line)
|
|
# else:
|
|
# if paragraph:
|
|
# lines.append(' '.join(paragraph))
|
|
# lines.append("\n")
|
|
# if paragraph:
|
|
# lines.append(' '.join(paragraph))
|
|
|
|
|
|
skipping = False
|
|
for line in sys.stdin:
|
|
if line.startswith(">"):
|
|
# ignore quoted line
|
|
print(line, end = "")
|
|
elif line.startswith("```"):
|
|
# ignore code block
|
|
skipping = not skipping
|
|
print(line, end = "")
|
|
elif line.startswith("--"):
|
|
skipping = True
|
|
print(line, end = "")
|
|
else:
|
|
# wrap the line
|
|
if not skipping:
|
|
wrapped = textwrap.wrap(line, width=74, break_long_words=False, replace_whitespace=True)
|
|
|
|
print("\n".join(wrapped))
|
|
else:
|
|
print(line, end = "")
|