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.35k stars 857 forks source link

cdn使用相对地址/相对协议时css被重复加载 #1606

Closed lz6060788 closed 5 months ago

lz6060788 commented 6 months ago

编辑模式

任何模式

描述问题

由于在内网环境访问不到cdn,于是我把cdn资源搬到了我的nuxt服务上,因此设置的cdn地址为相对地址。 此时引入代码高亮主题的js在判断link元素的href前后一致时有误。

const vditorHljsStyle = document.getElementById("vditorHljsStyle") as HTMLLinkElement;
const href = `${cdn}/dist/js/highlight.js/styles/${style}.css`;
// .href将获取到dom的完整地址,.getAttribute('href')才能够获取到相对地址,与href变量计算一致。
if (vditorHljsStyle && vditorHljsStyle.href !== href) {
    vditorHljsStyle.remove();
}

期待的结果

支持相对地址/相对协议

截屏或录像

image image

版本信息

其他信息

Vanessa219 commented 5 months ago

https://github.com/Vanessa219/vditor/pull/1607