diff --git a/.gitignore b/.gitignore index fda26ed..cf813ce 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,6 @@ go.work.sum node_modules/ dist/ -__pycache__/ \ No newline at end of file +__pycache__/ + +site/ \ No newline at end of file diff --git a/docs/fix_line_endings.py b/docs/fix_line_endings.py new file mode 100644 index 0000000..9555e6b --- /dev/null +++ b/docs/fix_line_endings.py @@ -0,0 +1,60 @@ +""" +MkDocs hook to fix line endings for proper rendering. +Automatically adds two spaces at the end of lines that need line breaks. +""" +import re + + +def on_page_markdown(markdown, page, config, **kwargs): + """ + Fix line endings in markdown content for proper MkDocs rendering. + Adds two spaces at the end of lines that need line breaks. + """ + lines = markdown.split('\n') + processed_lines = [] + in_code_block = False + + for i, line in enumerate(lines): + stripped = line.strip() + + # Track code blocks + if stripped.startswith('```'): + in_code_block = not in_code_block + processed_lines.append(line) + continue + + # Skip processing inside code blocks + if in_code_block: + processed_lines.append(line) + continue + + # Skip empty lines + if not stripped: + processed_lines.append(line) + continue + + # Skip lines that shouldn't have line breaks: + # - Headers (# ## ###) + # - Blockquotes (>) + # - Table rows (|) + # - Lines already ending with two spaces + # - YAML front matter and HTML tags + # - Standalone punctuation lines + if (stripped.startswith('#') or + stripped.startswith('>') or + '|' in stripped or + line.endswith(' ') or + stripped.startswith('---') or + stripped.startswith('<') or + stripped.endswith('>') or + stripped in ('.', '!', '?', ':', ';', '```', '---', ',')): + processed_lines.append(line) + continue + + # Add two spaces to lines that end with regular text or most punctuation + if stripped and not in_code_block: + processed_lines.append(line.rstrip() + ' ') + else: + processed_lines.append(line) + + return '\n'.join(processed_lines) \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index a4f51ea..70cbef3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -69,6 +69,7 @@ plugins: hooks: - docs/readme_sync.py + - docs/fix_line_endings.py extra: version: