When you set, eg. h1, h2 and h3 as blocking html elements and you have a title / subtitle in your node with a corresponding term, the glossary item will not be linked after the blocking match.

So it isn't linked in the title: that's correct
But the next occurance isn't linked either: not correct, because that's the first matching element, following the conditions.

How can this be solved?

in glossary.module line 636

      $first_match_found = FALSE;
      while (($offset = $findfunc($searchtext, $synonym, $offset)) !== FALSE) {
        $len = drupal_strlen($synonym);
        $match = drupal_substr($text, $offset, $len);
        // Only longer matches override shorter ones.
        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; // true even if the element occured in a blocked html item
            break;
          }
        }
        $offset += $len;
      }

How can we test if the term is within a blocked html element?

TIA,
Fossie

Comments

elfjohnson’s picture

I fixed this by adding some code to glossary.module -- this probably isn't the most efficient way to to it, but it works and involves minimal code changes:

In function _glossary_insertlink , initialize $skiparray:
$skiparray = array(); //ELFJ list of open and close offsets to be compared for first_match fix
then insert the bolded text into the below loop.

foreach ($open_tags as $i => $tag) {
$offset=0;
while (($offset = $findtagfunc($searchtext, $tag, $offset)) !== FALSE) {
// Longer tags will override shorter '<' on the same offset.
$events[$offset] = array('type' => 'open', 'which' => $i);
$offset += drupal_strlen($tag);
$skiparray[$offset] = array('which' => $i); //ELFJ stores the location and what tag is opened
}
}

In the next loop down add the bold code

while (($offset = $findfunc($searchtext, $synonym, $offset)) !== FALSE) {
$len = drupal_strlen($synonym);
$match = drupal_substr($text, $offset, $len);
// Only longer matches override shorter ones.
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);
$skipmatch = FALSE; //ELFJ
foreach ($skiparray as $place => $toskip) { //ELFJ+foreach check if in skipped text
if ($offset > $place){
if ($offset < $findtagfunc($searchtext, $close_tags[$toskip['which']], $place)){
$skipmatch = TRUE;
break;
}
}

}
if ((!$skipmatch) && (!$replaceall)) {
$first_match_found = TRUE;
break;
}
}

nancydru’s picture

Issue summary: View changes
Status: Active » Closed (outdated)