/** *******************************************************************************************************************
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, { FunctionComponent } from 'react';
import gfm from 'remark-gfm';
import frontmatter from 'remark-frontmatter';
import ReactMarkdown, { ReactMarkdownOptions } 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';
export interface MarkdownViewerProps {
/** The markdown content to be displayed */
children: string;
}
const components: ReactMarkdownOptions['components'] = {
code: ({ node, inline, className, children, ref, ...props }) => {
const match = /language-(\w+)/.exec(className || '');
const value = String(children).replace(/\n$/, '');
return !inline && match ? (
) : (
<>{value}>
);
},
h1: (props) => {props.children},
h2: (props) => {props.children},
h3: (props) => {props.children},
h4: (props) => {props.children},
h5: (props) => {props.children},
p: (props) => {props.children},
a: (props) => {props.children},
};
/**
* MarkdownViewer renders content with Markdown format.
*/
const MarkdownViewer: FunctionComponent = ({ children, ...props }) => {
return (