title: Drupal Adding Span inside A tags in Nice Menus
body: <p>I am trying to add drop down menus to a drupal theme which uses text sliding door CSS rounding. </p>
  
  <p>The current version uses a primary links injection of the span into the a tags, which works fine. But doesn't support drop down menus.</p>
  
  <p>Working code:</p>
  
  <pre><code>&lt;?php print theme('links', $primary_links, array('class' =&gt; 'links primary-links')) ?&gt;
  </code></pre>
  
  <p>In the template with a template.php file addition:</p>
  
  <pre><code>&lt;?php
  // function for injecting spans inside anchors which we need for the theme's rounded corner background images
  function strands_guybrush_links($links, $attributes =  array('class' =&gt; 'links')) {
    $output = '';
    if (count($links) &gt; 0) {
      $output = '&lt;ul'. drupal_attributes($attributes) .'&gt;';
  
      $num_links = count($links);
      $i = 1;
  
      foreach ($links as $key =&gt; $link) {
        $class = $key;
  
        // Add first, last and active classes to the list of links to help out themers.
        if ($i == 1) {
          $class .= ' first';
        }
        if ($i == $num_links) {
          $class .= ' last';
        }
        if (isset($link['href']) &amp;&amp; ($link['href'] == $_GET['q'] || ($link['href'] == '&lt;front&gt;' &amp;&amp; drupal_is_front_page()))) {
          $class .= ' active';
        }
        $output .= '&lt;li'. drupal_attributes(array('class' =&gt; $class)) .'&gt;';
  
        if (isset($link['href'])) {
          $link['title'] = '&lt;span class="link"&gt;' . check_plain($link['title']) . '&lt;/span&gt;';
          $link['html'] = TRUE;      
          // Pass in $link as $options, they share the same keys.
          $output .= l($link['title'], $link['href'], $link);        
        }
        else if (!empty($link['title'])) {
          // Some links are actually not links, but we wrap these in &lt;span&gt; for adding title and class attributes
          if (empty($link['html'])) {
            $link['title'] = check_plain($link['title']);
          }
          $span_attributes = '';
          if (isset($link['attributes'])) {
            $span_attributes = drupal_attributes($link['attributes']);
          }
          $output .= '&lt;span'. $span_attributes .'&gt;'. $link['title'] .'&lt;/span&gt;';
        }
  
        $i++;
        $output .= "&lt;/li&gt;\n";
      }
  
      $output .= '&lt;/ul&gt;';
    }
    return $output;
  }
  ?&gt;
  </code></pre>
  
  <p>So I have added the <a href="http://drupal.org/project/nice_menus" rel="nofollow noreferrer">Nice Menu module</a> which works well and allows the drop down menu functions for my navigation which is now addressed from the template using:</p>
  
  <pre><code>&lt;?php   print theme_nice_menu_primary_links() ?&gt;
  </code></pre>
  
  <p>The issue is that the a tags need to have spans inside to allow for the selected state markup. I have tried every angle I could find to edit the drupal function menu_item_link which is used by nice menus to build the links. </p>
  
  <p>E.g. I looked at the drupal forum for two days and no joy. </p>
  
  <p>The lines in the module that build the links are:</p>
  
  <pre><code>function theme_nice_menu_build($menu) {
    $output = '';
    // Find the active trail and pull out the menus ids.
  
    menu_set_active_menu_name('primary-links');
    $trail = menu_get_active_trail('primary-links');
    foreach ($trail as $item) {
      $trail_ids[] = $item['mlid'];
    }
  
    foreach ($menu as $menu_item) {
      $mlid = $menu_item['link']['mlid'];
      // Check to see if it is a visible menu item.
      if ($menu_item['link']['hidden'] == 0) {
        // Build class name based on menu path
        // e.g. to give each menu item individual style.
        // Strip funny symbols.
        $clean_path = str_replace(array('http://', '&lt;', '&gt;', '&amp;', '=', '?', ':'), '', $menu_item['link']['href']);
        // Convert slashes to dashes.
        $clean_path = str_replace('/', '-', $clean_path);
        $class = 'menu-path-'. $clean_path;
        $class .= in_array($mlid, $trail_ids) ? ' active' : '';  
        // If it has children build a nice little tree under it.
        if ((!empty($menu_item['link']['has_children'])) &amp;&amp; (!empty($menu_item['below']))) {
          // Keep passing children into the function 'til we get them all.
          $children = theme('nice_menu_build', $menu_item['below']);
          // Set the class to parent only of children are displayed.
          $class .= $children ? ' menuparent ' : '';
          // Add an expanded class for items in the menu trail.
          $output .= '&lt;li id="menu-'. $mlid .'" class="'. $class .'"&gt;'. theme('menu_item_link', $menu_item['link']);
          // Build the child UL only if children are displayed for the user.
          if ($children) {
            $output .= '&lt;ul&gt;';
            $output .= $children;
            $output .= "&lt;/ul&gt;\n";
          }  
          $output .= "&lt;/li&gt;\n";
        }  
        else {
          $output .= '&lt;li id="menu-'. $mlid .'" class="'. $class .'"&gt;'. theme('menu_item_link', $menu_item['link']) .'&lt;/li&gt;'."\n";
        }  
      }  
    }
    return $output;
  }
  </code></pre>
  
  <p>As you can see the $output uses menu_item_link to parse the array into links and to added the class of active to the selected navigation link. </p>
  
  <p>The question is how do I add a span inside the a tags OR how do I wrap the a tags with a span that has the active class to style the sliding door links? </p>