I want to implement a kind of glossary in a speed template (using Javascript). The following is an example of use:
- there are a large number of elements, the description of which may contain links to predefined terms
- there is a list of terms that are defined β allGlossary
- I want to automatically find and tag all the items in the allGlossary list that appear in the description of all my items.
Example:
allGlossary = ["GUI", "RBG", "fine", "Color Range"]
Description of the item . An interface (GUI) should be generated using only a specific range of RGB colors.
After running the script, I expect the description to look like this: "An interface ( GUI ) should be generated using only the predefined RGB color range ."
NOTE : even if the message βfineβ appears in the description (de fine d), it should not be marked.
I thought about dividing the description of each element into words, but then I skip all the dictionaries containing more than one word. My current idea is to search for every item in the list in each of the descriptions, but I have the following limitations:
- I need to find only matches for exact elements in 2 lists (one and several words)
- The search must be case insensitive.
- Items found can be at the beginning or end of the text and separated by various characters: space, comma, period, parentheses, brackets, etc.
I have the following code that works, but is not case sensitive:
#set($desc = $item.description)
Can anyone help in creating this case insensitive? Or does anyone have a better way to do this?
Thanks!
UPDATE: based on the answer below, I tried to do the following on the Velocity template page:
#set($allGlossary = ["GUI","RGB","fine","Color Range"]) #set($itemDescription = "The interface (GUI) shall be generated using only a pre-defined RGB color range.") <script type="text/javascript"> var allGlossary = new Array(); var itemDescription = "$itemDescription"; </script> #foreach($a in $allGlossary) <script type="text/javascript"> allGlossary.push("$a"); console.log(allGlossary); </script> #end##foreach <script type="text/javascript"> console.log(allGlossary[0]); </script>
The problem is that if I try to display the entire allGlossary array, it contains the correct elements. As soon as I try to display only one of them (as in the example), I get the error message Uncaught SyntaxError: missing ) after argument list .