!DOCTYPE htmlhtmlheadmeta charset="UTF-8"titleyuque编辑器/titlelink rel="stylesheet" type="text/css"href="https://gw.alipayobjects.com/render/p/yuyan_npm/@alipay_lakex-doc/1.12.0/umd/doc.css" /link rel="stylesheet" type="text/css" href="
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>yuque编辑器</title>
<link rel="stylesheet" type="text/css"
href="https://gw.alipayobjects.com/render/p/yuyan_npm/@alipay_lakex-doc/1.12.0/umd/doc.css" />
<link rel="stylesheet" type="text/css" href="https://unpkg.com/antd@4.24.13/dist/antd.css" />
</head>
<body>
<div id="root" class="ne-doc-major-editor"></div>
<script>
window.onload = function() {
const {
createOpenEditor
} = window.Doc;
// 创建编辑器
const editor = createOpenEditor(document.getElementById('root'), {
darkMode: false,
input: {},
image: {
isCaptureImageURL: (url) => {
// 判断当前url是否需要转存
// return true表示需要转存,会调用createUploadPromise
// return false表示不需要转存,直接用于展示
return true;
},
// 配置上传接口,要返回一个promise对象
createUploadPromise: (request) => {
const {
type,
data
} = request;
if (type === 'url') {
// data 是一个url,表示需要转存
} else if (type === 'file') {
// data是一个File
}
return Promise.resolve({
url: 'https://pgz-static.shidongvr.com/temp/hzy.jpg',
size: data.size, // 文件大小
filename: data.name
});
},
},
file: {
// 配置上传接口,要返回一个promise对象
createUploadPromise: (file) => {
// file是一个File对象
console.log(file)
return Promise.resolve({
url: 'https://pgz-dzdsgl-fastly.shidongvr.com/profile/upload/2023/12/22/266e2aa5-79f7-45ec-b5eb-7e7a474338e8.zip',
size: file.size, // 文件大小
filename: 'https://pgz-dzdsgl-fastly.shidongvr.com/profile/upload/2023/12/22/266e2aa5-79f7-45ec-b5eb-7e7a474338e8.zip',
});
},
},
video: {
// 配置上传接口,要返回一个promise对象
createUploadPromise: (file) => {
// file是一个File对象
return Promise.resolve({
url: 'https://pgz-dzdsgl-fastly.shidongvr.com/profile/upload/2023/12/22/4dc5803f-d790-4490-bf54-02d276b89afa.mp4',
size: file.size, // 文件大小
filename: file.name,
cover: '',
});
},
},
});
// 设置内容
editor.setDocument('text/lake',
'<p><span style="color: rgb(255, 111, 4),rgb(243, 48, 171)">欢迎来到yuque编辑器</span></p>');
// 监听内容变动
editor.on('contentchange', () => {
console.info(editor.getDocument('text/lake'));
});
}
</script>
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>\
<script src="https://gw.alipayobjects.com/render/p/yuyan_npm/@alipay_lakex-doc/1.12.0/umd/doc.umd.js"></script>
</body>
</html>