2 ms·
There are two main problems with such solution (and any other existing JS based code colorizers): 1. Use of regular expressions. Hard to get effective solution
by c-smile 10y ago
There are two main problems with such solution (and any other existing JS based code colorizers):
1. Use of regular expressions. Hard to get effective solution with that. Yet that famous parsing HTML by regex answer: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 http://stackoverflow.com/questions/1732348/regex-match-open-...
2. It modifies the DOM. Not desirable in most cases and heavy: each DOM element takes 0.2k..1.0k in memory. Yet DOM handling in browsers is O(N) complex (N - number of DOM elements).
Just in case, in Sciter (http://sciter.com http://sciter.com) I've added an option to style character runs so without DOM modification: Selection.applyMark(runStart, runEnd, name) and special ::mark(name) pseudo-element in CSS to style those runs.
Illustrations: http://sciter.com/tokenizer-mark-syntax-colorizer/ http://sciter.com/tokenizer-mark-syntax-colorizer/