Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复SV模式下脚注下方输入文本出现渲染错误 #1521

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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