2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import * as React from 'react';
20 import * as marked from 'marked';
21 import * as hljs from 'highlight.js';
23 type MarkdownComponentProps = {
26 markedOptions?: marked.MarkedOptions;
27 style?: React.CSSProperties
30 const defaultRenderer = new marked.Renderer();
31 defaultRenderer.link = (href, title, text) => (
32 `<a target="_blank" rel="noopener noreferrer" href="${ href }" title="${ title }">${ text }</a>`
36 class MarkdownComponent extends React.Component<MarkdownComponentProps> {
37 constructor(props: MarkdownComponentProps) {
40 const markedOptions: marked.MarkedOptions = {
49 ...(this.props.markedOptions || {}),
50 highlight: (code, lang) => {
51 if (!!(lang && hljs.getLanguage(lang))) {
52 return hljs.highlight(lang, code).value;
58 marked.setOptions(markedOptions);
61 const { text, className, style } = this.props;
64 const html = (marked(text || '', { renderer: this.props.markedOptions && this.props.markedOptions.renderer || defaultRenderer }));
68 dangerouslySetInnerHTML={ { __html: html } }
69 className={ className }
76 export const Markdown = MarkdownComponent;