+1  A: 

The Highlighter does not returns that information when you use the methods getBestFragment. Behind the scene the Highlighter uses the TokenGroup class to get the start and the end index of each fragment. You could probably use that class.

Pascal Dimassimo
actually, that hint was quite helpful. sorry for a really late response. Thanks
Umer
A: 

I did just that a few months ago. You have to build custom Formatter and Encoder. Basically, inside the highlighter, the formatter processes the tokens chosen for highlighting, while the encoder processes the rest of the tokens. In your case, you need the encoder to emit the empty each time it is called, and the formatter to emit the start index and the end index. They are indeed stored in the TokenGroup of the highlighted parts. Your highlighter should be constructed using these custom formatter and encoder.

Yuval F
can you please post a code sample
Midhat