Skip to content

Commit c09209c

Browse files
authored
Add rudimentary EQL syntax highlighting (#517)
1 parent f5a72c1 commit c09209c

File tree

7 files changed

+135
-16
lines changed

7 files changed

+135
-16
lines changed

docs/docset.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ toc:
117117
- file: req.md
118118
- folder: nested
119119
- file: cross-links.md
120+
- file: custom-highlighters.md
120121
- folder: mover
121122
children:
122123
- file: first-page.md
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Additional syntax highlighters
2+
3+
4+
## Console / REST API documentation
5+
6+
::::{tab-set}
7+
8+
:::{tab-item} Output
9+
10+
```console
11+
GET /mydocuments/_search
12+
{
13+
"from": 1,
14+
"query": {
15+
"match_all" {}
16+
}
17+
}
18+
```
19+
20+
:::
21+
22+
:::{tab-item} Markdown
23+
24+
````markdown
25+
```console
26+
GET /mydocuments/_search
27+
{
28+
"from": 1,
29+
"query": {
30+
"match_all" {}
31+
}
32+
}
33+
```
34+
````
35+
36+
## EQL
37+
38+
sequence
39+
```eql
40+
sequence
41+
[ file where file.extension == "exe" ]
42+
[ process where true ]
43+
```
44+
45+
sequence until
46+
47+
```eql
48+
sequence by ID
49+
A
50+
B
51+
until C
52+
```
53+
sample
54+
55+
```eql
56+
sample by host
57+
[ file where file.extension == "exe" ]
58+
[ process where true ]
59+
```
60+
head (pipes)
61+
```eql
62+
process where process.name == "svchost.exe"
63+
| tail 5
64+
```
65+
function calls
66+
67+
```eql
68+
modulo(10, 6)
69+
modulo(10, 5)
70+
modulo(10, 0.5)
71+
```

src/Elastic.Markdown/Assets/hljs.ts

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,63 @@ hljs.registerLanguage('apiheader', function() {
1414
], }
1515
})
1616

17-
hljs.addPlugin(mergeHTMLPlugin);
17+
// https://tc39.es/ecma262/#sec-literals-numeric-literals
18+
const decimalDigits = '[0-9](_?[0-9])*';
19+
const frac = `\\.(${decimalDigits})`;
20+
// DecimalIntegerLiteral, including Annex B NonOctalDecimalIntegerLiteral
21+
// https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
22+
const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;
23+
const NUMBER = {
24+
className: 'number',
25+
variants: [
26+
// DecimalLiteral
27+
{ begin: `(\\b(${decimalInteger})((${frac})|\\.)?|(${frac}))` +
28+
`[eE][+-]?(${decimalDigits})\\b` },
29+
{ begin: `\\b(${decimalInteger})\\b((${frac})\\b|\\.)?|(${frac})\\b` },
30+
31+
// DecimalBigIntegerLiteral
32+
{ begin: `\\b(0|[1-9](_?[0-9])*)n\\b` },
33+
34+
// NonDecimalIntegerLiteral
35+
{ begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
36+
{ begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
37+
{ begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },
38+
39+
// LegacyOctalIntegerLiteral (does not include underscore separators)
40+
// https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
41+
{ begin: "\\b0[0-7]+n?\\b" },
42+
],
43+
relevance: 0
44+
};
1845

46+
47+
hljs.registerLanguage('eql', function() {
48+
return {
49+
case_insensitive: true, // language is case-insensitive
50+
keywords: {
51+
keyword: 'where sequence sample untill and or not in in~',
52+
literal: ['false','true','null'],
53+
'subst': 'add between cidrMatch concat divide endsWith indexOf length modulo multiply number startsWith string stringContains substring subtract'
54+
},
55+
contains: [
56+
hljs.QUOTE_STRING_MODE,
57+
hljs.C_LINE_COMMENT_MODE,
58+
{
59+
scope: "operator", // (pathname: path1/path2/dothis) color #ab5656
60+
match: /(?:<|<=|==|:|!=|>=|>|like~?|regex~?)/,
61+
},
62+
{
63+
scope: "punctuation", // (pathname: path1/path2/dothis) color #ab5656
64+
match: /(?:!?\[|\]|\|)/,
65+
},
66+
NUMBER,
67+
68+
]
69+
}
70+
})
71+
72+
hljs.addPlugin(mergeHTMLPlugin);
1973
export function initHighlight() {
74+
2075
hljs.highlightAll();
2176
}

src/Elastic.Markdown/Assets/toc-nav.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ function setupSmoothScrolling(elements: TocElements) {
128128

129129
export function initTocNav() {
130130
const elements = initializeTocElements();
131-
elements.progressIndicator.style.height = '0';
132-
elements.progressIndicator.style.top = '0';
131+
if (elements.progressIndicator != null) {
132+
elements.progressIndicator.style.height = '0';
133+
elements.progressIndicator.style.top = '0';
134+
}
133135
const update = () => updateIndicator(elements)
134136
update();
135137
window.addEventListener('scroll', update);

src/Elastic.Markdown/Myst/CodeBlocks/SupportedLanguages.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ public static class CodeBlock
179179
{ "xquery", "xpath, xq, xqm" }, // XQuery
180180
{ "yml", "yaml" }, // YAML
181181
{ "zephir", "zep" }, // Zephir
182+
183+
//CUSTOM, Elastic language we wrote highlighters for
184+
{ "eql", "" }
182185
};
183186

184187

src/Elastic.Markdown/Slices/Layout/_Scripts.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/go.min.js"></script>
1919

2020
<script src="@Model.Static("hljs.js")"></script>
21-
<script src="@Model.Static("custom.js")"></script>
2221
<script src="https://unpkg.com/[email protected]/dist/mermaid.min.js"></script>

src/Elastic.Markdown/_static/custom.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)