0.0.5-alpha.3.fix.1
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
# file: scripts/audit_markdown_tables.py
|
||||
# version: 1
|
||||
# version: 2
|
||||
|
||||
"""Validate source formatting of Markdown tables in explicitly selected paths."""
|
||||
|
||||
@@ -13,6 +13,7 @@ import sys
|
||||
|
||||
_SEPARATOR = re.compile(r"^:?-{3,}:?$")
|
||||
_IGNORED_DIRECTORIES = frozenset({".git", ".idea", ".venv", "__pycache__", "dist", "node_modules", "target"})
|
||||
_MARKDOWN_FENCE_LANGUAGES = frozenset({"markdown", "md"})
|
||||
|
||||
|
||||
def _selected_files(raw_paths: list[str]) -> tuple[list[pathlib.Path], list[str]]:
|
||||
@@ -130,11 +131,19 @@ def _validate_table(path: pathlib.Path, start_line: int, rows: list[str]) -> lis
|
||||
return errors
|
||||
|
||||
|
||||
def _fence_language(stripped: str) -> str | None:
|
||||
info = stripped[3:].strip()
|
||||
if not info:
|
||||
return None
|
||||
return info.split(None, 1)[0].lower()
|
||||
|
||||
|
||||
def _audit_file(path: pathlib.Path) -> tuple[int, list[str]]:
|
||||
lines = path.read_text(encoding="utf-8").splitlines()
|
||||
errors: list[str] = []
|
||||
tables = 0
|
||||
fence: str | None = None
|
||||
audit_fenced_markdown = False
|
||||
index = 0
|
||||
|
||||
while index < len(lines):
|
||||
@@ -143,12 +152,14 @@ def _audit_file(path: pathlib.Path) -> tuple[int, list[str]]:
|
||||
marker = stripped[:3]
|
||||
if fence is None:
|
||||
fence = marker
|
||||
audit_fenced_markdown = _fence_language(stripped) in _MARKDOWN_FENCE_LANGUAGES
|
||||
elif fence == marker:
|
||||
fence = None
|
||||
audit_fenced_markdown = False
|
||||
index += 1
|
||||
continue
|
||||
|
||||
if fence is not None:
|
||||
if fence is not None and not audit_fenced_markdown:
|
||||
index += 1
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user