I'm working on a html tool to study ancient latin language.
There is one exercise where student have to click on some single word,
in which there is a div
with a piece of latin:
<div class="clickable">
Cum a Romanis copiis vincĭtur măr, Gallia terra fera est.
Regionis incŏlae terram non colunt, autem sagittis feras necant et postea eas vorant.
Etiam a_femĭnis vita agrestis agĭtur,
miseras vestes induunt et cum familiā in parvis casis vivunt.
Vita secūra nimiaeque divitiae a Gallis contemnuntur.
Gallorum civitates acrĭter pugnant et ab inimicis copiis timentur.
Galli densis silvis defenduntur, tamen Roma feram Galliam capit.
</div>
In my javascript I wrap all single words into a <span>
with a regex, and I apply some actions.
var words = $('div.clickable');
words.html(function(index, oldHtml) {
var myText = oldHtml.replace(/\b(\w+?)\b/g, '<span class="word">$1</span>')
return myText;
}).click(function(event) {
if(!$(event.target).hasClass("word"))return;
alert($(event.target).text());
}
The problem is that the words that contains ĭ, ŏ, ā
, are not wrapped correctly, but are divided in correspondence of these characters.
How I can match correctly this class of words?