From 026a5e47df53ed84c2b6d3573d605fe7a93b8611 Mon Sep 17 00:00:00 2001 From: giwaov Date: Mon, 27 Apr 2026 13:45:35 +0100 Subject: [PATCH] fix(cli): preserve Windows hidden-dir paths in markdown --- cli.py | 23 +++++++++++++++++++++++ tests/cli/test_cli_markdown_rendering.py | 17 +++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/cli.py b/cli.py index e8c804a9e8..3b9f6af531 100644 --- a/cli.py +++ b/cli.py @@ -1226,6 +1226,28 @@ def _strip_markdown_syntax(text: str) -> str: return plain.strip("\n") +_WINDOWS_PATH_WITH_DOT_SEGMENT_RE = re.compile( + r"(?i)(?:\b[a-z]:\\|\\\\)[^\s`]*\\\.[^\s`]*" +) + + +def _preserve_windows_dot_segments_for_markdown(text: str) -> str: + r"""Keep Windows path separators before hidden directories in Markdown. + + CommonMark treats ``\.`` as an escaped literal dot, so Rich Markdown would + render ``D:\repo\.ai`` as ``D:\repo.ai``. Doubling only that separator + inside Windows path-looking tokens preserves the path without changing + ordinary markdown escapes like ``1\. not a list``. + """ + if "\\." not in text: + return text + + def _protect(match: re.Match[str]) -> str: + return re.sub(r"(?