1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/dashboard/client/components/markdown-viewer/markdown-viewer.tsx
Jari Kolehmainen 1d0815abd2
Lens app source code (#119)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
2020-03-15 09:52:02 +02:00

37 lines
1013 B
TypeScript

// Wrapper Component with marked plugin in its core
// Source: https://www.npmjs.com/package/marked
import "./markdown-viewer.scss";
import React, { Component } from "react";
import marked from "marked";
import DOMPurify from "dompurify";
import { cssNames } from "../../utils";
import { themeStore } from "../../theme.store";
DOMPurify.addHook('afterSanitizeAttributes', function (node) {
// Set all elements owning target to target=_blank
if ('target' in node as any as HTMLElement) {
node.setAttribute('target', '_blank');
}
});
interface Props extends OptionalProps {
markdown: string;
}
interface OptionalProps {
className?: string;
}
export class MarkdownViewer extends Component<Props> {
render() {
const { className, markdown } = this.props;
const html = DOMPurify.sanitize(marked(markdown));
return (
<div
className={cssNames("MarkDownViewer", className, themeStore.activeTheme.type)}
dangerouslySetInnerHTML={{ __html: html }}
/>
);
}
}