i'm getting started on creating an html editor. one of the requirements is that i must be able to format the html tags so that they appear blue, text outside of the tags appear as black, notes appear as green, and errors appear as red. ideally, i would like to be able to give the end user the flexibility to change the above styles to fit their needs as well as to be able to let them add their own formatting styles.

thus far, i have been able to use the keypress event to accurately format text at the end of the document. however, this does not work well (or at all) when adding and deleting text in the middle of the document. to correct this, i tried using a refresh routine to run through the entire document, but this is incredibly slow for large files. i've considered using this same technique for a limited area around the cursor, but this still does not seem as efficient as it could be. another method i have considered is building an array that contains the location of all "<" or ">" symbols. i could then use this as a sort of map. but this may or may not be much faster. i would really love to hear suggestions on how to best approach this problem.