- Install NoteHighlight2016
- Modify Ribbon file
- Create custom .lang file
- Close, open OneNote
- Profits
1) Install NoteHighlight2016
https://github.com/elvirbrk/NoteHighlight2016/tree/master
2) Modify Ribbon file
“C:\Program Files\CodingRoad\NoteHighlight2016\ribbon.xml“
Add this line as shown in the screenshot:
<button id="buttonKQL" label="KQL" size="large" screentip="Enter KQL Code" onAction="AddInButtonClicked" tag="kql" image="SQL.png" visible="true"/>
3) Create custom .lang file for your language
Understanding the .lang File Markup
The .lang
file is a configuration file used by the NoteHighlight extension to highlight the syntax of code. Here’s a breakdown of the structure:
- Description: Provides a brief description of the language.
- Categories: Lists the categories under which this language falls.
- Keywords: A list of keywords categorized by their usage. Each category has an
Id
and aList
of keywords or aRegex
pattern for identifying keywords. - Strings: Defines the delimiters used for string literals.
- IgnoreCase: Indicates whether the keywords are case-insensitive.
- Comments: Defines the syntax for single-line and multi-line comments.
- Operators: Lists the operators used in the language.
Create the file below, save it as ‘sql.lang’ in this directory:
C:\Program Files\CodingRoad\NoteHighlight2016\highlight\langDefs
The root name of this file, “kql“, must match the tag value in the ribbon file entry:
tag=”kql”
Description="KQL"
Categories = {"database"}
Keywords={
{ Id=1,
List={
"add", "ago", "alias", "and", "as", "asc", "auto", "avg", "between", "by",
"count", "dcount", "datetime", "desc", "extend", "facet", "false", "find",
"from", "in", "join", "let", "limit", "mv-expand", "not", "or", "order",
"project", "project-away", "project-rename", "range", "regex", "repl",
"sample", "scan", "schema", "search", "serialize", "set", "sort", "summarize",
"take", "top", "true", "union", "where", "with", "startswith", "contains",
"contains_cs", "matches", "matches_regex", "parse", "parse_json", "print",
"project-away", "project-keep", "project-rename", "project-reorder", "distinct",
"countif", "max", "min", "sum", "avg", "variance", "stdev", "make-series",
"bin", "hll", "hll_merge", "percentiles", "percentiles_array", "tdigest_merge",
"arg_max", "arg_min", "arg_first", "arg_last",
"==", "!=", "=~", "!~", "contains", "!contains", "endswith", "!endswith",
"endswith_cs", "!endswith_cs", "has", "!has", "has_all", "has_any", "has_cs",
"!has_cs", "hasprefix", "!hasprefix", "hasprefix_cs", "!hasprefix_cs",
"hassuffix", "!hassuffix", "hassuffix_cs", "!hassuffix_cs", "in", "!in",
"in~", "!in~", "matches regex", "startswith", "!startswith", "startswith_cs",
"!startswith_cs",
"ago", "bin", "count", "countif", "dcount", "distinct", "extend", "facet",
"find", "join", "let", "limit", "mv-expand", "parse", "parse_json", "percentiles",
"percentiles_array", "project", "project-away", "project-rename", "project-reorder",
"range", "regex", "repl", "sample", "scan", "search", "serialize", "set", "sort",
"summarize", "take", "top", "union", "where", "with", "make-series", "arg_max",
"arg_min", "arg_first", "arg_last", "hll", "hll_merge", "tdigest_merge", "variance",
"stdev", "print"
},
},
{ Id=2,
List={
"bool", "datetime", "dynamic", "guid", "int", "long", "real", "string", "timespan"
},
},
{ Id=3,
Regex=[[\:\w+]],
},
{ Id=4,
Regex=[[(\w+)\s*\(]],
},
}
Strings={
Delimiter=[["|']],
}
IgnoreCase=true
Comments={
{ Block=false,
Delimiter= { [[//]] },
},
{ Block=true,
Nested=false,
Delimiter= { [[\/\*]],[[\*\/]],}
}
}
Operators=[[\(|\)|\[|\]|\{|\}|\,|\;|\:|\&|<|>|\!|\=|\/|\*|\%|\+|\-]]
Note: I asked ChatGPT to use the Microsoft documentation when creating the .lang file:
Identify all Kusto keywords from this page: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/kql-quick-reference, write the .lang file using the data from the site.
4) Close/Open OneNote
If OneNote is open, close it. Open it for changes to become active.
5) Profits
Test highlighting
- Highlight some code snippet in your notebook page.
- Click the new “KQL” button.
Before
After
Troubleshooting
While initially configuring this new language file I ran into some hurdles. I used ChatGPT to write my KQL file for me but it introduced some features/code that made NoteHighlight puke. For example, my first version included comments within the Keywords element. This was problematic.
When attempting to convert text to highlighted text:
Solution: remove the comments.
Additionally, the formatting of this original Comments mask, shown below, caused NoteHighlight to crash as well:
I changed the block Comments delimiter mask to match what was in the ‘sql.lang’ file since both KQL and SQL use the same formatting for comments.
The point is, if you have problems with your custom language file, simply copy the contents of an existing language file and change one section at a time, then close/open OneNote and test the highlight button until you can identify the problematic section of your custom file. Enjoy.