- fix Не появляется пустая странициа перед названием таблицы - fix Не появляется пустая страница перед альбомной ориентацией - fix При отказе от изменений создаётся новый файл - fix Замена "..." на «...» больше не затрагивает uml и mermaid блоки
This commit is contained in:
+40
-6
@@ -99,6 +99,38 @@ def get_profile(doc_type: str) -> DocProfile:
|
||||
|
||||
# --- text autofixes ---
|
||||
|
||||
# ```uml / ```mermaid / ```uml-c4 / ```bpmn … — кавычки и тире там синтаксис
|
||||
_FENCE_RE = re.compile(
|
||||
r"^(?P<fence>`{3,}|~{3,})(?P<info>[^\n]*)\n"
|
||||
r"(?P<body>[\s\S]*?)"
|
||||
r"^(?P=fence)[ \t]*(?:\n|$)",
|
||||
re.M,
|
||||
)
|
||||
|
||||
|
||||
def _fence_lang(info: str) -> str:
|
||||
return (info.strip().split() or [""])[0].lower()
|
||||
|
||||
|
||||
def _is_diagram_fence_info(info: str) -> bool:
|
||||
from .diagram_schemes import is_diagram_lang
|
||||
return is_diagram_lang(_fence_lang(info))
|
||||
|
||||
|
||||
def _map_outside_diagram_fences(text: str, fn) -> str:
|
||||
"""Apply fn only outside UML / Mermaid / scheme fences."""
|
||||
out: list[str] = []
|
||||
pos = 0
|
||||
for m in _FENCE_RE.finditer(text):
|
||||
if not _is_diagram_fence_info(m.group("info")):
|
||||
continue
|
||||
out.append(fn(text[pos:m.start()]))
|
||||
out.append(m.group(0))
|
||||
pos = m.end()
|
||||
out.append(fn(text[pos:]))
|
||||
return "".join(out)
|
||||
|
||||
|
||||
def fix_russian_quotes(text: str) -> str:
|
||||
"""Replace "..." with «...» for Russian text segments (heuristic)."""
|
||||
def repl(m):
|
||||
@@ -142,12 +174,14 @@ def dash_separator() -> str:
|
||||
def preprocess_markdown(text: str, emdash_to_hyphen: bool | None = None) -> str:
|
||||
if emdash_to_hyphen is not None:
|
||||
set_emdash_to_hyphen(emdash_to_hyphen)
|
||||
text = fix_russian_quotes(text)
|
||||
if _EMDASH_TO_HYPHEN:
|
||||
# Keep ASCII hyphens; flatten any em dashes from the source
|
||||
text = replace_emdash_with_hyphen(text)
|
||||
else:
|
||||
text = fix_dashes(text)
|
||||
|
||||
def _apply(chunk: str) -> str:
|
||||
chunk = fix_russian_quotes(chunk)
|
||||
if _EMDASH_TO_HYPHEN:
|
||||
return replace_emdash_with_hyphen(chunk)
|
||||
return fix_dashes(chunk)
|
||||
|
||||
text = _map_outside_diagram_fences(text, _apply)
|
||||
text = separate_biblio_lines(text)
|
||||
return text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user