Powerful syntax highlighting engine implemented by javascript

Source: Internet
Author: User

Powerful syntax highlighting engine implemented by javascript


SyCODE Syntax Highlighter is a javascript-based Syntax highlighting program. The implementation method draws on the famous db. SyntaxHighlighter to use regular expressions for keyword matching. The processing speed is 5 ~ higher than db. SyntaxHighlighter ~ 10 times as fast as the current javascript syntax highlighting program.

SyCODE Syntax Highlighter features high speed and scalability. On a mainstream PC, you can easily complete 32 KB code highlighting, 64 kB code highlighting can be completed at one time without a slow script prompt. Different regular expressions can be added to achieve syntax highlighting in any programming language.

Syntax Highlighter 1.0 has implemented Syntax highlighting for more than 20 languages, including:
1. C/C ++
2. C #
3. CSS
4. Delphi/Kylix
5. Pascal
6. Java
7. Vb B .net
8. J (ava) Script
9. ActionScript
10. Php
11. Python
12. Ruby/Rails
13. Perl
14. Assembly
15. Bat batch processing
16. UNIX Shell
18. AWK
19. SQL
20. xml/xhtml

Example: Highlighter. Execute (cleanCode, language );

Effect:
Var Highlighter = {
Brushes :{},
RegexLib :{
MultiLineCComments: new RegExp ('/\ * [\ s \ S] *? \ */', 'GM '),
SingleLineCComments: new RegExp ('//. * $', 'GM '),
SingleLinePerlComments: new RegExp ('#. * $', 'GM '),
DoubleQuotedString: new RegExp ('"(? : \. | (\ ") | [^ \" "\ N]) *" ', 'G '),
SingleQuotedString: new RegExp ("'(? : \. | (\ ') | [^ \ ''\ N]) *'", 'G ')
},
Match: function (value, index, css ){
This. value = value;
This. index = index;
This. length = value. length;
This.css = css;
},
Execute: function (str, lang ){
Var registered = new Object ();
For (var brush in Highlighter. Brushes)
{
Var aliases = Highlighter. Brushes [brush]. Aliases;
If (aliases = null) continue;
For (var I = 0; I <aliases. length; I ++) registered [aliases [I]. toLowerCase ()] = brush;
};
If (!! Registered [lang. toLowerCase ()]) {
Var ht = new Highlighter. Brushes [registered [lang. toLowerCase ()] ();
Return ht. Highlight (str );
}
Else {
Str = str. replace (/&/g ,'&');
Str = str. replace (/</g, '<');
Str = str. replace (/>/g, '> ');
Str = str. replace (/\ t/g ,'');
Str = str. replace (/[] {2}/g ,'');
Return str. replace (/\ n/g, '<br/> ');
}
}
};

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.