From 9b0a1647f9863a0e11c17888d92c87374ef31ef0 Mon Sep 17 00:00:00 2001 From: Christian Boos Date: Wed, 24 Jun 2026 00:03:22 +0200 Subject: [PATCH] Render Read/Write of any Markdown file as Markdown, not Pygments (#232) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Generalize the auto-memory body rendering (#192) to every .md file: a fully-contained Markdown file should render the usual way (rendered Markdown) rather than syntax-highlighted source. - Add is_markdown_path() (.md/.markdown, case- and separator-insensitive). Memory paths are a subset, so is_memory_path ⊂ is_markdown_path. - Write always carries the whole file → always rendered as Markdown for any .md path (no partial-slice concern). - Read renders as Markdown only for a *full* read (start_line == 1 and not truncated, via _is_full_read). A partial slice (offset/limit) can begin or end mid-code-fence and would render garbled, so partial reads keep Pygments — where a line-numbered source view is more useful anyway. - Reuse the HTML-escaping markdown helper: file content is untrusted regardless of being a memory file, so raw \n")) + assert "<script>" in html + assert "" not in html + + def test_general_md_read_has_no_memory_link_resolution(self): + # Relative links in a non-memory .md stay as-authored (no file:// rewrite). + html = format_read_output(_read(MD, "[peer](peer.md)\n")) + assert 'href="peer.md"' in html + assert "file://" not in html + + +# ----------------------------- Write rendering ------------------------------- + + +class TestWriteMarkdownRendering: + def test_md_write_rendered_as_markdown(self): + html = format_write_input(WriteInput(file_path=MD, content=MD_BODY)) + assert re.search(r'class="write-tool-content markdown"', html) + assert re.search(r"]*>Guide", html) + + def test_non_markdown_write_keeps_pygments(self): + html = format_write_input(WriteInput(file_path=PY, content="x = 1\n")) + assert 'class="write-tool-content markdown"' not in html + + def test_md_write_escapes_raw_html(self): + html = format_write_input( + WriteInput(file_path=MD, content="# T\n\n") + ) + assert "<script>" in html + assert "" not in html + + def test_general_md_write_has_no_memory_link_resolution(self): + html = format_write_input(WriteInput(file_path=MD, content="[peer](peer.md)\n")) + assert 'href="peer.md"' in html + assert "file://" not in html