Yuque Rich Text(语雀富文本编辑器)

Yuque Rich Text(语雀富文本编辑器)

由于本人觉得语雀编辑器非常好用,很符合我的使用习惯,然后发现语雀的Chrome浏览器插件实现了编辑器的功能,所以将其富文本的功能拆分位一个单独的Vue3组件。

安装

sh 复制代码
npm i yuque-rich-text

截图

Props

ts 复制代码
export interface EditorProps {
        value: string; // 传递给组件的内容
        children?: any; 
        isview?: boolean; // 预览模式,用于在客户端页面展示结果。
        uploadImage?: (params: { data: string | File }) => Promise<{
            url: string;
            size: number;
            filename: string;
        }>;
        uploadVideo?: (params: { data: string | File }) => Promise<{
            url: string;
            size: number;
            filename: string;
        }>;
    }

Emit

ts 复制代码
export interface EditorEmits{
        onChange?: (value: string) => void;
        onLoad?: () => void;
        onSave?: () => void;
    }

Expose

ts 复制代码
export interface IEditorRef {
        /**
         * 追加html到文档
         * @param html html内容
         * @param breakLine 是否前置一个换行符
         */
        appendContent: (html: string, breakLine?: boolean) => void;
        /**
         * 设置文档内容,将清空旧的内容
         * @param html html内容
         */
        setContent: (content: string, type?: "text/lake" | "text/html") => void;
        /**
         * 获取文档内容
         * @param type 内容的格式
         * @return 文档内容
         */
        getContent: (type: "lake" | "text/html") => Promise<string>;
        /**
         * 判断当前文档是否是空文档
         * @return true表示当前是空文档
         */
        isEmpty: () => boolean;

        /**
         * 获取额外信息
         * @return
         */
        getSummaryContent: () => string;

        /**
         * 统计字数
         * @return
         */
        wordCount: () => number;

        /**
         * 聚焦到文档开头
         * @param {number} offset 偏移多少个段落,可以将选区落到开头的第offset个段落上, 默认是0
         * @return
         */
        focusToStart: (offset?: number) => void;

        /**
         * 插入换行符
         * @return
         */
        insertBreakLine: () => void;
    }

使用编辑器

使用非常简单,只需import组件即可

注意不可在onChange事件中修改value的值,否则会进入无限递归。

vue3 复制代码
<template>
      <YuqueRichText ref="editRef" :value="modelValue"/>
</template>

<script setup lang="ts">
import { ref, watch, PropType } from "vue";
import { YuqueRichText } from "yuque-rich-text";

const editRef = ref<InstanceType<typeof YuqueRichText>>();
const modelValue = ref("hello yuque richtext");
</script>

⚠️ Disclaimer

This is an unofficial third-party extension for [www.yuque.com]. It is not affiliated with, maintained by, or endorsed by [www.yuque.com].

  • Use at your own risk. The developers are not responsible for any violations of [www.yuque.com]'s terms or damages caused by this project.
  • Do not use if [www.yuque.com] prohibits third-party modifications.
  • This project does not redistribute any copyrighted materials from [www.yuque.com].
相关推荐
Be1k016 天前
推荐一款语雀知识库批量导出工具
python·gui·工具·语雀·批量导出·原创
扫地僧过江南3 个月前
一文讲解:sward的快速安装、快速入门
语雀·confluence·开源知识库管理工具
一叶轻舟随风行4 个月前
sward全面介绍(1) - 安装、配置
语雀·confluence·开源知识库管理工具
一叶轻舟随风行4 个月前
多款知识管理工具纵评:confluence、语雀、notion、sward
语雀·confluence·开源知识管理工具
一叶轻舟随风行4 个月前
sward V2.1.7 版本发布,新增Arm64架构的centos/ubuntu/debian等系统安装与钉钉消息通知
语雀·confluence·开源知识管理工具
想看一次满天星5 个月前
阿里140-语雀逆向分析
javascript·爬虫·python·语雀·阿里140
一叶轻舟随风行5 个月前
sward V2.1.5 版本发布,支持文档导出为html\PDF,社区版新增多种账号集成与认证
语雀·confluence·知识管理工具
一叶轻舟随风行5 个月前
一文掌握,sward安装与配置
语雀·confluence·知识管理工具
茄菲猫的往事5 个月前
2025知识协作工具选型,confluence vs 语雀 vs sward哪一款更好用?
语雀·confluence
城南花开时5 个月前
confluence or 语雀 or sward,知识管理工具一文全方位对比
语雀·confluence·sward