Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ toc:
- file: req.md
- folder: nested
- file: cross-links.md
- file: custom-highlighters.md
- folder: mover
children:
- file: first-page.md
Expand Down
71 changes: 71 additions & 0 deletions docs/testing/custom-highlighters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Additional syntax highlighters


## Console / REST API documentation

::::{tab-set}

:::{tab-item} Output

```console
GET /mydocuments/_search
{
"from": 1,
"query": {
"match_all" {}
}
}
```

:::

:::{tab-item} Markdown

````markdown
```console
GET /mydocuments/_search
{
"from": 1,
"query": {
"match_all" {}
}
}
```
````

## EQL

sequence
```eql
sequence
[ file where file.extension == "exe" ]
[ process where true ]
```

sequence until

```eql
sequence by ID
A
B
until C
```
sample

```eql
sample by host
[ file where file.extension == "exe" ]
[ process where true ]
```
head (pipes)
```eql
process where process.name == "svchost.exe"
| tail 5
```
function calls

```eql
modulo(10, 6)
modulo(10, 5)
modulo(10, 0.5)
```
57 changes: 56 additions & 1 deletion src/Elastic.Markdown/Assets/hljs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,63 @@ hljs.registerLanguage('apiheader', function() {
], }
})

hljs.addPlugin(mergeHTMLPlugin);
// https://tc39.es/ecma262/#sec-literals-numeric-literals
const decimalDigits = '[0-9](_?[0-9])*';
const frac = `\\.(${decimalDigits})`;
// DecimalIntegerLiteral, including Annex B NonOctalDecimalIntegerLiteral
// https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
const decimalInteger = `0|[1-9](_?[0-9])*|0[0-7]*[89][0-9]*`;
const NUMBER = {
className: 'number',
variants: [
// DecimalLiteral
{ begin: `(\\b(${decimalInteger})((${frac})|\\.)?|(${frac}))` +
`[eE][+-]?(${decimalDigits})\\b` },
{ begin: `\\b(${decimalInteger})\\b((${frac})\\b|\\.)?|(${frac})\\b` },

// DecimalBigIntegerLiteral
{ begin: `\\b(0|[1-9](_?[0-9])*)n\\b` },

// NonDecimalIntegerLiteral
{ begin: "\\b0[xX][0-9a-fA-F](_?[0-9a-fA-F])*n?\\b" },
{ begin: "\\b0[bB][0-1](_?[0-1])*n?\\b" },
{ begin: "\\b0[oO][0-7](_?[0-7])*n?\\b" },

// LegacyOctalIntegerLiteral (does not include underscore separators)
// https://tc39.es/ecma262/#sec-additional-syntax-numeric-literals
{ begin: "\\b0[0-7]+n?\\b" },
],
relevance: 0
};


hljs.registerLanguage('eql', 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.addPlugin(mergeHTMLPlugin);
export function initHighlight() {

hljs.highlightAll();
}
6 changes: 4 additions & 2 deletions src/Elastic.Markdown/Assets/toc-nav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ function setupSmoothScrolling(elements: TocElements) {

export function initTocNav() {
const elements = initializeTocElements();
elements.progressIndicator.style.height = '0';
elements.progressIndicator.style.top = '0';
if (elements.progressIndicator != null) {
elements.progressIndicator.style.height = '0';
elements.progressIndicator.style.top = '0';
}
const update = () => updateIndicator(elements)
update();
window.addEventListener('scroll', update);
Expand Down
3 changes: 3 additions & 0 deletions src/Elastic.Markdown/Myst/CodeBlocks/SupportedLanguages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ public static class CodeBlock
{ "xquery", "xpath, xq, xqm" }, // XQuery
{ "yml", "yaml" }, // YAML
{ "zephir", "zep" }, // Zephir

//CUSTOM, Elastic language we wrote highlighters for
{ "eql", "" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to be esql or eql something different?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. I just saw that eql is actually used docs-content.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eql and esql both exists :D

};


Expand Down
1 change: 0 additions & 1 deletion src/Elastic.Markdown/Slices/Layout/_Scripts.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/go.min.js"></script>

<script src="@Model.Static("hljs.js")"></script>
<script src="@Model.Static("custom.js")"></script>
<script src="https://unpkg.com/mermaid@10.2.0/dist/mermaid.min.js"></script>
12 changes: 0 additions & 12 deletions src/Elastic.Markdown/_static/custom.js

This file was deleted.

Loading