How can I merge paragraphs in a code block?

I’m using setBlockType from prosemirror-commands to convert some paragraphs to code when selected. However, every paragraph is wrapped in each own pre block (see ProseMirror’s homepage, for example). What I want is one code block created. How can I do that?

You’d have to, after changing the paragraphs to code blocks, replace the boundaries between the affected ones (the range from the end of one code block to the start of the next one, covering the closing and opening tokens for the code blocks) with a newline (or two?).