import os from os import walk import os.path from md2gemini import md2gemini def merge_lines(input_text): lines = input_text.splitlines() result = [] last_line = None for line in lines: stripped = line.strip() if stripped == '' or stripped == '*': # Tentatively hold this line last_line = stripped continue if stripped.startswith('=>') and (last_line == '' or last_line == '*'): # Skip the held line last_line = None if last_line is not None: result.append(last_line) last_line = None result.append(line) # If the last line was held and never flushed if last_line is not None: result.append(last_line) return '\n'.join(result) def convert_md_to_gemini(): for file in os.listdir("output/markdown"): with open("output/markdown/" + str(file), "r") as f: gemini = md2gemini(f.read()) f.close() f = open("output/gemini/" + str(file).replace(".md", ".gmi"), "w") gemini = merge_lines(gemini) f.write(gemini) f.close() for file in os.listdir("output/gemini"): processed = "" f = open("output/gemini/" + file, "r") for line in f.readlines(): if line == "html\n": pass else: processed += line f.close() f = open("output/gemini/" + file, "w") f.write(processed) f.close() return "markdown was converted to gemini (2/3)"