Skip to content

Commit a431832

Browse files
authored
Add ES|QL language support and move hl theme over to theme colors (#519)
* Add ES|QL language support and move hl theme over to theme colors * Add Painless language support (#521)
1 parent 3f8a468 commit a431832

File tree

6 files changed

+264
-3
lines changed

6 files changed

+264
-3
lines changed

docs/testing/custom-highlighters.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ GET /mydocuments/_search
3232
}
3333
```
3434
````
35+
::::
3536

3637
## EQL
3738

@@ -68,4 +69,83 @@ function calls
6869
modulo(10, 6)
6970
modulo(10, 5)
7071
modulo(10, 0.5)
72+
```
73+
74+
75+
76+
## ESQL
77+
78+
79+
```esql
80+
FROM employees
81+
| LIMIT 1000
82+
```
83+
84+
```esql
85+
ROW a = "2023-01-23T12:15:00.000Z - some text - 127.0.0.1"
86+
| DISSECT a """%{date} - %{msg} - %{ip}"""
87+
| KEEP date, msg, ip
88+
```
89+
90+
```esql
91+
FROM books
92+
| WHERE KQL("author: Faulkner")
93+
| KEEP book_no, author
94+
| SORT book_no
95+
| LIMIT 5
96+
```
97+
98+
```esql
99+
FROM hosts
100+
| STATS COUNT_DISTINCT(ip0), COUNT_DISTINCT(ip1)
101+
```
102+
103+
```esql
104+
ROW message = "foo ( bar"
105+
| WHERE message RLIKE "foo \\( bar"
106+
```
107+
108+
```esql
109+
FROM books
110+
| WHERE author:"Faulkner"
111+
| KEEP book_no, author
112+
| SORT book_no
113+
| LIMIT 5;
114+
```
115+
116+
## Painless
117+
118+
```painless
119+
int i = (int)5L;
120+
Map m = new HashMap();
121+
HashMap hm = (HashMap)m;
122+
```
123+
124+
```painless
125+
ZonedDateTime zdt1 =
126+
ZonedDateTime.of(1983, 10, 13, 22, 15, 30, 0, ZoneId.of('Z'));
127+
ZonedDateTime zdt2 =
128+
ZonedDateTime.of(1983, 10, 17, 22, 15, 35, 0, ZoneId.of('Z'));
129+
130+
if (zdt1.isAfter(zdt2)) {
131+
// handle condition
132+
}
133+
```
134+
135+
```painless
136+
if (doc.containsKey('start') && doc.containsKey('end')) {
137+
138+
if (doc['start'].size() > 0 && doc['end'].size() > 0) {
139+
140+
ZonedDateTime start = doc['start'].value;
141+
ZonedDateTime end = doc['end'].value;
142+
long differenceInMillis = ChronoUnit.MILLIS.between(start, end);
143+
144+
// handle difference in times
145+
} else {
146+
// handle fields without values
147+
}
148+
} else {
149+
// handle index with missing fields
150+
}
71151
```

src/Elastic.Markdown/Assets/hljs.ts

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ const NUMBER = {
4343
relevance: 0
4444
};
4545

46-
4746
hljs.registerLanguage('eql', function() {
4847
return {
4948
case_insensitive: true, // language is case-insensitive
@@ -69,6 +68,100 @@ hljs.registerLanguage('eql', function() {
6968
}
7069
})
7170

71+
hljs.registerLanguage('painless', function() {
72+
return {
73+
case_insensitive: true, // language is case-insensitive
74+
keywords: {
75+
keyword: 'where sequence sample untill and or not in in~',
76+
literal: ['false','true','null'],
77+
'subst': 'add between cidrMatch concat divide endsWith indexOf length modulo multiply number startsWith string stringContains substring subtract'
78+
},
79+
contains: [
80+
hljs.QUOTE_STRING_MODE,
81+
hljs.C_LINE_COMMENT_MODE,
82+
{
83+
scope: "operator", // (pathname: path1/path2/dothis) color #ab5656
84+
match: /(?:<|<=|==|:|!=|>=|>|like~?|regex~?)/,
85+
},
86+
{
87+
scope: "punctuation", // (pathname: path1/path2/dothis) color #ab5656
88+
match: /(?:!?\[|\]|\|)/,
89+
},
90+
NUMBER,
91+
92+
]
93+
}
94+
})
95+
96+
97+
hljs.registerLanguage('esql', function() {
98+
return {
99+
case_insensitive: true, // language is case-insensitive
100+
keywords: {
101+
keyword: 'FROM ROW SHOW DISSECT DROP ENRICH EVAL GROK KEEP LIMIT RENAME SORT STATS WHERE METADATA',
102+
literal: ['false','true','null'],
103+
function: [
104+
// aggregate
105+
"AVG", "COUNT", "COUNT_DISTINCT", "MAX", "MEDIAN", "MEDIAN_ABSOLUTE_DEVIATION", "MIN",
106+
"PERCENTILE", "SUM", "TOP", "VALUES", "WEIGHTED_AVG", "BUCKET",
107+
108+
// conditional
109+
"CASE", "COALESCE", "GREATEST", "LEAST",
110+
111+
//Date
112+
"DATE_DIFF", "DATE_EXTRACT", "DATE_FORMAT", "DATE_PARSE", "DATE_TRUNC", "NOW",
113+
114+
//ip
115+
"CIDR_MATCH", "IP_PREFIX",
116+
117+
//math
118+
"ABS", "ACOS", "ASIN", "ATAN", "ATAN2", "CBRT", "CEIL", "COS", "COSH", "E", "EXP", "FLOOR",
119+
"HYPOT", "LOG", "LOG10", "PI", "POW", "ROUND", "SIGNUM", "SIN", "SINH", "SQRT", "TAN",
120+
"TANH", "TAU",
121+
122+
//search
123+
"MATCH", "QSTR",
124+
125+
//spatial
126+
"ST_DISTANCE", "ST_INTERSECTS", "ST_DISJOINT", "ST_CONTAINS", "ST_WITHIN", "ST_X", "ST_Y",
127+
128+
//string
129+
130+
"BIT_LENGTH", "BYTE_LENGTH", "CONCAT", "ENDS_WITH", "FROM_BASE64", "LEFT", "LENGTH", "LOCATE",
131+
"LTRIM", "REPEAT", "REPLACE", "REVERSE", "RIGHT", "RTRIM", "SPACE", "SPLIT", "STARTS_WITH",
132+
"SUBSTRING", "TO_BASE64", "TO_LOWER", "TO_UPPER", "TRIM",
133+
134+
//type conversion
135+
"TO_BOOLEAN", "TO_CARTESIANPOINT", "TO_CARTESIANSHAPE", "TO_DATETIME", "TO_DEGREES",
136+
"TO_DOUBLE", "TO_GEOPOINT", "TO_GEOSHAPE", "TO_INTEGER", "TO_IP", "TO_LONG", "TO_RADIANS",
137+
"TO_STRING", "TO_VERSION",
138+
139+
//multivalued
140+
"MV_APPEND", "MV_AVG", "MV_CONCAT", "MV_COUNT", "MV_DEDUPE", "MV_FIRST", "MV_LAST", "MV_MAX",
141+
"MV_MEDIAN", "MV_MEDIAN_ABSOLUTE_DEVIATION", "MV_MIN", "MV_PERCENTILE", "MV_PSERIES_WEIGHTED_SUM",
142+
"MV_SORT", "MV_SLICE", "MV_SUM", "MV_ZIP",
143+
144+
"KQL"
145+
]
146+
},
147+
contains: [
148+
hljs.QUOTE_STRING_MODE,
149+
hljs.C_LINE_COMMENT_MODE,
150+
{
151+
scope: "operator", // (pathname: path1/path2/dothis) color #ab5656
152+
match: /(?:<|<=|==|::|\w+:|!=|>=|>|LIKE|RLIKE|IS NULL|IS NOT NULL)/,
153+
},
154+
{
155+
scope: "punctuation", // (pathname: path1/path2/dothis) color #ab5656
156+
match: /(?:!?\[|\]|\|)/,
157+
},
158+
NUMBER,
159+
160+
]
161+
}
162+
})
163+
164+
72165
hljs.addPlugin(mergeHTMLPlugin);
73166
export function initHighlight() {
74167

src/Elastic.Markdown/Assets/markdown/code.css

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,91 @@
7979
text-decoration: inherit;
8080
font-weight: inherit;
8181
}
82+
83+
84+
.hljs-built_in,
85+
.hljs-selector-tag,
86+
.hljs-section,
87+
.hljs-link {
88+
color: var(--color-blue-elastic-70)
89+
}
90+
91+
.hljs-keyword {
92+
color: var(--color-blue-elastic-70)
93+
}
94+
95+
.hljs {
96+
color: var(--color-blue-elastic-30) !important;
97+
}
98+
.hljs-subst {
99+
color: var(--color-purple-60)
100+
}
101+
.hljs-function {
102+
color: var(--color-purple-60)
103+
}
104+
105+
.hljs-title,
106+
.hljs-title.function,
107+
.hljs-attr,
108+
.hljs-meta-keyword {
109+
color: var(--color-yellow-50)
110+
}
111+
112+
.hljs-string {
113+
color: var(--color-green-50)
114+
}
115+
.hljs-operator {
116+
color: var(--color-yellow-50)
117+
}
118+
119+
.hljs-meta,
120+
.hljs-name,
121+
.hljs-bullet,
122+
.hljs-addition,
123+
.hljs-template-tag,
124+
.hljs-template-variable {
125+
color: var(--color-yellow-50)
126+
}
127+
128+
.hljs-type,
129+
.hljs-symbol {
130+
color: var(--color-teal-50)
131+
}
132+
.hljs-variable {
133+
color: var(--color-purple-50)
134+
}
135+
136+
.hljs-comment,
137+
.hljs-quote,
138+
.hljs-deletion {
139+
color: var(--color-grey-70)
140+
}
141+
142+
.hljs-punctuation {
143+
color: var(--color-grey-50);
144+
font-weight: bold;
145+
}
146+
147+
.hljs-keyword,
148+
.hljs-selector-tag,
149+
.hljs-literal,
150+
.hljs-title,
151+
.hljs-section,
152+
.hljs-doctag,
153+
.hljs-type,
154+
.hljs-name,
155+
.hljs-strong {
156+
font-weight: bold;
157+
}
158+
159+
.hljs-literal {
160+
color: var(--color-pink-50)
161+
}
162+
.hljs-number {
163+
color: var(--color-red-50)
164+
}
165+
166+
.hljs-emphasis {
167+
font-style: italic;
168+
}
82169
}

src/Elastic.Markdown/Assets/styles.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@import "tailwindcss";
22
@import "./fonts.css";
33
@import "./theme.css";
4-
@import "highlight.js/styles/github-dark-dimmed.css";
54
@import "./markdown/typography.css";
65
@import "./markdown/list.css";
76
@import "./markdown/tabs.css";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public override bool Close(BlockProcessor processor, Block block)
8585
"console-response" => "json",
8686
"console-result" => "json",
8787
"terminal" => "bash",
88+
"painless" => "java",
8889
_ => codeBlock.Language
8990
};
9091
if (!string.IsNullOrEmpty(codeBlock.Language) && !CodeBlock.Languages.Contains(codeBlock.Language))

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public static class CodeBlock
181181
{ "zephir", "zep" }, // Zephir
182182

183183
//CUSTOM, Elastic language we wrote highlighters for
184-
{ "eql", "" }
184+
{ "eql", "" },
185+
{ "esql", "" }
185186
};
186187

187188

0 commit comments

Comments
 (0)