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/> ');
}
}
};