I am currently working on a project that requires grabbing text from an epub.
We are using React-Native and Futurepress epubjs-rn.
Trying to Achieve:
- User highlights word on mobile device via longPress
- Highlighted text is grabbed from highlighted region and used elsewhere in application.
Current Attempts:
I have tried the onSelected
prop which returns an event that contains the CFI position of the selected area, but I cannot figure out how to pull actual text from the parsed CFI location.
On the epubjs-rn Github, onMarkClicked
was recommended for a similar issue, but am unable to trigger.
Here is my current code:
import React from 'react';
import { StyleSheet, Text, View, TouchableHighlight, Alert , WebView } from "react-native";
import { Epub } from 'epubjs-rn';
const epubCFI = require('./lib/EpubCFI/src/epubcfi');
export default class App extends React.Component {
constructor(props) {
super(props);
}
onLongPress = (event) => {
console.log("epubCFI.prototype.parse(): " , epubCFI.prototype.parse(event));
console.log("epubCFI.prototype.getRange(): ", epubCFI.prototype.getRange(event));
}
selectText = (event, rendition) => {
console.log('event', event);
const parsedEvent = epubCFI.prototype.parse(event);
}
render() {
return (
<Epub onSelected={(event, rendition) => this.selectText(event, rendition)}
onLongPress={this.onLongPress.bind(this)}
src={"https://s3.amazonaws.com/epubjs/books/moby-dick/OPS/package.opf"}
flow="scrolled" />
)
}
}
Any help would be appreciated. Thanks~