SyCODE Syntax Highlighter is a syntax highlighting program based on javascript. The implementation method draws on the famous db.SyntaxHighlighter to use regular expressions for keyword matching. The processing speed is 5 to 10 times higher than db.SyntaxHighlighter. It is currently the fastest processing speed. Fast javascript syntax highlighting program.
SyCODE Syntax Highlighter has the characteristics of high speed and strong scalability. It can easily complete 32KB code highlighting processing on a current mainstream PC, and can complete 64KB code highlighting processing at one time without the script slow prompt. By adding different Regular expressions can implement syntax highlighting in any programming language.
SyCODE Syntax Highlighter 1.0 has internally 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/Vb.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/>');
}
}
};