Skip to content

Commit

Permalink
🐛 Fix #1518 (#1521)
Browse files Browse the repository at this point in the history
  • Loading branch information
justice2001 authored Dec 15, 2023
1 parent e72899d commit fa28133
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
21 changes: 6 additions & 15 deletions src/ts/sv/inputEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export const inputEvent = (vditor: IVditor, event?: InputEvent) => {

// 添加脚注
vditor.sv.element.querySelectorAll("[data-type='footnotes-link']").forEach((item, index) => {
if (index === 0 && item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) {
// 加入所有脚注便于渲染引用
if (item && !(blockElement as HTMLElement).isEqualNode(item.parentElement)) {
html += "\n" + item.parentElement.textContent;
item.parentElement.remove();
}
Expand Down Expand Up @@ -181,20 +182,10 @@ export const inputEvent = (vditor: IVditor, event?: InputEvent) => {
}

// 脚注合并后添加的末尾
let firstFootnoteElement: Element;
const allFootnoteElement = vditor.sv.element.querySelectorAll("[data-type='footnotes-link']");
allFootnoteElement.forEach((item, index) => {
if (index === 0) {
firstFootnoteElement = item.parentElement;
} else {
firstFootnoteElement.lastElementChild.remove();
firstFootnoteElement.insertAdjacentHTML("beforeend", `${item.parentElement.innerHTML}`);
item.parentElement.remove();
}
});
if (allFootnoteElement.length > 0) {
vditor.sv.element.insertAdjacentElement("beforeend", firstFootnoteElement);
}
vditor.sv.element.querySelectorAll("[data-type='footnotes-link']")
.forEach((item, index) => {
vditor.sv.element.insertAdjacentElement("beforeend", item.parentElement)
});

setRangeByWbr(vditor.sv.element, range);

Expand Down
22 changes: 6 additions & 16 deletions src/ts/sv/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ export const processPaste = (vditor: IVditor, text: string) => {
blockElement = vditor.sv.element;
}
let spinHTML = vditor.lute.SpinVditorSVDOM(blockElement.textContent)
if (spinHTML.indexOf('data-type="footnotes-link"') > -1 ||
spinHTML.indexOf('data-type="link-ref-defs-block"') > -1) {
spinHTML = "<div data-block='0'>" + spinHTML + "</div>";
} else {
spinHTML = "<div data-block='0'>" +
spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
"</div>";
}
spinHTML = "<div data-block='0'>" +
spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
"</div>";
if (blockElement.isEqualNode(vditor.sv.element)) {
blockElement.innerHTML = spinHTML;
} else {
Expand Down Expand Up @@ -56,14 +51,9 @@ export const getSideByType = (spanNode: Node, type: string, isPrevious = true) =
export const processSpinVditorSVDOM = (html: string, vditor: IVditor) => {
log("SpinVditorSVDOM", html, "argument", vditor.options.debugger);
const spinHTML = vditor.lute.SpinVditorSVDOM(html)
if (spinHTML.indexOf('data-type="footnotes-link"') > -1 ||
spinHTML.indexOf('data-type="link-ref-defs-block"') > -1) {
html = "<div data-block='0'>" + spinHTML + "</div>";
} else {
html = "<div data-block='0'>" +
spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
"</div>";
}
html = "<div data-block='0'>" +
spinHTML.replace(/<span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span><span data-type="newline"><br \/><span style="display: none">\n<\/span><\/span></g, '<span data-type="newline"><br /><span style="display: none">\n</span></span><span data-type="newline"><br /><span style="display: none">\n</span></span></div><div data-block="0"><') +
"</div>";
log("SpinVditorSVDOM", html, "result", vditor.options.debugger);
return html;
};
Expand Down

0 comments on commit fa28133

Please sign in to comment.