Vanessa219 / vditor

♏ 一款浏览器端的 Markdown 编辑器,支持所见即所得(富文本)、即时渲染(类似 Typora)和分屏预览模式。An In-browser Markdown editor, support WYSIWYG (Rich Text), Instant Rendering (Typora-like) and Split View modes.
https://b3log.org/vditor
MIT License
8.09k stars 844 forks source link

是否可以写一些 example 用来了解使用方法活着补充一些文档 #1629

Closed joebnb closed 1 month ago

joebnb commented 1 month ago

因为API比较多,有时候完成一件事需要了解多个 API 才能完成,但官方文档写的不是特别全(比如Upload的地方)

如题,是否可以在repo 下写一写 popular topic example,用来将大部分问题进行归纳回答

我这样配置了,但是(ctr+v)每次插入 markdown 的位置都不是预期 cursor 位置,时有时无,我觉得是我理解的 API 不够全面,没有掌握你写代码时候的想法,是否可以给个比较完整的example,这样会更容易理解一些

upload: {
    url: wrapApi('/file/upload/article'),
    max: 3 * 1024 * 1024,
    success: (target, resStr) => {
        const res = JSON.parse(resStr);
        const markdownImg = toObsUrl(res.data?.[0]?.path);
        vd?.insertValue(`![](${markdownImg})`);
    },
},

当然,辛苦在这里解答一下也可以

joebnb commented 1 month ago

似乎写的没有问题,重新启动了构建器正常了,这是示例代码,在光标位置插入markdown img标签,以及自动重命名上传文件文件

 upload: {
                url: wrapApi('/file/upload/article'),
                max: 10 * 1024 * 1024,
                file(files) {
                    return files.map((originalFile) => {
                        const newFileName = `image_${dayjs().toISOString()}_${generateUuid('xxxx-xx')}`;
                        const newFile = new File([originalFile], newFileName, {
                            type: originalFile.type,
                            lastModified: originalFile.lastModified,
                        });
                        return newFile;
                    });
                },
                success: (target, resStr) => {
                    const res = JSON.parse(resStr);
                    const markdownImg = toObsUrl(res.data?.[0]?.path);
                    vditor?.insertValue(`![](${markdownImg})`);
                },
            },

还有一个问题,自建CDN这个是否可以给个参数或者 import 文件,让直接集成到项目中

joebnb commented 1 month ago

目前感觉快速介入这部分,CDN是个问题,接入后一定会觉得编辑器加载慢,一看就发现是 CDN 问题,但是自己去改的话改动会有不少,希望看可不可以解决下

Vanessa219 commented 1 month ago

CDN 接口已经优化过了。