Can I save and load a tokenized version of the text?

I’d like to try using codeMirror to try and create a text editor for viewing and editing semantic markup for normal text.

So the editor might display “The cat sat on the mat.”
But the text might be
"The <span type="noun" name="felix" age="6" owner="John" >cat</span> sat on the mat."
and clicking on the word “cat” could trigger another form to load the details for editing.

From reading through the documentation and some simple testing I think I could use the “markText” method to hide and highlight text, but thought there might be a better way to do this and maybe I should be reading more into the language modes. Or looking as the Lezer Parser system?

Lange modes and parsers just take the text as input, so they wouldn’t know the name and age of the cat. I think for an application like this you will need to keep your own data structure with the metadata, and add it to the text on load. You could use something like getAllMarks to find the marks in the document when saving, but making sure these stay meaningful during editing will require a bunch of custom code, i expect.

1 Like