1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/markdown-viewer/markdown-viewer.tsx
dependabot[bot] f629de8589
Bump marked from 2.1.3 to 4.0.10 (#4695)
* Bump marked from 2.1.3 to 4.0.10

Bumps [marked](https://github.com/markedjs/marked) from 2.1.3 to 4.0.10.
- [Release notes](https://github.com/markedjs/marked/releases)
- [Changelog](https://github.com/markedjs/marked/blob/master/.releaserc.json)
- [Commits](https://github.com/markedjs/marked/compare/v2.1.3...v4.0.10)

---
updated-dependencies:
- dependency-name: marked
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Upgrading marked types

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Alex Andreev <alex.andreev.email@gmail.com>
2022-01-18 12:33:36 +03:00

43 lines
1.1 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
// 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";
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)}
dangerouslySetInnerHTML={{ __html: html }}
/>
);
}
}