How to export Codemirror mini canvas

I’m trying to export the code in Codemirror into a canvas (Use the html2canve library).
But I found that the canvas contains only part of the code block. Because Codemirror only renders DOM nodes within the scope of the window. (DOM nodes not in the window cannot be captured by html2canve library)

How can I make Codemirror render all DOM nodes on the page when I export the canvas so that I can get those DOM nodes.

Can you give me some suggestions?

Is there any way that I can get all highlighted DOM nodes or HTML strings.
In this way, I can replace the contents of the clone node in the cloning phase of the html2canves library.

You could use highlightTree to generated highlighted HTML for the code (possibly using the syntax tree that is already in the editor state), I guess.