From b36a43b96f6f5fef1112dc9791eb980979fe70b5 Mon Sep 17 00:00:00 2001 From: uvok Date: Mon, 23 Jun 2025 19:28:41 +0200 Subject: gemini: Improve strip logic --- converters/md_to_gemini.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'converters') diff --git a/converters/md_to_gemini.py b/converters/md_to_gemini.py index d7c1596..fad3d4f 100644 --- a/converters/md_to_gemini.py +++ b/converters/md_to_gemini.py @@ -9,30 +9,22 @@ def merge_lines(input_text): last_line = None for line in lines: - stripped = line.strip() + stripped = line.rstrip() - 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: + if (last_line == '' or last_line == '*') and stripped.startswith('=>'): + last_line = None # Skip the previous line if last_line is not None: result.append(last_line) - last_line = None - result.append(line) + last_line = stripped - # 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: -- cgit v1.2.3