提交 8039f5e4 编写于 作者: 璃白.'s avatar 璃白. 🌻

🐛 过滤img onerror事件

上级 7aa51ca6
无法预览此类型文件
...@@ -147,6 +147,7 @@ ...@@ -147,6 +147,7 @@
// console.log(res); // console.log(res);
}, },
onUpload: function(file, type, callback) { onUpload: function(file, type, callback) {
debugger
if (type === "video" || type === "img") { if (type === "video" || type === "img") {
let time = 0; let time = 0;
const timeObj = setInterval(() => { const timeObj = setInterval(() => {
......
{
"devDependencies": {
"http-server": "^14.1.0"
}
}
...@@ -535,9 +535,9 @@ export default { ...@@ -535,9 +535,9 @@ export default {
item.linkType = linkEl.getAttribute("data-type"); item.linkType = linkEl.getAttribute("data-type");
linkEl.setAttribute("target", "_blank"); linkEl.setAttribute("target", "_blank");
linkEl.setAttribute("href", url); linkEl.setAttribute("href", url);
if (item.url.includes(".ipynb")) { // if (item.url.includes(".ipynb")) {
linkEl.className = "jupyterEl"; // linkEl.className = "jupyterEl";
} // }
const title = getLinkTitle(linkEl, item); const title = getLinkTitle(linkEl, item);
linkEl.innerHTML = renderLinkCard(title, item); linkEl.innerHTML = renderLinkCard(title, item);
}); });
......
// 获取选中文本信息 // 获取选中文本信息
import DOMPurify from "dompurify";
export function getSelectionInfo(selectorId) { export function getSelectionInfo(selectorId) {
const selector = document.getElementById(selectorId); const selector = document.getElementById(selectorId);
if (!selector) return; if (!selector) return;
...@@ -224,21 +225,21 @@ export function removeBlankLine(val) { ...@@ -224,21 +225,21 @@ export function removeBlankLine(val) {
} }
// 获取被过滤掉的标签 // 获取被过滤掉的标签
export function getFilteredTags(oldStr, newStr) { // export function getFilteredTags(oldStr, newStr) {
// if (oldStr.length - newStr.length === 0) return []; // // if (oldStr.length - newStr.length === 0) return [];
// const filteredStr = oldStr.replace(newStr.trim(), ""); // // const filteredStr = oldStr.replace(newStr.trim(), "");
// console.log(11, filteredStr); // // console.log(11, filteredStr);
const virtualDom = document.createElement("div"); // const virtualDom = document.createElement("div");
virtualDom.innerHTML = oldStr; // virtualDom.innerHTML = oldStr;
const oldTags = Array.from(virtualDom.getElementsByTagName("*")); // const oldTags = Array.from(virtualDom.getElementsByTagName("*"));
virtualDom.innerHTML = newStr; // virtualDom.innerHTML = newStr;
const newTags = Array.from(virtualDom.getElementsByTagName("*")); // const newTags = Array.from(virtualDom.getElementsByTagName("*"));
// 待优化 // // 待优化
const filteredTags = new Array(oldTags.length - newTags.length).fill(0); // const filteredTags = new Array(oldTags.length - newTags.length).fill(0);
return filteredTags; // return filteredTags;
} // }
// 格式刷的规则 // 格式刷的规则
export function copyFormatRules(selection) { export function copyFormatRules(selection) {
if (!selection) return ""; if (!selection) return "";
...@@ -348,7 +349,7 @@ export function copyFormatRules(selection) { ...@@ -348,7 +349,7 @@ export function copyFormatRules(selection) {
export function addLanguageClass(html) { export function addLanguageClass(html) {
const virtualDom = document.createElement("div"); const virtualDom = document.createElement("div");
virtualDom.innerHTML = html; virtualDom.innerHTML = DOMPurify.sanitize(html);
virtualDom.querySelectorAll("code").forEach(item => { virtualDom.querySelectorAll("code").forEach(item => {
if (!/language-/.test(item.className)) { if (!/language-/.test(item.className)) {
item.className = "language-javascript"; item.className = "language-javascript";
......
jupyter-render @ 9a1cda54
Subproject commit 9a1cda54eb91de46852797e1d4ddb66c667d6747
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
} }
html, html,
body, body {
#app {
padding: 0; padding: 0;
margin: 0; margin: 0;
min-height: 100vh; min-height: 100vh;
......
import { import {
getFilteredTags, // getFilteredTags,
getLinkTags, getLinkTags,
addLanguageClass, addLanguageClass,
formatElements, formatElements,
...@@ -36,7 +36,8 @@ export default { ...@@ -36,7 +36,8 @@ export default {
], ],
FORBID_ATTR: ["style"] FORBID_ATTR: ["style"]
}); // 去除标签 }); // 去除标签
const filteredTags = getFilteredTags(html, cleanHtml); // 计算是否有标签被过滤 const filteredTags = DOMPurify.removed; // 计算是否有标签被过滤
// const filteredTags = getFilteredTags(html, cleanHtml); // 计算是否有标签被过滤
// 链接转换为卡片 // 链接转换为卡片
// 获取标题列表 // 获取标题列表
const { vDom, links, dirTags } = getLinkTags(this.id, cleanHtml); const { vDom, links, dirTags } = getLinkTags(this.id, cleanHtml);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册