Index: includes/linodef-filter.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/linodef/includes/linodef-filter.inc,v
retrieving revision 1.1.2.12
diff -u -r1.1.2.12 linodef-filter.inc
--- includes/linodef-filter.inc	14 Aug 2009 04:12:54 -0000	1.1.2.12
+++ includes/linodef-filter.inc	2 Nov 2009 14:25:42 -0000
@@ -402,23 +403,24 @@
 			}
 			// Set nolink automatically for content with HTML block level elements.
 			if (variable_get('linodef_option_auto_nolink', TRUE) && !$options['nolink']) {
-				$html_block_element = array('<div>', '<p>', '<ol>', '<ul>', '<table>', '<h1>', '<h2>', '<h3>', '<dl>', '<pre>', '<h4>', '<h5>', '<h6>', '<address>', '<blockquote>', '<del>', '<fieldset>', '<form>', '<hr>', '<ins>', '<noscript>');
-				foreach ($html_block_element as $value) {
-					if (strpos($output, $value)) {
-						$options['nolink'] = TRUE;
-						break;
-					}
-				}
+				$options['nolink'] = _linodef_filter_option_nolink_auto($output);
 			}
 			// Finalize node processing.
 			if (isset($options['nolink'])) {
+				if (isset($options['attributes'])) {
+					$output = _linodef_filter_option_attributes($output, $options['attributes']);
+				}
 				return $output;
 			}
 			else {
 				// Thx @AjK for your module review on applying for cvs access. Should become themeable.
 				// Can cause bad HTML if field item contains html block elements. But Linodef shouldn't interfere with the content/formatting of the field.
 				$class = $fieldname ? 'linodef linodef_field linodef_field_'. $fieldname : 'linodef linodef_node linodef_node_'. $node->nid;
-				return l($output, 'node/'. $node->nid, array('html' => true, 'attributes' => array('title' => t('Node') .' '. $node->nid .': '. $node->title, 'class' => $class)));
+				$attributes = array('title' => t('Node') .' '. $node->nid .': '. $node->title, 'class' => $class);
+				if (isset($options['attributes'])) {
+					$attributes += _linodef_filter_option_attributes_str2array($options['attributes']);
+				}
+				return l($output, 'node/'. $node->nid, array('html' => true, 'attributes' => $attributes));
 			}
 		}
 		else {
@@ -445,7 +447,13 @@
 	if (module_exists('taxonomy')) {
 		if ($tid && $term = taxonomy_get_term($tid)) {
 			if (isset($options['nolink'])) {
-				return check_plain($term->name);
+				if (isset($options['attributes'])) {
+					$output = '<span ' . $options['attributes'] . '>' . check_plain($term->name) . '</span>';
+					return $output;
+				}
+				else {
+					return check_plain($term->name);
+				}
 			}
 			$termlink = taxonomy_term_path($term);
 			if (isset($options['override'])) {
@@ -454,7 +462,11 @@
 			else {
 				$output = $term->name;
 			}
-			return l($output, $termlink, array('attributes' => array('title' => t('Shows a teaser list of nodes using term !term', array('!term' => $term->name)), 'class' => 'linodef linodef_term linodef_term_'. $term->name)));
+			$attributes = array('title' => t('Shows a teaser list of nodes using term !term', array('!term' => $term->name)), 'class' => 'linodef linodef_term linodef_term_'. $term->name);
+			if (isset($options['attributes'])) {
+				$attributes += _linodef_filter_option_attributes_str2array($options['attributes']);
+			}
+			return l($output, $termlink, array('attributes' => $attributes));
 		}
 		else {
 			return linodef_message(array('error' => array('term' => $tid, 'type' => 'not found')));
@@ -497,13 +509,7 @@
 			}
 			// Set nolink automatically for content with HTML block level elements.
 			if (variable_get('linodef_option_auto_nolink', TRUE) && !$options['nolink']) {
-				$html_block_element = array('<div>', '<p>', '<ol>', '<ul>', '<table>', '<h1>', '<h2>', '<h3>', '<dl>', '<pre>', '<h4>', '<h5>', '<h6>', '<address>', '<blockquote>', '<del>', '<fieldset>', '<form>', '<hr>', '<ins>', '<noscript>');
-				foreach ($html_block_element as $value) {
-					if (strpos($output, $value)) {
-						$options['nolink'] = TRUE;
-						break;
-					}
-				}
+				$options['nolink'] = _linodef_filter_option_nolink_auto($output);
 			}
 			// Debug: print('(' . __FUNCTION__ . ') ');print('View id: <b>' . $viewid . '</b> Name: <b>' . $view->name . '</b> Display: <b>' . $display . '</b> Display path: <b>' . $view->display[$display]->display_options['path'] . '</b><pre>');print_r($options);print('</pre><hr />');
 			// Create link if available/needed.
@@ -512,9 +518,16 @@
 				if ($url_args) {
 					$path .= '/'. $url_args;
 				}
-				return l($output, $view->get_url($args, $path), array('html' => true, 'attributes' => array('title' => t('Show !view', array('!view' => $output)), 'class' => 'linodef linodef_view linodef_view_'. $output)));
+				$attributes = array('title' => t('Show !view', array('!view' => $output)), 'class' => 'linodef linodef_view linodef_view_'. $output);
+				if (isset($options['attributes'])) {
+					$attributes += _linodef_filter_option_attributes_str2array($options['attributes']);
+				}
+				return l($output, $view->get_url($args, $path), array('html' => true, 'attributes' => $attributes));
 			}
 			else {
+				if (isset($options['attributes'])) {
+					$output = _linodef_filter_option_attributes($output, $options['attributes']);
+				}
 				return $output;
 			}
 		}
@@ -555,3 +568,80 @@
 	}
 	return $output . $message;
 }
+
+/**
+ * Returns TRUE when a HTML block element is detected in $text.
+ */
+function _linodef_filter_option_nolink_auto($text) {
+	$html_block_elements = array('<div', '<p', '<ol', '<ul', '<table', '<h1', '<h2', '<h3', '<dl', '<pre', '<h4', '<h5', '<h6', '<address', '<blockquote', '<fieldset', '<form', '<hr', '<noscript');
+	foreach ($html_block_elements as $value) {
+		if (strpos($text, $value) !== FALSE) {
+			return TRUE;
+			break;
+		}
+	}
+	return NULL;
+}
+
+/**
+ * Applies attributes to tags.
+ */
+function _linodef_filter_option_attributes($text, $attributes_string) {
+	$html_block_elements = array('<div', '<p', '<ol', '<ul', '<table', '<h1', '<h2', '<h3', '<dl', '<pre', '<h4', '<h5', '<h6', '<address', '<blockquote', '<fieldset', '<form', '<hr', '<noscript');
+	$html_inline_elements = array('<a', '<span', '<img', '<strong', '<em', '<code', '<del', '<ins', '<cite', '<object', '<sub', '<sup', '<bdo', '<map', '<area', '<param', '<q', '<kbd', '<var', '<acronym', '<abbr');
+	$html_elements = $html_block_elements + $html_inline_elements;
+	foreach ($html_elements as $value) {
+		if (substr($text, 0, strlen($value)) == $value) {
+			$text = substr_replace($text, $value . ' ' . $attributes_string, 0, strlen($value));
+			$option_attributes_done = TRUE;
+			break;
+		}
+	}
+	// Use a div element if content contains block elements.
+	if (!$option_attributes_done) {
+		foreach ($html_block_elements as $value) {
+			if (strpos($text, $value) !== FALSE) {
+				$text = '<div ' . $attributes_string . '>' . $text . '</div>';
+				$option_attributes_done = TRUE;
+				break;
+			}
+		}
+	}
+	if (!$option_attributes_done) {
+		$text = '<span ' . $attributes_string . '>' . $text . '</span>';
+	}
+	return $text;
+}
+
+/**
+ * Str2array for option attributes.
+ *
+ * @param string $attributes_string
+ * @return
+ *   Returns an array with attributes to use with l().
+ */
+function _linodef_filter_option_attributes_str2array($attributes_string) {
+	// Transform space inside attribute values.
+	$attributes_string = preg_replace_callback("@(='[^']*')@", create_function('$treffer', 'return str_replace(" ", "\xf4\x80\x81\x8c", $treffer[0]);'), $attributes_string);
+	// Several attributes separated by space.
+	if (strpos($attributes_string, ' ') !== FALSE) {
+		$attributes_array = explode(' ', $attributes_string);
+		foreach ($attributes_array as $value) {
+			if (($pos = strpos($value, '=')) !== FALSE) {
+				$attributes_key = substr($value, 0, $pos);
+				$value = substr($value, -(strlen($value)-$pos-1));
+			}
+			$attributes[$attributes_key] = $value;
+		}
+	}
+	else {
+		if (($pos = strpos($attributes_string, '=')) !== FALSE) {
+			$attributes_key = substr($attributes_string, 0, $pos);
+			$value = substr($attributes_string, -(strlen($attributes_string)-$pos-1));
+		}
+		$attributes[$attributes_key] = $value;
+	}
+	// Replace ' ' back and remove '' from value.
+	foreach ($attributes as &$value) {
+		if (is_string($value)) {
+			$value = str_replace("\xf4\x80\x81\x8c", " ", $value);
+			$value = str_replace("'", "", $value);
+		}
+	}
+	unset($value);
+	// Debug: print($attributes_string . '<pre>');print_r($attributes);print('</pre><br />');
+	return $attributes;
+}
+
Index: linodef.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/linodef/linodef.module,v
retrieving revision 1.1.2.9
diff -u -r1.1.2.9 linodef.module
--- linodef.module	14 Aug 2009 04:12:54 -0000	1.1.2.9
+++ linodef.module	2 Nov 2009 12:25:35 -0000
@@ -250,6 +253,14 @@
 					'#description' => t('All characters except %char1 and %char2 are allowed.', array('%char1' => ']', '%char2' => '"'))
 				)
 			),
+			'attributes' => array(
+				'#title' => t('HTML attributes'),
+				'#types' => $this->valid_types,
+				'#description' => t('Append HTML attributes to the tag.'),
+				'value' => array(
+					'#description' => t('Separate attributes as usual by space, e.g. %example.', array('%example' => 'class=\'highlighted\' name=\'anchor\' style=\'color: red; text-decoration: underline;\''))
+				)
+			),
 			'formatter' => array(
 				'#title' => t('CCK formatter'),
 				'#types' => array('node' => TRUE),