Split your 'rmarkdown' or 'quarto' files by sections into a tibble: titles, text, chunks. Rebuild the file from the tibble.
conda install conda-forge::r-lightparser