var _excluded = ["node"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import Markdown from 'react-markdown';
import rehypeRaw from 'rehype-raw';
import remarkGfm from 'remark-gfm';
import { MarkdownCodeBlock } from "./MarkdownCodeBlock"; // 引入我们创建的自定义组件

export var MarkdownComponent = /*#__PURE__*/React.memo(function (_ref) {
  var content = _ref.content,
    showRunButton = _ref.showRunButton;
  return /*#__PURE__*/React.createElement(Markdown, {
    remarkPlugins: [remarkGfm],
    rehypePlugins: [rehypeRaw],
    components: {
      // 1. 重写 `p` 标签的渲染
      p: function p(props) {
        var node = props.node,
          rest = _objectWithoutProperties(props, _excluded);
        return /*#__PURE__*/React.createElement("p", _extends({
          style: {
            marginBottom: 'unset',
            lineHeight: '1.6'
          }
        }, rest));
      },
      // 2. 【核心】重写 `code` 标签的渲染，使用我们自己的组件
      code: function code(props) {
        return /*#__PURE__*/React.createElement(MarkdownCodeBlock, _extends({
          showRunButton: showRunButton
        }, props));
      },
      // 3. 重写非标准 `description` 标签的渲染
      // @ts-expect-error - 告知 TypeScript 我们知道这是一个自定义的、非标准的 HTML 标签
      description: function description(props) {
        return /*#__PURE__*/React.createElement("span", _extends({
          style: {
            fontSize: '12px',
            color: '#777',
            display: 'block'
          }
        }, props));
      } // 你还可以重写更多...
      // h1: (props) => <h1 style={{ color: 'blue' }} {...props} />,
      // a: (props) => <a style={{ color: 'green' }} target="_blank" rel="noopener noreferrer" {...props} />,
    }
  }, content);
});