Skip to content

Commit 541fa7c

Browse files
jdmonacoclaude
andcommitted
Preserve CLI option dashes from smart dash conversion
Protect --option and ---option patterns (whitespace-preceded dashes followed by word characters) using the existing placeholder mechanism. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e27691b commit 541fa7c

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

mdformat_space_control/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""An mdformat plugin for space control: EditorConfig indentation, tight lists, frontmatter spacing, smart dash conversion, soft break joining, and wikilinks."""
22

3-
__version__ = "0.4.2"
3+
__version__ = "0.4.3"
44

55
from .config import (
66
get_current_file,

mdformat_space_control/plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ def _convert_dash_sequences(text: str) -> str:
411411
em_dash_re = re.compile(r"(?<!-)---(?!-)")
412412
en_dash_re = re.compile(r"(?<!-)--(?!-)")
413413

414+
# CLI option pattern: --word or ---word preceded by whitespace or line start
415+
cli_option_re = re.compile(r"(?<=\s)-{2,3}(?=\w)")
416+
414417
# Lines that are only dashes (thematic breaks, frontmatter delimiters)
415418
only_dashes_re = re.compile(r"^-{2,}\s*$")
416419

@@ -453,6 +456,9 @@ def _save_placeholder(m: re.Match) -> str:
453456
protected = html_comment_re.sub(_save_placeholder, protected)
454457
protected = html_tag_re.sub(_save_placeholder, protected)
455458

459+
# Protect CLI option dashes (e.g., --output, ---long-opt)
460+
protected = cli_option_re.sub(_save_placeholder, protected)
461+
456462
# Convert em-dash first (longer match), then en-dash
457463
protected = em_dash_re.sub("\u2014", protected)
458464
protected = en_dash_re.sub("\u2013", protected)

0 commit comments

Comments
 (0)