کد Highlight Syntax برای JavaScript در این نمونه:

Screenshot 2025-01-16 113506.jpg

Public Class JavaScript
Protected Friend Shared Sub Highlight(ByRef Line As String)
Dim CompleteLine As Boolean = False
If Line.EndsWith(";") Then
CompleteLine = True
Line = Line.Remove(Line.Length - 1, 1)
End If
Dim Words As String() = Line.Split(" ")
Dim List As New List(Of String)
Dim BeginString, BeginComment, BeginCommentLine As Boolean
For Each Word As String In Words
If (Word.StartsWith(Chr(34)) Or Word.StartsWith(Chr(39))) AndAlso (BeginString = False And BeginComment = False And BeginCommentLine = False) Then
BeginString = True
If (Word.Trim.Length > 1) AndAlso (Word.EndsWith(Chr(34)) Or Word.EndsWith(Chr(39))) Then
BeginString = False
List.Add(String.Format("<str>{0}</str>", Word))
Else
List.Add(String.Format("<str>{0}", Word))
End If
ElseIf (Word.Trim.EndsWith(Chr(34)) Or Word.Trim.EndsWith(Chr(39))) And BeginString = True Then
BeginString = False
List.Add(String.Format("{0}</str>", Word))
ElseIf Word.StartsWith("/*") AndAlso (BeginString = False And BeginComment = False And BeginCommentLine = False) Then
BeginComment = True
List.Add(String.Format("<cm>{0}", Word))
ElseIf Word.EndsWith("*/") AndAlso BeginComment = True Then
BeginComment = False
List.Add(String.Format("{0}</cm>", Word))
ElseIf Word.StartsWith("//") AndAlso (BeginString = False And BeginComment = False And BeginCommentLine = False) Then
BeginCommentLine = True
List.Add(String.Format("<cm>{0}", Word))
ElseIf JavaScriptKeyWords.Contains(Word.Trim) AndAlso (BeginString = False And BeginComment = False And BeginCommentLine = False) Then
List.Add(String.Format("<kw>{0}</kw>", Word))
Else
List.Add(Word)
End If
Next
If BeginCommentLine = True Then List.Add("</cm>")
Dim Expr As String = Join(List.ToArray, " ")
List.Clear()
Line = Expr + If(CompleteLine, ";", "")
Debug.Print(" => {0}", Line)
End Sub
End Class




Public JavaScriptKeyWords() As String = {"abstract",
"arguments", "await", "boolean", "break", "byte", "case",
"catch", "char", "class", "const", "continue", "debugger",
"default", "delete", "do", "double", "else", "enum",
"eval", "export", "extends", "false", "final", "finally",
"float", "for", "function", "goto", "if", "implements",
"import", "in", "instanceof", "int", "interface", "let",
"long", "native", "new", "null", "package", "private",
"protected", "public", "return", "short", "static",
"super", "switch", "synchronized", "this", "throw",
"throws", "transient", "true", "try", "typeof", "var",
"void", "volatile", "while", "with", "yield"}