import re


def format_comments_after_cell_delimiters(text: str) -> str:
    """Ensure single space between cell delimiter and possible comment on same line.

    --- before ---
    # %%some comment
    # %%     another comment
    --- after ---
    # %% some comment
    # %% another comment
    """
    # [^\S\n\r] = not non-whitespace and not new line or carriage return
    return re.sub(r"(?m)^# %%[^\S\n\r]*(\S)", r"# %% \g<1>", text)