fix(kosync): normalize xpointer to improve KOReader sync tolerance, closes #1857 (#1914)

This commit is contained in:
Huang Xin
2025-08-27 15:18:32 +08:00
committed by GitHub
parent 584f3511f8
commit 515bfee2a1
3 changed files with 30 additions and 12 deletions
+12
View File
@@ -539,3 +539,15 @@ export const getXPointerFromCFI = async (
const xpointer = converter.cfiToXPointer(cfi);
return xpointer;
};
// Koreader sometimes cannot recognize totally valid XPointer.
// Workaround this by cleaning up any trailing /text().N segments.
// This has neglectable effect on position accuracy as the XPointer still point to the correct element
// while offset within the text node is usually ignored by pagination.
export const normalizeProgressXPointer = (xpointer: string): string => {
const tailingTextRange = /\/text\(\)\.\d+$/;
if (xpointer.match(tailingTextRange)) {
xpointer = xpointer.replace(tailingTextRange, '');
}
return xpointer;
};