At the suggestion of Deyi Little Snake, I sorted out the JavaScript syntax coloring engine I wrote last year and provided it for download. If you like it, feel free to take it. Hehe
Generally speaking, it is a very simple thing. It only provides keyword coloring. As well as some basic syntax (such as comments, strings, regular expressions, etc.), its usage should be easy to see from the demo. Here is a brief introduction:
Class name: Lighter
Can be obtained through new Lighter() A shader engine instance, assuming it is lighter, has the following attributes and methods:
Language attribute: lighter.language
The range of this attribute can be added based on the number of grammar files. The provided demo includes 'cpp' , 'js' , 'xml' , 'java' four grammar files, you are welcome to provide more grammar files:)
Coloring method: lighter.highlight(code)
This is the core coloring function, code It is the code to be colored. The method returns the colored code. The code color is implemented using html tags.
Syntax extension: Lighter.addLanguage(object)
This is a static method, called through the class name. The parameter is a javascript object, which contains syntax keyword information. You can see the format in lang/demo.js to expand it yourself. Grammar file. Independent grammar files can be linked directly in HTML using <script> tags, or they can be dynamically loaded using the provided $import method. It should be noted that the syntax file must be added after the class definition and before the class is instantiated. <BR>Existing grammar file: Lighter.supportedLanguages <BR>It is also a static attribute, indicating the collection of currently supported languages. <br><br>Demo address: <A href="http://www.supnate.com/codelighter/demo.html" target=_blank>http://www.supnate.com/codelighter/demo.html <BR>Download address: <A href="http://www.supnate.com/codelighter/X2CodeLighter.rar">http://www.supnate.com/codelighter /X2CodeLighter.rar <br><br><A href="http://files.jb51.net/upload/X2CodeLighter.rar" target=_blank>Local download</script>