Merge identical blocks when using wrapIn

I have some emphasis block that behave a bit like code blocks. When two of those blocks touch, I want them to be merged them automatically.

For example, this:

<div class="important"><p>foo</p></div>
<div class="important"><p>bar</p></div>

Would be merged to

<div class="important"><p>foo</p><p>bar</p></div>

I found this topic: How can I merge paragraphs in a code block? - #2 by marijn

But it does not really help me. To create my block, I use wrapIn from prosemirror-commands.

It should be possible to write your command so that it follows the wrapIn with join calls when appropriate.