Post-process the converted markdown, preserving base64 content images.
(text: str)
| 136 | |
| 137 | |
| 138 | def _clean_markdown(text: str) -> str: |
| 139 | """Post-process the converted markdown, preserving base64 content images.""" |
| 140 | text = re.sub(r'!\[([^\]]*?)\n+([^\]]*?)\]', _fix_multiline_alt, text) |
| 141 | text = re.sub(r'\n{4,}', '\n\n\n', text) |
| 142 | text = re.sub(r'^\s*\n', '\n', text, flags=re.MULTILINE) |
| 143 | text = re.sub(r'\n{3,}', '\n\n', text) |
| 144 | return text.strip() + '\n' |
| 145 | |
| 146 | |
| 147 | def _fix_multiline_alt(match): |