diff options
| author | uvok | 2025-06-23 20:53:40 +0200 |
|---|---|---|
| committer | uvok | 2025-06-23 20:53:40 +0200 |
| commit | 9a70dda521b2ea481200eefc80e4755ee5279927 (patch) | |
| tree | 8852df346a4c3672192fcb47cfdf00de4174212e | |
| parent | b36a43b96f6f5fef1112dc9791eb980979fe70b5 (diff) | |
Use regex to merge lines
also, remove "html" pass
| -rw-r--r-- | converters/md_to_gemini.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/converters/md_to_gemini.py b/converters/md_to_gemini.py index fad3d4f..3f751c4 100644 --- a/converters/md_to_gemini.py +++ b/converters/md_to_gemini.py @@ -2,8 +2,23 @@ import os from os import walk import os.path from md2gemini import md2gemini +import re + +def merge_lines(text): + pattern = r'(^=>.*)(?:\n[ \t\*]*)+(=>)' + pattern = r'(^=>.*)(?:\r?\n[ \t\*]*)+\r?\n(?=^=>)' + while True: + new_text = re.sub(pattern, r'\1\n', text, flags=re.MULTILINE) + if new_text == text: + break + text = new_text + text = re.sub(r'^\* *\r?$', r'', text, flags=re.MULTILINE) + return text + + # Match any blank line (or whitespace-only line) that’s followed by a line starting with => + pattern = r'(^=>.*)(?:[\n \t\*]*)(?=^=>)' + return re.sub(pattern, r'\1\n', input_text, flags=re.MULTILINE) -def merge_lines(input_text): lines = input_text.splitlines() result = [] last_line = None @@ -35,6 +50,8 @@ def convert_md_to_gemini(): gemini = merge_lines(gemini) f.write(gemini) f.close() + return "markdown was converted to gemini (2/3)" + for file in os.listdir("output/gemini"): processed = "" f = open("output/gemini/" + file, "r") |
