fix(footnote): add custom attributes for footnote in sanitizer, closes #2651 (#2657)

This commit is contained in:
Huang Xin
2025-12-09 12:27:52 +08:00
committed by GitHub
parent b425bfdc89
commit de3a539621
2 changed files with 18 additions and 21 deletions
@@ -176,27 +176,22 @@ export const handleClick = (
lastClickTime = now;
const postSingleClick = () => {
let element: HTMLElement | null = event.target as HTMLElement;
while (element) {
if (['sup', 'a', 'audio', 'video'].includes(element.tagName.toLowerCase())) {
return;
}
if (
element.classList.contains('js_readerFooterNote') ||
element.classList.contains('zhangyue-footnote')
) {
eventDispatcher.dispatch('footnote-popup', {
bookKey,
element,
footnote:
element.getAttribute('data-wr-footernote') ||
element.getAttribute('zy-footnote') ||
element.getAttribute('alt') ||
'',
});
return;
}
element = element.parentElement;
const element = event.target as HTMLElement | null;
if (element?.closest('sup, a, audio, video')) {
return;
}
const footnote = element?.closest('.js_readerFooterNote, .zhangyue-footnote');
if (footnote) {
eventDispatcher.dispatch('footnote-popup', {
bookKey,
element: footnote,
footnote:
footnote.getAttribute('data-wr-footernote') ||
footnote.getAttribute('zy-footnote') ||
footnote.getAttribute('alt') ||
'',
});
return;
}
// if long hold is detected, we don't want to send single click event
@@ -25,6 +25,8 @@ export const sanitizerTransformer: Transformer = {
'link',
'vlink',
'imt-state', // custom attribute generated by some translators
'data-wr-footernote', // custom attribute for weread footnotes
'zy-footnote', // custom attribute for zhangyue footnotes
];
return (
attrWhitelist.includes(attributeName) ||