Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to implement a super syntax highlighting engine with Javascript

Shulou Source: shulou.com Published: 2022-05-31 11:53:17 10月01日 Update

Most people do not understand the knowledge points of this article "Javascript how to achieve a super grammar highlighting engine", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Javascript how to achieve a super grammar highlighting engine" article.

SyCODE Syntax Highlighter has the characteristics of high speed and strong expansibility, it can easily complete the code highlighting processing of 32KB on a current mainstream PC, and can complete the code highlighting processing of 64KB at one time without the slow prompt of script. Syntax highlighting processing of any programming language can be realized by adding different regular expressions.

Syntax highlighting in more than 20 languages has been implemented within SyCODE Syntax Highlighter 1.0, including:

1. C _ blank +

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 = Highlight. Brushes.aliases

If (aliases = = null) continue

For (var itemositani}

If (!! registered [lang.toLowerCase ()]) {

Var ht = new Highlighter.Brushes [registered [lang.toLowerCase [)] ()

Return ht.Highlight (str)

}

Else {

Str = str.replace (/ & / g,'&')

Str = str.replace (/ str = str.replace (/ > / g,'>')

Str = str.replace (/\ t Compact g,'')

Str = str.replace (/ [] {2} / g,'')

Return str.replace (/\ nUnip g,'

')

}

}

}

The above is about the content of this article on "how to achieve a super grammar highlighting engine in Javascript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

Tags: Highlighting syntax content engine processing code articles knowledge articles different slow one-time mainstream value extensibility most that is more regular steps Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB MySQL Linux Huawei