Return text including highlight spans

Im trying to make a bunch of code snippets Perl Golf Dictionary and Im finding my application is really slow to load up with my current method of dynamically creating a bunch of textboxes, calling the CodeMirror.fromTextArea function on each text box, then extracting the contents manually to place into the table, deleting the code mirror thing afterwards. I am aware I could just hardcode the information into the html each time but Im curious if there is a better way. Maybe something involving returning the text instead of displaying it onto the code mirror object it creates.

ah found the CodeMirror.runMode extension. runs smooth as butter and much simpler than what I was doing lol https://codemirror.net/5/addon/runmode/runmode.js