Prep

Remove ASCII art boxes from text

#!/usr/bin/env python3
import sys
import re
def prep(lines):
    cleaned = []
    for raw in lines:
        line = raw.rstrip("\n")
        if re.fullmatch(r"\+[-+]+\s*", line):
            continue
        if line.startswith("|"):
            line = line[1:]
        if line.endswith("|"):
            line = line[:-1]
        line = line.rstrip()
        if not line.strip():
            if cleaned and cleaned[-1] != "":
                cleaned.append("")
            continue
        line = line.lstrip()
        if cleaned and cleaned[-1] != "":
            cleaned[-1] += " " + line
        else:
            cleaned.append(line)
    return "\n".join(cleaned) + "\n"
if __name__ == "__main__":
    sys.stdout.write(prep(sys.stdin))

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply