`black==25.11.0` removing `%% [markdown]` comments
Describe the bug
As of black==25.11.0 but not in black==25.9.0, it's removing extra code comments.
To Reproduce
Run black a.py on the below:
# %% [markdown]
# fmt: off
# fmt: on
It overzealously removes the top comment, leaving just:
# fmt: off
# fmt: on
Expected behavior
black to not remove the header comments, as they're part of Jupytext's percent format.
Environment
- Black's version: 25.11.0 (and current
mainbranch atblack==25.11.1.dev3+gf209c53a0) - OS: macOS 15.6.1, build version 24G90
- Python version: Python 3.13.5 (main, Jul 10 2025, 15:26:00) [Clang 17.0.0 (clang-1700.0.13.5)]
Additional context
Coming from https://github.com/mwouts/jupytext/issues/1467#issuecomment-3536887316
@jamesbraza i created a pr on this issue. #4845 it will help resolve this integration issue between Jupytext and Black.
@jamesbraza ---Issue #4843 is RESOLVED ✅
Black 25.11.0 was incorrectly removing # %% [markdown] comments.
The fix updates _handle_comment_only_fmt_block() in black/comments.py to preserve comments before # fmt: off.
All tests pass, and the reproduction case now works correctly — the # %% [markdown] comment is preserved.