diff --git a/docs/users/changelog.md b/docs/users/changelog.md index c1427df..1cf4408 100644 --- a/docs/users/changelog.md +++ b/docs/users/changelog.md @@ -3,6 +3,11 @@ This log documents all Python API or CLI breaking backwards incompatible changes. Note that there is currently no guarantee for a stable Markdown formatting style across versions. +## **unreleased** + +- Deprecated + - `mdformat.codepoints.ASCII_WHITESPACE` + ## 0.7.19 - Deprecated diff --git a/src/mdformat/codepoints/__init__.py b/src/mdformat/codepoints/__init__.py index 25cfe95..37929c1 100644 --- a/src/mdformat/codepoints/__init__.py +++ b/src/mdformat/codepoints/__init__.py @@ -5,8 +5,27 @@ "ASCII_WHITESPACE", ) +import warnings + from mdformat.codepoints._unicode_punctuation import UNICODE_PUNCTUATION from mdformat.codepoints._unicode_whitespace import UNICODE_WHITESPACE ASCII_CTRL = frozenset(chr(i) for i in range(32)) -ASCII_WHITESPACE = frozenset({chr(9), chr(10), chr(11), chr(12), chr(13), chr(32)}) + + +def __getattr__(name: str) -> frozenset[str]: + """Attribute getter fallback. + + Used during the deprecation period of `ASCII_WHITESPACE`. + """ + if name == "ASCII_WHITESPACE": + warnings.warn( + "ASCII_WHITESPACE is deprecated because CommonMark v0.30 no longer " + "defines ASCII whitespace.", + DeprecationWarning, + stacklevel=2, + ) + return frozenset({chr(9), chr(10), chr(11), chr(12), chr(13), chr(32)}) + raise AttributeError( + f"module {__name__!r} has no attribute {name!r}" + ) # pragma: no cover diff --git a/src/mdformat/renderer/_util.py b/src/mdformat/renderer/_util.py index c9313e9..45a17a4 100644 --- a/src/mdformat/renderer/_util.py +++ b/src/mdformat/renderer/_util.py @@ -65,9 +65,7 @@ def longest_consecutive_sequence(seq: str, char: str) -> int: def maybe_add_link_brackets(link: str) -> str: """Surround URI with brackets if required by spec.""" - if not link or ( - codepoints.ASCII_CTRL | codepoints.ASCII_WHITESPACE | {"(", ")"} - ).intersection(link): + if not link or (codepoints.ASCII_CTRL | {" ", "(", ")"}).intersection(link): return "<" + link + ">" return link diff --git a/tests/test_api.py b/tests/test_api.py index 20c8f80..ce90049 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -141,3 +141,8 @@ def test_mdrenderer_no_finalize(tmp_path): unfinalized = MDRenderer().render(tokens, {}, env, finalize=False) finalized = MDRenderer().render(tokens, {}, env) assert finalized == unfinalized + "\n\n[gl ref]: https://gitlab.com\n" + + +def test_ascii_whitespace_deprecation(): + with pytest.warns(DeprecationWarning): + mdformat.codepoints.ASCII_WHITESPACE