--- glossary/glossary.module	2009-01-20 01:55:36.000000000 +0000
+++ glossary/glossary_new.module	2009-08-29 13:44:45.000000000 +0100
@@ -679,7 +679,6 @@ function _glossary_insertlink($format, &
         $synonym = drupal_strtolower($synonym);
       }
       $offset=0;
-      $first_match_found = FALSE;
       while (($offset = $findfunc($searchtext, $synonym, $offset)) !== FALSE) {
         $len = drupal_strlen($synonym);
         $match = drupal_substr($text, $offset, $len);
@@ -687,17 +686,9 @@ function _glossary_insertlink($format, &
         if (!isset($events[$offset]) || drupal_strlen($events[$offset]['match']) < drupal_strlen($match)) {
           // Get synonym with case as in text.
           $events[$offset] = array('type' => 'match', 'which' => $i, 'match' => $match);
-          if (!$replaceall) {
-            $first_match_found = TRUE;
-            break;
-          }
         }
         $offset += $len;
       }
-      //TODO: remove this if we want different synonyms of the same term to be matched independently as 'first matches'
-      if ($first_match_found && !$replaceall) {
-        break;
-      }
     }
   }
 
@@ -705,6 +696,7 @@ function _glossary_insertlink($format, &
 
   $newtext = '';
   $parsed = 0; // Text was parsed from chars 0 to $parsed (exclusive).
+  $eventsdone = array();
 
   foreach ($events as $place => $event) {
     // Skip events inside blocking tag (they're already copied as is).
@@ -760,8 +752,14 @@ function _glossary_insertlink($format, &
             break;
       }
       if ($proper_match) {
+      // Only replace first match, check for current event in those already done
+        if ((!$replaceall) && (in_array($event['which'], $eventsdone))) {
+          continue;
+          }
         $newtext .= $terms[$event['which']]['ins_before'] . $event['match'] . $terms[$event['which']]['ins_after'];
         $parsed += $matchlen;
+        // Keep track of processed events
+        $eventsdone[] = $event['which'];
       }
     }
   }
