UNPKG

aws-northstar

Version:
65 lines (61 loc) 3.96 kB
"use strict"; 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; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); /** ******************************************************************************************************************* 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. * ******************************************************************************************************************** */ const react_1 = __importDefault(require("react")); const remark_gfm_1 = __importDefault(require("remark-gfm")); const remark_frontmatter_1 = __importDefault(require("remark-frontmatter")); const react_markdown_1 = __importDefault(require("react-markdown")); const react_syntax_highlighter_1 = require("react-syntax-highlighter"); const prism_1 = require("react-syntax-highlighter/dist/cjs/styles/prism"); const Heading_1 = __importDefault(require("../Heading")); const Text_1 = __importDefault(require("../Text")); const Link_1 = __importDefault(require("../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_1.default.createElement(react_syntax_highlighter_1.Prism, Object.assign({ style: prism_1.tomorrow, language: match[1], children: value }, props))) : (react_1.default.createElement(react_1.default.Fragment, null, value)); }, h1: (props) => react_1.default.createElement(Heading_1.default, { variant: "h1" }, props.children), h2: (props) => react_1.default.createElement(Heading_1.default, { variant: "h2" }, props.children), h3: (props) => react_1.default.createElement(Heading_1.default, { variant: "h3" }, props.children), h4: (props) => react_1.default.createElement(Heading_1.default, { variant: "h4" }, props.children), h5: (props) => react_1.default.createElement(Heading_1.default, { variant: "h5" }, props.children), p: (props) => react_1.default.createElement(Text_1.default, { variant: "p" }, props.children), a: (props) => react_1.default.createElement(Link_1.default, { href: props.href }, props.children), }; /** * MarkdownViewer renders content with Markdown format. */ const MarkdownViewer = (_a) => { var { children } = _a, props = __rest(_a, ["children"]); return (react_1.default.createElement("div", { "data-testid": props['data-testid'] }, react_1.default.createElement(react_markdown_1.default, { plugins: [remark_gfm_1.default, remark_frontmatter_1.default], components: components, children: children }))); }; exports.default = MarkdownViewer;