[Xerte-dev] Glossary

Tom Reijnders reijnders at tor.nl
Fri Oct 5 08:33:52 BST 2012


Julain,

I suppose this is one for you:

I have a teacher that wants to create a kind of dictionary, so he's 
created a big glossary, and then for each letter a separate text page 
containing a list of the terms.

However, the terms are not all transformed into a link.
1. The regular expression doesn't like the sentence ending on a 
'newline', I've added '\r' to the set of characters that may 'end' a 
term in the RegExp of line 6662 (or the teacher has to add a space at 
the end of the term.

That still is not enough, it will only transform the first term to a 
link. I had to remove the \\b from the regexp. I tried to find a manual 
page to figure out what \\b means in RegExp, but I can't find it. Do you 
have any idea what the \\b is doing there?

For quick reference I needed to change this:

if (Glossary.enabled && highlight != false){
                 for (var i = 0; i<Glossary.terms.length; i++) {
                     //new code with regexp
                     var re = new RegExp('\\b(' + Glossary.terms[i] + 
')([.,!? -])', 'gi');
                     myText = myText.replace(re, '<font color = 
"'+STYLES.glossaryColour+'"><a class="glossary" href = 
"asfunction:_root.engine.rootIcon.showGlosTerm,'+i+'">$1</a></font>$2');
                 }
             }

into this:

if (Glossary.enabled && highlight != false){
                 for (var i = 0; i<Glossary.terms.length; i++) {
                     //new code with regexp
                     var re = new RegExp('(' + Glossary.terms[i] + 
')([.,!? -\n\r])', 'gi');
                     myText = myText.replace(re, '<font color = 
"'+STYLES.glossaryColour+'"><a class="glossary" href = 
"asfunction:_root.engine.rootIcon.showGlosTerm,'+i+'">$1</a></font>$2');
                 }
             }

-- 
--

Tom Reijnders
TOR Informatica
Chopinlaan 27
5242HM Rosmalen
Tel: 073 5226191
Fax: 073 5226196

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nottingham.ac.uk/pipermail/xerte-dev/attachments/20121005/f37d60c4/attachment.html>


More information about the Xerte-dev mailing list