fix(kosync): handle non-standard XPath syntax from Koreader, closes #1968 (#1988)

This commit is contained in:
Huang Xin
2025-09-07 12:05:27 +08:00
committed by GitHub
parent 48d754c184
commit 55b2c678a4
+8 -3
View File
@@ -544,12 +544,17 @@ export const getXPointerFromCFI = async (
// Koreader sometimes cannot recognize totally valid XPointer.
// Workaround this by cleaning up any trailing /text().N segments.
// Also remove any trailing .N suffixes after node steps.
// 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\(\).*$/;
if (xpointer.match(tailingTextRange)) {
xpointer = xpointer.replace(tailingTextRange, '');
const tailingTextOffset = /\/text\(\).*$/;
if (xpointer.match(tailingTextOffset)) {
xpointer = xpointer.replace(tailingTextOffset, '');
}
const suffixNodeOffset = /\.\d+$/;
if (xpointer.match(suffixNodeOffset)) {
xpointer = xpointer.replace(suffixNodeOffset, '');
}
return xpointer;
};