news 2026/7/10 1:40:29

Md编辑器整合-react

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Md编辑器整合-react

推荐md编辑器 - ByteMD

在线体验:ByteMD Playground

git 链接:GitHub - pd4d10/bytemd: ByteMD v1 repository

安装

编辑器本体

pnpm install @bytemd/react

官方插件 - 代码高亮 & 支持 GFM 功能(自动链接文字、删除线、表格、任务列表等)

pnpm install @bytemd/plugin-highlight @bytemd/plugin-gfm

MdEditor 组件

import gfm from '@bytemd/plugin-gfm' import { Editor } from '@bytemd/react' import highlight from '@bytemd/plugin-highlight' import 'bytemd/dist/index.css' import 'highlight.js/styles/vs.css' import './github-markdown-light.css' import './index.css' interface Props { value?: string onChange?: (value: string) => void placeholder?: string } const plugins = [gfm(), highlight()] /** * 编辑器 * @param props * @constructor */ const MdEditor = (props: Props) => { const { value = '', onChange, placeholder } = props return ( <Editor className="md-editor" value={value} placeholder={placeholder} mode="split" plugins={plugins} onChange={onChange} /> ) } export default MdEditor

MdViewer 组件

import gfm from '@bytemd/plugin-gfm' import { Viewer } from '@bytemd/react' import highlight from '@bytemd/plugin-highlight' import 'bytemd/dist/index.css' import 'highlight.js/styles/vs.css' import '../MdEditor/github-markdown-light.css' import './index.css' interface Props { value?: string } const plugins = [gfm(), highlight()] /** * Md 浏览器 * @param props * @constructor */ const MdViewer = (props: Props) => { const { value = '' } = props return ( <div className="md-viewer"> <Viewer value={value} plugins={plugins} /> </div> ) } export default MdViewer

引入 github markdown 样式

github 地址:GitHub - sindresorhus/github-markdown-css: The minimal amount of CSS to replicate the GitHub Markdown style · GitHub

测试

在全局基础布局组件引入编辑器组件进行效果测试

'use client' import { ProLayout } from '@ant-design/pro-components' import { Dropdown, Input } from 'antd' import React, { useEffect, useState } from 'react' import MdEditor from '@/components/MdEditor' import MdViewer from '@/components/MdViewer' interface props { children: React.ReactNode } export default function BasicLayout({ children }: props) { const [text, setText] = useState<string>('') ... return ( <div id="basic-layout" style={{ height: '100vh', }} > <ProLayout ... > <MdEditor value={text} onChange={setText} /> <MdViewer value={text} /> {children} </ProLayout> </div> ) }

效果图

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/10 1:35:11

VAE模型是什么?为什么说它是画质保命符

你有没有遇到过这样的情况:明明用了不错的模型、写了详细的提示词、参数也调得挺认真,但生成出来的图片总感觉 灰蒙蒙的、颜色发暗、细节模糊,像是隔了一层雾? 或者更糟——生成的图片 完全是一团黑,什么都没有? 如果你遇到这些问题,十有八九是 VAE(变分自编码器) 出…

作者头像 李华
网站建设 2026/7/10 1:33:12

2026年邵阳VI设计机构市场专业水平现状与发展趋势

导语 在当今竞争激烈的商业环境中&#xff0c;品牌形象的塑造至关重要&#xff0c;VI设计作为品牌视觉识别系统的核心&#xff0c;其重要性不言而喻。2026年&#xff0c;邵阳的VI设计机构市场呈现出独特的面貌。相传国际作为行业内具有一定影响力的品牌&#xff0c;一直关注着…

作者头像 李华
网站建设 2026/7/10 1:33:10

3个步骤掌握命令行大文件上传工具:从零开始使用Zenodo-Upload

3个步骤掌握命令行大文件上传工具&#xff1a;从零开始使用Zenodo-Upload 【免费下载链接】zenodo-upload upload big files to Zenodo using cURL, jq and bash 项目地址: https://gitcode.com/gh_mirrors/ze/zenodo-upload 你是否曾经需要上传大型研究数据文件到开放科…

作者头像 李华
网站建设 2026/7/10 1:31:31

母线槽外壳与密封结构设计:加厚铝合金外壳如何提升防护等级@TOC

母线槽多铺设于地下室、室外管廊、化工车间等潮湿、多粉尘、有腐蚀性介质环境&#xff0c;外壳材质厚度、密封结构直接决定整机防护等级与使用寿命。很多项目投入使用两三年出现外壳变形、进水进灰、内部导体锈蚀&#xff0c;大多是外壳用料单薄、密封结构简化导致。本文从结构…

作者头像 李华
网站建设 2026/7/10 1:29:18

新手亲测推荐——素月古琴太适合初学者

新手亲测推荐——素月古琴太适合初学者 作为一名零基础入门古琴的学生&#xff0c;刚开始学琴时&#xff0c;我最大的焦虑不是看不懂减字谱、练不会指法&#xff0c;而是不知道该选一张什么样的入门琴。相信很多初学琴友和我一样&#xff0c;选琴时左右为难&#xff1a;几百块的…

作者头像 李华