quill 储存 为markdown 文件

文章展示了在Vue.js项目中使用Quill富文本编辑器的过程,包括设置toolbar、注册表格模块和转换为Markdown格式。由于遇到问题,作者最终选择切换到TinyMCE编辑器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
    <div class="editor-container">
        <div ref="editor"></div>
        <button @click="save">保存</button>
    </div>
</template>
  
<script>
import Quill from 'quill'
import 'quill/dist/quill.snow.css'
import { marked } from 'marked'
import TableModule from 'quill-table'

Quill.register('modules/table', TableModule)

export default {
    data() {
        return {
            quill: null
        }
    },
    methods: {
        save() {
            let html = this.quill.root.innerHTML
            let markdown = marked(html)
            // TODO: 保存markdown
            console.log('我都markdown文件');
            console.log(markdown);
            // fs.writeFile('article.md', markdown, err => {
            //     if (err) throw err
            //     this.$message('Saved!')
            // })
        }
    },
    mounted() {
        const toolbarOptions = [
            ['bold', 'italic', 'underline'], // 加粗,斜体,下划线,删除线
            [{ 'header': [1, 2, 3, 4, 5, 6, false] }], // 标题
            [{ 'color': [] }, { 'background': [] }], // 字体颜色,背景颜色
            [{ 'align': [] }], // 对齐方式
            [{ 'list': 'ordered' }, { 'list': 'bullet' }], // 有序列表,无序列表
            ['link', 'image', 'video'], // 链接,图片,视频
        ]

        this.quill = new Quill(this.$refs.editor, {
            modules: {
                toolbar: toolbarOptions
            },
            theme: 'snow'
        })
        this.quill.getModule('toolbar').addHandler('table', function () {
            const range = this.quill.getSelection();
            if (range) {
                this.quill.insertEmbed(range.index, 'table', [['', ''], ['', '']]);
            }
        });
        // let markdown = fs.readFileSync('article.md', 'utf8')
        // let html = marked(markdown)
        // this.quill.root.innerHTML = html

    }
}
</script>
  
<style>
.editor-container {
    width: 800px;
    margin: 0 auto;
    padding: 20px;
}
</style>

这里由于 quill 踩坑太多 没有继续写下去 换成了 tinymce 富文本框,记录一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值