def convert_one_fmt_off_pair(
    node: Node, mode: Mode, lines: Collection[tuple[int, int]]
) -> bool:
    """Convert content of a single `# fmt: off`/`# fmt: on` into a standalone comment.

    Returns True if a pair was converted.
    """
    for leaf in node.leaves():
        previous_consumed = 0
        for comment in list_comments(leaf.prefix, is_endmarker=False):
            is_fmt_off = comment.value in FMT_OFF
            is_fmt_skip = _contains_fmt_skip_comment(comment.value, mode)
            if (not is_fmt_off and not is_fmt_skip) or (
                # Invalid use when `# fmt: off` is applied before a closing bracket.
                is_fmt_off
                and leaf.type in CLOSING_BRACKETS
            ):
                previous_consumed = comment.consumed
                continue
            # We only want standalone comments. If there's no previous leaf or
            # the previous leaf is indentation, it's a standalone comment in
            # disguise.
            if comment.type != STANDALONE_COMMENT:
                prev = preceding_leaf(leaf)
                if prev:
                    if is_fmt_off and prev.type not in WHITESPACE:
                        continue
                    if is_fmt_skip and prev.type in WHITESPACE:
                        continue

            ignored_nodes = list(generate_ignored_nodes(leaf, comment, mode))
            if not ignored_nodes:
                continue

            first = ignored_nodes[0]  # Can be a container node with the `leaf`.
            parent = first.parent
            prefix = first.prefix
            if comment.value in FMT_OFF:
                first.prefix = prefix[comment.consumed :]
            if is_fmt_skip:
                first.prefix = ""
                standalone_comment_prefix = prefix
            else:
                standalone_comment_prefix = (
                    prefix[:previous_consumed] + "\n" * comment.newlines
                )
            hidden_value = "".join(str(n) for n in ignored_nodes)
            comment_lineno = leaf.lineno - comment.newlines
            if comment.value in FMT_OFF:
                fmt_off_prefix = ""
                if len(lines) > 0 and not any(
                    line[0] <= comment_lineno <= line[1] for line in lines
                ):
                    # keeping indentation of comment by preserving original whitespaces.
                    fmt_off_prefix = prefix.split(comment.value)[0]
                    if "\n" in fmt_off_prefix:
                        fmt_off_prefix = fmt_off_prefix.split("\n")[-1]
                standalone_comment_prefix += fmt_off_prefix
                hidden_value = comment.value + "\n" + hidden_value
            if is_fmt_skip:
                hidden_value += comment.leading_whitespace + comment.value
            if hidden_value.endswith("\n"):
                # That happens when one of the `ignored_nodes` ended with a NEWLINE
                # leaf (possibly followed by a DEDENT).
                hidden_value = hidden_value[:-1]
            first_idx: Optional[int] = None
            for ignored in ignored_nodes:
                index = ignored.remove()
                if first_idx is None:
                    first_idx = index
            assert parent is not None, "INTERNAL ERROR: fmt: on/off handling (1)"
            assert first_idx is not None, "INTERNAL ERROR: fmt: on/off handling (2)"
            parent.insert_child(
                first_idx,
                Leaf(
                    STANDALONE_COMMENT,
                    hidden_value,
                    prefix=standalone_comment_prefix,
                    fmt_pass_converted_first_leaf=first_leaf_of(first),
                ),
            )
            return True

    return False
Convert content of a single `# fmt: off`/`# fmt: on` into a standalone comment.

    Returns True if a pair was converted.
    
src/black/comments.py