diff options
Diffstat (limited to 'converters')
| -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") |
