Should be proud of the suggestion of the snake, I tidied up a bit last year wrote the JavaScript syntax coloring engine, and provide downloads, like even though take it, hey
In general, it's very simple to provide a keyword coloring as well as some basic syntax (such as annotations, strings, regular, and so on), which should be easy to see in the demo, here is a brief introduction:
Class Name: Lighter
With the new lighter () you can get a shaded engine instance, assuming lighter, with the following properties and methods:
Language attributes: Lighter.language
The scope of this attribute can be based on the number of grammar files to add themselves, the demo provided by the ' CPP ', ' JS ', ' xml ', ' Java ' Four grammar files, welcome to provide more grammar files:
Coloring method: Lighter.highlight (Code)
This is the core of the coloring function, code is to be shaded codes, methods to return the coloring code, code color using HTML markup implementation.
Syntax Extensions: Lighter.addlanguage (object)
This is a static method called by the class name, the parameter is a JavaScript object, contains the syntax keyword information, you can see the format of Lang/demo.js to expand the grammar file. Independent grammar files can be used either directly in HTML <script> tag links, or dynamically loaded using the $import method provided. Note that the grammar file must be added after the class definition, before the class is instantiated.
Existing Grammar file: Lighter.supportedlanguages
is also a static property that represents the collection of currently supported languages.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.