taxdoc-preprocessor / formatter.py
iamnew123's picture
Upload 5 files
7780d69 verified
raw
history blame contribute delete
578 Bytes
import re
def format_text(text):
lines = text.splitlines()
formatted = []
section = []
for line in lines:
if re.search(r'(?i)section \\d+[A-Z]*|TDS on|TCS on|Form \\d+', line):
if section:
formatted.append("\n".join(section))
formatted.append("")
section = [f"## {line.strip()}"]
else:
if not section:
section = []
section.append(f"- {line.strip()}")
if section:
formatted.append("\n".join(section))
return "\n\n".join(formatted)