Open PhilipMay opened 8 months ago
import re def fix_md_headlines(md: str) -> str: headlines = re.findall(r'^#+', md, re.MULTILINE) if len(headlines) == 0: return md lenths = [len(h) for h in headlines] min_length = min(lenths) for i in range(6): source_str = "#" * (min_length + i) target_str = "#" * (i + 1) md = re.sub(f"^{source_str}", target_str, md, flags=re.MULTILINE) return md