def merge_markdown(nb: nbf.notebooknode.NotebookNode) -> None:
    """Merges consequent markdown cells into one."""
    start_idx = None
    slices = []
    for i, cell in enumerate(nb["cells"]):
        if cell["cell_type"] == "markdown":
            if start_idx is None:
                start_idx = i
        else:
            if start_idx is not None:
                if i - start_idx > 1:
                    slices.append(slice(start_idx, i))
                start_idx = None
    for sl in slices[::-1]:
        nb["cells"][sl.start]["source"] = "\n\n".join([c["source"].rstrip() for c in nb["cells"][sl]])
        del nb["cells"][sl.start + 1: sl.stop]  # nb["cells"][sl] does not work properly
Merges consequent markdown cells into one.
utils/prepare/optimize_ipynb.py