In response to the suggestion of Deyi Xiaoshe, I sorted out the JavaScript syntax coloring engine I wrote last year and provided downloads. If you like it, take it, hehe
In general, it is a very simple thing, just providing keyword shading and some basic syntax (such as comments, strings, regulars, etc.), and it should be easy to see its usage from the demo. Here is a brief introduction:
Class name: Lighter
You can get a shading engine instance through new Lighter(). Assume it is a lighter, with the following properties and methods:
Language properties:
The scope of this attribute can be added by itself according to the number of syntax files. The demos provided include four syntax files: 'cpp', 'js', 'xml', and 'java'. Everyone is welcome to provide more syntax files:)
Coloring method: (code)
This is the core coloring function. Code is the code to be colored. The method returns the color of the color, and the code color is implemented using the html tag.
Syntax extension: (object)
This is a static method called by class name, the parameters are javascript objects, and the syntax keyword information is included. You can refer to the format in lang/ to extend the syntax file yourself. Independent syntax files can be directly marked with <script> in html, or they can be loaded dynamically using the provided $import method. It should be noted that the syntax file must be added after the class definition and before the class instantiation.
Already syntax files:
It is also a static property that represents the collection of currently supported languages.
Demo address:/codelighter/
Download address:/codelighter/
Local download
In general, it is a very simple thing, just providing keyword shading and some basic syntax (such as comments, strings, regulars, etc.), and it should be easy to see its usage from the demo. Here is a brief introduction:
Class name: Lighter
You can get a shading engine instance through new Lighter(). Assume it is a lighter, with the following properties and methods:
Language properties:
The scope of this attribute can be added by itself according to the number of syntax files. The demos provided include four syntax files: 'cpp', 'js', 'xml', and 'java'. Everyone is welcome to provide more syntax files:)
Coloring method: (code)
This is the core coloring function. Code is the code to be colored. The method returns the color of the color, and the code color is implemented using the html tag.
Syntax extension: (object)
This is a static method called by class name, the parameters are javascript objects, and the syntax keyword information is included. You can refer to the format in lang/ to extend the syntax file yourself. Independent syntax files can be directly marked with <script> in html, or they can be loaded dynamically using the provided $import method. It should be noted that the syntax file must be added after the class definition and before the class instantiation.
Already syntax files:
It is also a static property that represents the collection of currently supported languages.
Demo address:/codelighter/
Download address:/codelighter/
Local download