3

I am trying to make "Highlighter" for epub reader in one my Android project using webview. I am using Rangy for getting Selected text. The serialize functions gives me this value after selecting text from the below sample HTML:

2/5/3/5/1/2:0,13/5/3/5/1/2:24

I am storing this in DB. When user returns to this page, i am retrieving the same selection and trying to deserialize but the deserialize function throws the following error:

Error in Rangy Serializer module: deserializePosition failed: node <DIV>[7] has no child with index 13, 0

I am getting why this is happenig?? Even i am trying to do the same thing using XPath but still the same issue.

<html>
<head>
<script></script>
</head>
<body>
<div id="mainpage" class="highlighter-context">
<div>       Some text here also....... </div>
<div>      Some text here also.........</div>
<div>
  <h1 class="heading"></h1>
  <div class="left_side">
<ol></ol>
<h1></h1>
<div class="text_bio">
In human beings, height, colour of eyes, complexion, chin, etc. are 
some recognisable features. A feature that can be recognised is known as 
character or trait. Human beings reproduce through sexual reproduction. In this                
process, two individuals one male and another female are involved. Male produces   
male gamete or sperm and female produces female gamete or ovum. These gametes fuse 
to form zygote which develops into a new young one which resembles to their parent. 
During the process of sexual reproduction 
</div>
  </div>
  <div class="righ_side">
  Some text here also.........
  </div>
  <div class="clr">
    Some text here also.......
  </div>
</div>
</div>
</body>
</html>

Any guesses??

Neernay
  • 379
  • 1
  • 4
  • 13

1 Answers1

0

you are probably using the following:

highlighter.highlightSelection();
rangy.serializeSelection();  

if you are running highlightSelection before serializing it will not work. this is because highlighting is actually wrapping text in tags which means that DOM is manipulated.

deserializing on original DOM will obviously won't work. try change the order of commands so you will serialize first and only then use highlight.

Correct Order:

rangy.serializeSelection();    
highlighter.highlightSelection();
Ori Price
  • 3,593
  • 2
  • 22
  • 37