Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get cfi position from string? #3

Open
Yaco opened this issue Sep 9, 2020 · 1 comment
Open

Get cfi position from string? #3

Yaco opened this issue Sep 9, 2020 · 1 comment

Comments

@Yaco
Copy link

Yaco commented Sep 9, 2020

Hi! Just wondering if it would be possibl to use this to get cfi position (range?) of a string of text inside an ePub file?

Thanks!

@Juul
Copy link
Member

Juul commented Sep 9, 2020

Hm. You can use the function CFI.generate(node, offset, extra) to generate a CFI given a reference to a node (e.g. a text node) and an optional offset into the text node, and you could do that twice for the beginning and end of the range but there is currently no function for turning those two CFIs into a range CFI.

This is definitely an oversight and needs to be added. Pull requests very welcome.

I'd look at the CFI.generatePart function and instead of directly building the CFI in reverse order, then build the same data structure as returned by the .get function. Once you have such a data structure for both the start and end CFIs I'd traverse these two data structures in the forward direction, comparing them and building the range CFI on piece at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants