From 80927a14009d3969edea7cb665650f8d18f65a9c7d9833dc4b193e2fbc941d00 Mon Sep 17 00:00:00 2001 From: Discsearcher Date: Tue, 1 Sep 2026 12:43:26 -0400 Subject: [PATCH] Updated to fix issue. --- app.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/app.py b/app.py index 8ca685c..67ab777 100644 --- a/app.py +++ b/app.py @@ -144,6 +144,65 @@ def is_hidden_path(file_path): # Check all parts of the path including the filename return any(part.startswith('.') for part in path_obj.parts) +def normalize_list_indentation(md_content): + """ + Normalize list indentation from 2-space to 4-space for proper markdown parsing. + Python-Markdown requires 4 spaces for nested lists, but many editors use 2 spaces. + Also ensures blank lines before lists when needed. + """ + lines = md_content.split('\n') + normalized_lines = [] + + def is_list_item_line(text): + """Check if a line is actually a list item, not bold/italic markdown.""" + stripped = text.lstrip(' ') + if not stripped: + return False + + # Check for unordered list (- or + or single * followed by space) + if stripped[0] in '-+': + return len(stripped) > 1 and stripped[1] == ' ' + elif stripped[0] == '*': + # Make sure it's not ** (bold) and is actually a list marker + return len(stripped) > 1 and stripped[1] == ' ' and not (len(stripped) > 2 and stripped[2] == '*') + + # Check for ordered list (digits followed by . and space) + if stripped[0].isdigit(): + i = 0 + while i < len(stripped) and stripped[i].isdigit(): + i += 1 + return i < len(stripped) and stripped[i] == '.' and i + 1 < len(stripped) and stripped[i + 1] == ' ' + + return False + + for i, line in enumerate(lines): + # Count leading spaces + leading_spaces = len(line) - len(line.lstrip(' ')) + stripped = line.lstrip(' ') + is_list = is_list_item_line(line) + + if is_list: + # Check if previous line exists and is not empty and is not a list item and is not a blank line + if i > 0 and normalized_lines: + prev_line = normalized_lines[-1] + prev_is_list = is_list_item_line(prev_line) + + # If previous line exists, is not empty, and is not a list item, add blank line + if prev_line.strip() and not prev_is_list and prev_line != '': + normalized_lines.append('') + + if leading_spaces > 0 and leading_spaces % 2 == 0: + # Convert 2-space indentation to 4-space for nested lists + # Each 2-space indent becomes 4-space + new_spaces = (leading_spaces // 2) * 4 + normalized_lines.append(' ' * new_spaces + stripped) + else: + normalized_lines.append(line) + else: + normalized_lines.append(line) + + return '\n'.join(normalized_lines) + def rewrite_image_paths(md_content, filepath): """Rewrite relative image paths to be served by Flask.""" # Get the directory of the current file @@ -403,6 +462,9 @@ def view_file(filepath): # Rewrite image paths to be served by Flask md_content = rewrite_image_paths(md_content, filepath) + # Normalize list indentation for proper markdown parsing + md_content = normalize_list_indentation(md_content) + # Convert markdown to HTML html_content = markdown.markdown( md_content,