aws-northstar
Version:
NorthStar Design System
60 lines (56 loc) • 3.3 kB
JavaScript
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
/** *******************************************************************************************************************
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License").
You may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. *
******************************************************************************************************************** */
import React from 'react';
import gfm from 'remark-gfm';
import frontmatter from 'remark-frontmatter';
import ReactMarkdown from 'react-markdown';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { tomorrow } from 'react-syntax-highlighter/dist/cjs/styles/prism';
import Heading from '../Heading';
import Text from '../Text';
import Link from '../Link';
const components = {
code: (_a) => {
var { node, inline, className, children, ref } = _a, props = __rest(_a, ["node", "inline", "className", "children", "ref"]);
const match = /language-(\w+)/.exec(className || '');
const value = String(children).replace(/\n$/, '');
return !inline && match ? (React.createElement(SyntaxHighlighter, Object.assign({ style: tomorrow, language: match[1], children: value }, props))) : (React.createElement(React.Fragment, null, value));
},
h1: (props) => React.createElement(Heading, { variant: "h1" }, props.children),
h2: (props) => React.createElement(Heading, { variant: "h2" }, props.children),
h3: (props) => React.createElement(Heading, { variant: "h3" }, props.children),
h4: (props) => React.createElement(Heading, { variant: "h4" }, props.children),
h5: (props) => React.createElement(Heading, { variant: "h5" }, props.children),
p: (props) => React.createElement(Text, { variant: "p" }, props.children),
a: (props) => React.createElement(Link, { href: props.href }, props.children),
};
/**
* MarkdownViewer renders content with Markdown format.
*/
const MarkdownViewer = (_a) => {
var { children } = _a, props = __rest(_a, ["children"]);
return (React.createElement("div", { "data-testid": props['data-testid'] },
React.createElement(ReactMarkdown, { plugins: [gfm, frontmatter], components: components, children: children })));
};
export default MarkdownViewer;