diff --git a/docs/testing/custom-highlighters.md b/docs/testing/custom-highlighters.md index cc6f559cb..35fec9e3f 100644 --- a/docs/testing/custom-highlighters.md +++ b/docs/testing/custom-highlighters.md @@ -112,3 +112,40 @@ FROM books | SORT book_no | LIMIT 5; ``` + +## Painless + +```painless +int i = (int)5L; +Map m = new HashMap(); +HashMap hm = (HashMap)m; +``` + +```painless +ZonedDateTime zdt1 = + ZonedDateTime.of(1983, 10, 13, 22, 15, 30, 0, ZoneId.of('Z')); +ZonedDateTime zdt2 = + ZonedDateTime.of(1983, 10, 17, 22, 15, 35, 0, ZoneId.of('Z')); + +if (zdt1.isAfter(zdt2)) { + // handle condition +} +``` + +```painless +if (doc.containsKey('start') && doc.containsKey('end')) { + + if (doc['start'].size() > 0 && doc['end'].size() > 0) { + + ZonedDateTime start = doc['start'].value; + ZonedDateTime end = doc['end'].value; + long differenceInMillis = ChronoUnit.MILLIS.between(start, end); + + // handle difference in times + } else { + // handle fields without values + } +} else { + // handle index with missing fields +} +``` \ No newline at end of file diff --git a/src/Elastic.Markdown/Assets/hljs.ts b/src/Elastic.Markdown/Assets/hljs.ts index fa3fe8d6b..675963dc4 100644 --- a/src/Elastic.Markdown/Assets/hljs.ts +++ b/src/Elastic.Markdown/Assets/hljs.ts @@ -68,6 +68,32 @@ hljs.registerLanguage('eql', function() { } }) +hljs.registerLanguage('painless', function() { + return { + case_insensitive: true, // language is case-insensitive + keywords: { + keyword: 'where sequence sample untill and or not in in~', + literal: ['false','true','null'], + 'subst': 'add between cidrMatch concat divide endsWith indexOf length modulo multiply number startsWith string stringContains substring subtract' + }, + contains: [ + hljs.QUOTE_STRING_MODE, + hljs.C_LINE_COMMENT_MODE, + { + scope: "operator", // (pathname: path1/path2/dothis) color #ab5656 + match: /(?:<|<=|==|:|!=|>=|>|like~?|regex~?)/, + }, + { + scope: "punctuation", // (pathname: path1/path2/dothis) color #ab5656 + match: /(?:!?\[|\]|\|)/, + }, + NUMBER, + + ] + } +}) + + hljs.registerLanguage('esql', function() { return { case_insensitive: true, // language is case-insensitive diff --git a/src/Elastic.Markdown/Assets/markdown/code.css b/src/Elastic.Markdown/Assets/markdown/code.css index a80f619cf..b01ef22dd 100644 --- a/src/Elastic.Markdown/Assets/markdown/code.css +++ b/src/Elastic.Markdown/Assets/markdown/code.css @@ -118,16 +118,21 @@ .hljs-meta, .hljs-name, - .hljs-type, - .hljs-symbol, .hljs-bullet, .hljs-addition, - .hljs-variable, .hljs-template-tag, .hljs-template-variable { color: var(--color-yellow-50) } + .hljs-type, + .hljs-symbol { + color: var(--color-teal-50) + } + .hljs-variable { + color: var(--color-purple-50) + } + .hljs-comment, .hljs-quote, .hljs-deletion { @@ -155,7 +160,7 @@ color: var(--color-pink-50) } .hljs-number { - color: var(--color-teal-50) + color: var(--color-red-50) } .hljs-emphasis { diff --git a/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs b/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs index 5cd0787c8..6857fa991 100644 --- a/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs +++ b/src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs @@ -85,6 +85,7 @@ public override bool Close(BlockProcessor processor, Block block) "console-response" => "json", "console-result" => "json", "terminal" => "bash", + "painless" => "java", _ => codeBlock.Language }; if (!string.IsNullOrEmpty(codeBlock.Language) && !CodeBlock.Languages.Contains(codeBlock.Language))