forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support warning_markdown on metrics (apache#1011)
- Loading branch information
1 parent
4bc2d58
commit 0a52a10
Showing
7 changed files
with
289 additions
and
11 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
34 changes: 34 additions & 0 deletions
34
...mporary_superset_ui/superset-ui/packages/superset-ui-core/src/components/SafeMarkdown.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,34 @@ | ||
import React from 'react'; | ||
import ReactMarkdown, { MarkdownAbstractSyntaxTree } from 'react-markdown'; | ||
// @ts-ignore no types available | ||
import htmlParser from 'react-markdown/plugins/html-parser'; | ||
|
||
import { FeatureFlag, isFeatureEnabled } from '../utils'; | ||
|
||
interface SafeMarkdownProps { | ||
source: string; | ||
} | ||
|
||
function isSafeMarkup(node: MarkdownAbstractSyntaxTree) { | ||
return node.type === 'html' && node.value | ||
? /href="(javascript|vbscript|file):.*"/gim.test(node.value) === false | ||
: true; | ||
} | ||
|
||
function SafeMarkdown({ source }: SafeMarkdownProps) { | ||
return ( | ||
<ReactMarkdown | ||
source={source} | ||
escapeHtml={isFeatureEnabled(FeatureFlag.ESCAPE_MARKDOWN_HTML)} | ||
skipHtml={!isFeatureEnabled(FeatureFlag.DISPLAY_MARKDOWN_HTML)} | ||
allowNode={isSafeMarkup} | ||
astPlugins={[ | ||
htmlParser({ | ||
isValidNode: (node: MarkdownAbstractSyntaxTree) => node.type !== 'script', | ||
}), | ||
]} | ||
/> | ||
); | ||
} | ||
|
||
export default SafeMarkdown; |
1 change: 1 addition & 0 deletions
1
...ntend/temporary_superset_ui/superset-ui/packages/superset-ui-core/src/components/index.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 @@ | ||
export { default as SafeMarkdown } from './SafeMarkdown'; |
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.