forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new markdown parser for send to timeline actions for eql, kql an…
…d queryDSL
- Loading branch information
Showing
6 changed files
with
317 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/security_solution/public/security_assistant/use_conversation/helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type React from 'react'; | ||
import type { QueryType } from '../../timelines/components/timeline/data_providers/data_provider'; | ||
|
||
export interface CodeBlockDetails { | ||
type: QueryType; | ||
content: string; | ||
start: number; | ||
end: number; | ||
controlContainer?: HTMLElement; | ||
button?: React.FC; | ||
} | ||
|
||
export const analyzeMarkdown = (markdown: string): CodeBlockDetails[] => { | ||
const codeBlockRegex = /```(\w+)?\s([\s\S]*?)```/g; | ||
const matches = [...markdown.matchAll(codeBlockRegex)]; | ||
const types = { | ||
eql: ['Event Query Language', 'EQL sequence query'], | ||
kql: ['Kibana Query Language', 'KQL Query'], | ||
dsl: ['Elasticsearch QueryDSL', 'Elasticsearch Query DSL', 'Elasticsearch DSL'], | ||
}; | ||
|
||
const result: CodeBlockDetails[] = matches.map((match) => { | ||
let type = match[1] || 'no-type'; | ||
if (type === 'no-type' || type === 'json') { | ||
const start = match.index || 0; | ||
const precedingText = markdown.slice(0, start); | ||
for (const [typeKey, keywords] of Object.entries(types)) { | ||
if (keywords.some((kw) => precedingText.includes(kw))) { | ||
type = typeKey; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
const content = match[2].trim(); | ||
const start = match.index || 0; | ||
const end = start + match[0].length; | ||
return { type: type as QueryType, content, start, end }; | ||
}); | ||
|
||
return result; | ||
}; |
Oops, something went wrong.