I sorted out the Javascript syntax coloring engine I wrote last year and provided the download. Even if you like it
In general, it is very simple. It only provides the coloring of keywords and some basic syntaxes (such as comments, strings, and regular expressions). It is easy to see its usage in the demo, here is a brief introduction:
Class Name: lighter
You can use new lighter () to obtain a coloring engine instance, which is assumed to be lighter. It has the following attributes and methods:
Language attribute: lighter. Language
The range of this attribute can be added by yourself based on the number of syntax files. The provided demo contains four syntax files: 'cpp ', 'js', 'xml', and 'java, you are welcome to provide more syntax files :)
Coloring method: lighter. Highlight (CODE)
This is the core coloring function, and the code needs to be colored. CodeThe method returns the colored code, and the color of the Code is implemented using HTML tags.
Syntax Extension: lighter. addlanguage (object)
This is a static method called by class name. The parameter is a JavaScript Object and contains syntax keyword information. For details, see the format extension syntax file in lang/demo. js. An independent syntax file can be directly tagged with <SCRIPT> links in HTML, or dynamically loaded using the $ import method provided. Note that the syntax file must be added before class instantiation after class definition.
Existing syntax file: lighter. supportedlanguages
It is also a static attribute, indicating a set of currently supported languages.
Demo address: http://www.supnate.com/codelighter/demo.html
: Http://www.supnate.com/codelighter/X2CodeLighter.rar
Local download