Conversation
|
What's the use case for this? Are you mutating the OPF? |
|
The use case is just the one mentioned in your readme, in the "epub cfi" section:
In particular, I give the possibility to insert a horizontally scrollable container around block math elements (all the major browsers now support natively MathML Core, but only Firefox handles breaklines). I subclassed the View class in view.js and I use a filter in the getCFI and resolveCFI methods, but for that to work, the epub's resolveCFI method and the CFI.toElement function need to accept the filter also. The default behavior of the foliate-js library remains unchanged. |
|
Well, Also |
|
Ok, in my proposal I changed
In my project I subclassed the getCFI(index, range) {
const baseCFI = this.book.sections[index].cfi ?? CFI.fake.fromIndex(index)
if (!range) return baseCFI
return CFI.joinIndir(baseCFI, CFI.fromRange(range, cfiFilter))
}
resolveCFI(cfi) {
if (this.book.resolveCFI)
return this.book.resolveCFI(cfi, cfiFilter)
else {
const parts = CFI.parse(cfi)
const index = CFI.fake.toIndex((parts.parent ?? parts).shift())
const anchor = doc => CFI.toRange(doc, parts, cfiFilter)
return { index, anchor }
}
}I can change the PR adding |
|
I suppose there's nothing inherently wrong with adding a filter for when dealing with the OPF, but it just seems a bit unexpected to me. And although you're using the filter when using Perhaps it'd be better to design an interface for CFI, such that Another idea is to not use CFIs at all in |
This pull request adds the possibility to pass an optional cfi parser filter to the
resolveCFImethods inepub.jsand totoElementandfromElementsfunctions inepubcfi.js.