cherry-markdown
cherry-markdown copied to clipboard
[clinet] 静态资源
issue type
Bug
Clear and concise description of the problem or idea.
我在开发一个electron应用,其中图片保存到了本地,我在做图片url处理的时候,发现本地的文件路径背会编码,导致无法正常渲染图片,这个可以设置去除这个拦截吗
Additional context
No response
Validations
- [ ] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Help us
None
感觉有更好的方法,我最近忙,还没有去做处理和思考。
fileUpload(file: File, callback: (path: string, arg: { [key: string]: any }) => void) {
console.log(file)
const fileUrl = URL.createObjectURL(file)
console.log('url', fileUrl)
if (/video/i.test(file.type)) {
callback(fileUrl, {
name: `${file.name.replace(/\.[^.]+$/, '')}`,
poster: '/favicon.ico',
isBorder: true,
isShadow: true,
isRadius: true,
width: '300px',
height: 'auto',
});
} else {
callback(fileUrl, { name: `${file.name.replace(/\.[^.]+$/, '')}`, isShadow: true });
}
},
你这个是文件上传阶段,我的问题是有个图片是本地图片,我在markdown写的是绝对路径,但是在渲染的时候,我发现cherry-markdown会对文件路径使用encodeURIComponent方法,导致图片无法渲染
这个跟 encode 无关。浏览器加载本地资源请使用 file 协议的 uri。
可以通过配置 engine.global.urlProcessor 自行定制链接转换逻辑。
https://github.com/Tencent/cherry-markdown/blob/892c7b7811cbb8b0f7cc99d1c968f8ce73760a54/src/Cherry.config.js#L99-L105
