There are tools off-the-shelf, so why re-designing all the stuff?
Basing on highlight.js, I enhanced the highlighting rules in the following aspects:
The following paragraphs refer to the paragraphs in the source code.
Commands
Instead of enumerating all possible commands, hightlight.js used a different approach: They listed out all officially-approved verbs, since every PowerShell command is in the form of VERB-NOUN. Therefore, I switched to their method.
For the old method, commands starting with these verbs would not be highlighted properly:
Redo-
Search-
Skip-
Step-
Watch-
Edit-
Merge-
Unpublish-
Approve-
Deny-
Request-
Submit-
Ping-
There was a buggy rule cd.. in the old method (line 7). Since it was regex, it would highlight cdaa but not cd...
In addition, I added 157 new built-in aliases, such as clear, kill and copy, basing on highlight.js.
Operators
Basing on highlight.js, I added 47 more operators, such as -ceq, -clike and -split.
Keywords (aka Statements)
Basing on highlight.js, I added 28 more keywords, such as try, catch, using and class.
Types
Types such as string or int were not being highlighted originally.
Basing on highlight.js, I added 14 new built-in types.
Comments
There was a bug for block comment. That is, in the following example, Get-Help would be recognized as a comment, but in fact it should not.
<# comment #> Get-Help
Quoted text
Here-strings are strings starting with @" or @' and ending with "@ or '@.
The old rules only consider @-with-double-quotes, but not @-with-single-quotes.
Color-coding convention
I changed to a more mainstream color-coding convention (eg. Bash), which is the same as PR #357.
Description
There are tools off-the-shelf, so why re-designing all the stuff? Basing on highlight.js, I enhanced the highlighting rules in the following aspects:
Commands
VERB-NOUN
. Therefore, I switched to their method.cd..
in the old method (line 7). Since it was regex, it would highlightcdaa
but notcd..
.clear
,kill
andcopy
, basing on highlight.js.Operators
-ceq
,-clike
and-split
.Keywords (aka Statements)
try
,catch
,using
andclass
.Types
string
orint
were not being highlighted originally.Comments
Get-Help
would be recognized as a comment, but in fact it should not.Quoted text
@"
or@'
and ending with"@
or'@
.Color-coding convention
Summary
To sum up, these are my enhancements:
Before
After