Files
fotoplaner/venv/lib/python3.12/site-packages/docling/backend/latex/utils/whitespace.py
T
anders 16c54c6653 Tilføjet venv med docling og afhængigheder
Testfiler opdelt i PNG og previews
2026-10-27 12:20:23 +01:00

23 lines
631 B
Python

# SPDX-FileCopyrightText: The Docling Contributors
# SPDX-License-Identifier: MIT
"""Whitespace normalization for text taken from LaTeX source."""
from __future__ import annotations
import re
_WHITESPACE_RUN = re.compile(r"[ \t\r\n]+")
def collapse_source_layout_whitespace(text: str) -> str:
"""Replace each whitespace run that has a tab or line break with one space.
Runs of plain spaces stay unchanged. Each run is matched once, so the work is
linear in the text length.
"""
return _WHITESPACE_RUN.sub(
lambda match: match.group() if not match.group().strip(" ") else " ",
text,
)