Hi everyone,

I'm trying to write a filter module to automatically add the node path for page anchor links:

<a href="#goto777">Section 777</a>
...
...
<a name="goto777">

Unfortunately... I don't know why my filter module isn't working. I can't even get it to do a simple word replace (eg. the -> THE). I think I named the functions right and i'm following the filter example. Not sure whats wrong.

Do you know if I should be calling this module manually? Thanks for your help.
- Anthony

function fanchor_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      // This description is shown in the listing at admin/modules.
      return t('FIX: This completes the URL so that page anchors work.');
  }



function fanchor_filter($op, $delta = 0, $format = -1, $text = '') { 
  switch ($op) { 
    case 'list': 
      return array(0 => t('Code filter')); 

    case 'description': 
      return t('FIX: This completes the URL so that page anchors work.'); 

    case 'prepare': 
      return $text; 

    case 'process': 
	// $pattern = '/(<[Aa]\s[^<>]*[hH][rR][eE][fF]\s*=\s*[\'"]?)#/';
	// $text = preg_replace($pattern, "\\1$_SERVER[REQUEST_URI]#", $text);
	$text = preg_replace('/(href="?)#/i', '\1'. $_REQUEST['q'] .'#', $text);
	return $text; 

    default: 
      return $text; 
  } 
}

<[

Comments

M.J. Taylor’s picture

Update for any others trying to fix this:

Fixing page anchors problems for prior 4.7 versions are a much larger problem than expected. Please see the thread http://drupal.org/node/13148 (last 20-30 comments) for a fuller explanation. Version 4.7 will exhibit the expected behavior.