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"(?