-
-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🐛 Fix #1518 * 🐛 Fix #1269 * 🗑️ Clean code for 1269 * 🐛 Fix link-ref-defs-block parsing error * ♻️ Refactor the combine footnote function * 🐛 Fix similar problem with #1518 on link-ref-defs-block
- Loading branch information
1 parent
fa28133
commit 6bc8fa1
Showing
4 changed files
with
57 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* 合并脚注 | ||
* @param elements vditor.sv.element | ||
* @param afterCombine 每个脚注块合并完成后的回调, param: root为合并后的脚注块 | ||
*/ | ||
export const combineFootnote = (elements: HTMLElement, afterCombine?: (root: HTMLElement) => void ) => { | ||
elements.querySelectorAll("[data-type=footnotes-link]").forEach((el: Element) => { | ||
const root = el.parentElement | ||
let footnote = root.nextSibling | ||
// 寻找所有该脚注的块 | ||
while (footnote) { | ||
if (footnote.textContent.startsWith(" ")) { | ||
// 解析到四个空格,加入到root并继续解析 | ||
const thisNode = footnote | ||
thisNode.childNodes.forEach(node => { | ||
root.append(node.cloneNode(true)) | ||
}) | ||
footnote = footnote.nextSibling | ||
thisNode.remove() | ||
} else { | ||
// 非空格停止解析 | ||
break | ||
} | ||
} | ||
afterCombine && afterCombine(root) | ||
}) | ||
} |