how to insert custom dom to codemirror6

I want to achieve this effect. The number 3 in the picture is a dynamically generated field. When I click, it will generate the DOM structure at the number 2 in the picture. Thank you