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 结果,无需编辑。

安装:

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

封装组件
MdViewer.vue

<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>

使用

import MdViewer from "./MdViewer.vue";
<md-viewer :value="mdContent" />

效果:

在这里插入图片描述

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员大佬超

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值