-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
# Conflicts: # package.json
- Loading branch information
1 parent
b828702
commit f283973
Showing
26 changed files
with
1,139 additions
and
460 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
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/cases/common/utils/markdown_plugins/utils.ts
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,56 @@ | ||
/* | ||
* 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 { filter } from 'lodash'; | ||
import type { Node } from 'unist'; | ||
import markdown from 'remark-parse'; | ||
import remarkStringify from 'remark-stringify'; | ||
import unified from 'unified'; | ||
|
||
import { TimeRange } from 'src/plugins/data/server'; | ||
import { SerializableRecord } from '@kbn/utility-types'; | ||
import { LENS_ID, LensParser, LensSerializer } from './lens'; | ||
import { TimelineSerializer, TimelineParser } from './timeline'; | ||
|
||
interface LensMarkdownNode extends Node { | ||
timeRange: TimeRange; | ||
attributes: SerializableRecord; | ||
type: string; | ||
id: string; | ||
} | ||
|
||
interface LensMarkdownParent extends Node { | ||
children: Array<LensMarkdownNode | Node>; | ||
} | ||
|
||
export const getLensVisualizations = (parsedComment?: Array<LensMarkdownNode | Node>) => | ||
(parsedComment?.length ? filter(parsedComment, { type: LENS_ID }) : []) as LensMarkdownNode[]; | ||
|
||
export const parseCommentString = (comment: string) => { | ||
const processor = unified().use([[markdown, {}], LensParser, TimelineParser]); | ||
return processor.parse(comment) as LensMarkdownParent; | ||
}; | ||
|
||
export const stringifyComment = (comment: LensMarkdownParent) => | ||
unified() | ||
.use([ | ||
[ | ||
remarkStringify, | ||
{ | ||
allowDangerousHtml: true, | ||
handlers: { | ||
/* | ||
because we're using rison in the timeline url we need | ||
to make sure that markdown parser doesn't modify the url | ||
*/ | ||
timeline: TimelineSerializer, | ||
lens: LensSerializer, | ||
}, | ||
}, | ||
], | ||
]) | ||
.stringify(comment); |
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
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
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
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
Oops, something went wrong.