I want a simple real-time syntax highlighting in a tinyMce editor.
I want to highlight (change background or color of the text) for every #{keyword} and #{more keywords} in the text. Keyword can only contain letters, numbers and dots (.).
I don’t know if my idea is good:
- bind to onChange event of the editor
- remove all occurrences of
<span class="code">#{keyword}</span>(regex) - find all #{keyword} and replace them with #{found keyword}
(css class code would have background set to some color)
Any ideas how to solve this problem?
Binding to the onChange event seems ok, but you should consider using the onKey— events too. I hope the following code snippet will be helpfull for you:
css (to be defined in content_css i.e.):
js helpfunctions:
on event call: