tinymce6可以粘贴word+wps文字图片的插件

下载地址:https://github.com/hanghang2/tinymce-pastewordimage
创作不易,给颗小星星呐!

tinymce6 pastewordimage插件

一款从word粘贴到富文本框图片正常显示插件,wps和office都可以正常复制粘贴图片

使用步骤:
第一步:把当前plugins目录下的pastewordimage文件夹拷贝到你的项目tinymce/plugins目录下去;
例如react项目,路径为 项目根目录/public/tinymce/plugins/

第二步:tinymce初始化init配置plugins参属下增加pastewordimage;
例如:

// 如下增加pastewordimage参数


<Editor
    init={{
        branding: false, // 去掉右下角的水印
        menubar: true, // 菜单栏
        height: 500,
        plugins: [
            'advlist', 'autolink', 'lists', 'link', 'image', 'charmap', 'preview',
            'anchor', 'searchreplace', 'visualblocks', 'code', 'fullscreen',
            'insertdatetime', 'media', 'table', 'code', 'help', 'wordcount', 'codesample',
            'pastewordimage', // word复制图片插件
        ],
    }}
    initialValue="<p>This is the initial content of the editor.</p>"
    onInit={(evt, editor) => editorRef.current = editor}
    rootClassName={style.editor}
/>

第三步:版当前项目的tinymce.min.js文件拷贝到项目的tinymce目录中进行覆盖;
解释:

// 源码中 wps粘贴单个图片时候粘贴的内容中会有text/html类型,导致getDataTransferItems函数返回结果不正确;
// 修改如下:items[contentType]赋值增加判断;

const getDataTransferItems = dataTransfer => {
    const items = {};
    if (dataTransfer && dataTransfer.types) {
        for (let i = 0; i < dataTransfer.types.length; i++) {
            const contentType = dataTransfer.types[i];
            try {
                // items[contentType] = dataTransfer.getData(contentType);
                items[contentType] = dataTransfer.types.indexOf('Files') === -1 ? dataTransfer.getData(contentType) : ''; // wps粘贴单个图片问题处理
            } catch (ex) {
                items[contentType] = '';
            }
        }
    }
    return items;
};

下载地址:https://github.com/hanghang2/tinymce-pastewordimage

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值