// Copyright 2023, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import * as React from "react"; import * as mobxReact from "mobx-react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { clsx } from "clsx"; import { GlobalModel } from "@/models"; import { v4 as uuidv4 } from "uuid"; import "./markdown.less"; import { boundMethod } from "autobind-decorator"; function LinkRenderer(props: any): any { let newUrl = "https://extern?" + encodeURIComponent(props.href); return ( {props.children} ); } function HeaderRenderer(props: any, hnum: number): any { return
{props.children}
;
}
@mobxReact.observer
class CodeBlockMarkdown extends React.Component<
{ children: React.ReactNode; codeSelectSelectedIndex?: number; uuid: string },
{}
> {
blockIndex: number;
blockRef: React.RefObject{this.props.children}); } } @mobxReact.observer class Markdown extends React.Component< { text: string; style?: any; extraClassName?: string; codeSelect?: boolean }, {} > { curUuid: string; constructor(props) { super(props); this.curUuid = uuidv4(); } @boundMethod codeBlockRenderer(props: any, codeSelect: boolean, codeSelectIndex: number, curUuid: string): any { if (codeSelect) { return (
clickHandler(event)}>{props.children}; } } render() { let { text } = this.props; let codeSelect = this.props.codeSelect; let curCodeSelectIndex = GlobalModel.inputModel.getCodeSelectSelectedIndex(); let markdownComponents = { a: LinkRenderer, h1: (props) => HeaderRenderer(props, 1), h2: (props) => HeaderRenderer(props, 2), h3: (props) => HeaderRenderer(props, 3), h4: (props) => HeaderRenderer(props, 4), h5: (props) => HeaderRenderer(props, 5), h6: (props) => HeaderRenderer(props, 6), code: (props) => CodeRenderer(props), pre: (props) => this.codeBlockRenderer(props, codeSelect, curCodeSelectIndex, this.curUuid), }; return (