Skip to content

Instantly share code, notes, and snippets.

@fchasen
Created July 1, 2015 13:12
Show Gist options
  • Save fchasen/140346a0ef928116d44a to your computer and use it in GitHub Desktop.
Save fchasen/140346a0ef928116d44a to your computer and use it in GitHub Desktop.
Find CFI text
var epubcfi = new EPUBJS.EpubCFI();
var text;
// Find the range
var range = epubcfi.generateRangeFromCfi("epubcfi(/6/14[xchapter_001]!4/2/14/2[c001p0006]/1:305)", Book.renderer.doc);
text = range.toString();
// Or find the containing element and then get the offset
var parent = epubcfi.findParent("epubcfi(/6/14[xchapter_001]!4/2/14/2[c001p0006]/1:305)", Book.renderer.doc);
text = parent.textContent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment