Vue3使用markdown编辑器之Bytemd

官网地址:https://bytemd.js.org/playground

GitHub地址:https://github.com/bytedance/bytemd

ByteMD 是字节跳动出品的富文本编辑器,功能强大,可以免费使用,而且支持很多掘金内置的主题,写作体验很棒。

ByteMD 编辑器使用 Svelte 框架开发,支持原生、Vue、React、Svelte 框架集成,几乎适用于所有前端开发人员。

有两个组件:Editor 和 Viewer。Editor 顾名思义就是 Markdown 编辑器;Viewer 通常用于显示渲染的 Markdown 结果,无需编辑。

安装:

shell 复制代码
npm install @bytemd/vue-next
shell 复制代码
# 安装辅助插件,例如gfm(表格支持)插件、highlight 代码高亮插件、GitHub风格的Markdown CSS框架
npm install @bytemd/plugin-gfm
npm install @bytemd/plugin-highlight
npm install github-markdown-css

封装组件

MdViewer.vue

html 复制代码
<template>
	<Viewer :value="value" :plugins="plugins" />
</template>

<script setup lang="ts">
	import { Viewer } from "@bytemd/vue-next";
	import gfm from "@bytemd/plugin-gfm";
	import highlight from "@bytemd/plugin-highlight";
	import "bytemd/dist/index.css";
	import "highlight.js/styles/default.css";
	import "github-markdown-css/github-markdown-light.css";
	// import "github-markdown-css/github-markdown-dark.css";

	const plugins = [
		gfm(), 
		highlight()
	];

	interface Props {
		value : string;
	}

	const props = withDefaults(defineProps<Props>(), {
		value: () => {
			return "";
		},
	});
</script>

使用

html 复制代码
import MdViewer from "./MdViewer.vue";
html 复制代码
<md-viewer :value="mdContent" />

效果:

相关推荐
来杯@Java9 小时前
图书管理系统(基于springboot+vue前后端分离的项目)计算机毕业设计java
java·spring boot·spring·vue·毕业设计·mybatis·课程设计
华大哥16 小时前
前后端分离实现五级行政区划树形菜单及设备查询管理
sqlite·vue·springboot
码界筑梦坊17 小时前
282-基于Python的豆瓣音乐可视化分析推荐系统
开发语言·python·信息可视化·数据分析·flask·vue
wbc1031555818 小时前
基于 VSCode + Icarus 的 Verilog 编译和仿真
ide·vscode·编辑器
似夜晓星辰19 小时前
Markdown文本编辑器Typora平替
编辑器·github
谷哥的小弟21 小时前
(最新版)VSCode安装图文详解教程
ide·vscode·编辑器·教程·前端开发·图文
chushiyunen21 小时前
滑块验证(滑动验证)
vue
xiaoliuliu1234521 小时前
LaTeX 2023 (TeX Live + TeXstudio) 安装与汉化教程 Windows版:自定义路径+编辑器配置指南
windows·编辑器
IOT.FIVE.NO.11 天前
Codex+Vscode+Remote ssh+ 服务器自定义第三方API配置保姆级教程
ide·vscode·编辑器
SpiderPex1 天前
Vibe Coding 开发流程心得:从入门到规范化的踩坑记录
vscode·编辑器·ai编程·开发流程·vibe coding