Reformatting gemini text

Gemini prescribes putting whole paragraphs in single line. I find it extremely unfortunate, since it places burden of textwrapping on client instead of server. Wrapping text is art, smashing whole paragraph into single line is one shell command. Unfortunately, I can do nothing but adapt, so I write my articles with semantic linefeeds, and post-process them during the build. Here is the command, using GNU sed:

$ sed -z -r -e 's/```/\x0/g' -e 's/([^`\n])\n([a-zA-Z])/\1 \2/g' -e 's/\x0/```/g'

Handling of verbatim blocks is left as excercise for the reader.

Update (2021-06-30): There is small program written in C that does exactly that, respecting verbatim blocks. Thanks to Sandra Snan for hint.