It seems formatting "around" wordpress features and needs is a pretty heavy job, and despite online criticism I've read, I bet it was designed the best possible for backwards compatibility and manual edition in the post editor.
Many reasons have made that code VERY specific for wordpress. It's not just a paragraph converter function, but it takes into account shortcodes, quicktags, etc. so
Can you please allow me to plug into it?
Currently adding content between paragraphs, for example, makes me having to replicate 3/4 of the wpautop function, and run it along with SOME of the texturize filter, or replicate the whole get_the_content() behavior…
I'd like to see those heavy functions to be pluggable at the stages where the paragraphs have been split, or cleaned of extra spaces, or balanced tags, etc.
or arrays like
post_content_paragraphs (array of p's)…
but most importantly, subsequent functions like get_the_content() to USE that info if found, because I found nowhere to replace the post_content after read from the DB and THAT makes it available for the rest of the functions
If there are strong reasons to always get_the_content() from the DB, even if the data is already in the running $post object, you could add a little conditional to use the current data in $post if a change has made to it after read from the DB?
I find an exponentially growing amount of old sites being updated, with hundreds of posts and most need re-paragraphizing text (the owner pasted/worked the copy in such a way that there are NO paragraphs at all) and taking advantage of the logic you already came up with to cleanup post content without creating another whole engine replicating 80% of your code would be great.
I just exposed many ideas, probably misconceptions, to save our time from a long topic asking/explaining those. If you don't have the time to correct me, or to guess what I meant and consider the multiple possible answers too much to waste your time on, please be corteous and either name me a few keywords to research myself or just don't answer, but please don't try to shake me off with a blunt short answer. Someone else could answer in the following years.