feat: 🚀 切换富文本编辑器
This commit is contained in:
15
src/utils/convertSpanToDiv.ts
Normal file
15
src/utils/convertSpanToDiv.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export const convertSpanToDiv = (html: any) => {
|
||||
const parser = new DOMParser();
|
||||
const doc = parser.parseFromString(html, "text/html");
|
||||
const spans = doc.querySelectorAll("span");
|
||||
if (!spans.length) {
|
||||
return;
|
||||
}
|
||||
spans.forEach((span: any) => {
|
||||
if (span.querySelector("img")) {
|
||||
const img = span.querySelector("img");
|
||||
span.parentNode.replaceChild(img, span);
|
||||
}
|
||||
});
|
||||
return doc.body.innerHTML;
|
||||
};
|
||||
13
src/utils/recursiveCompare.ts
Normal file
13
src/utils/recursiveCompare.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const recursiveCompare = (item: any, targetId: any) => {
|
||||
if (typeof item === "object" && item !== null) {
|
||||
if (item.value !== undefined && item.value === targetId) {
|
||||
return true;
|
||||
}
|
||||
for (const key in item) {
|
||||
if (recursiveCompare(item[key], targetId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user