--- footnotes.module	2008-07-14 16:08:13.000000000 -0400
+++ footnotes-alt.module	2008-07-17 17:12:31.000000000 -0400
@@ -119,7 +119,7 @@ function footnotes_filter($op, $delta = 
           // A closing tag may sometimes be missing when we are processing a teaser
           // and it has been cut in the middle of the footnote. http://drupal.org/node/253326
           $foo = array();
-          $open_tags = preg_match_all("|<fn>|", $text, $foo);
+          $open_tags = preg_match_all("|<fn([^>]*)>|", $text, $foo);
           $close_tags = preg_match_all("|</fn>|", $text, $foo);
           if($open_tags == $close_tags + 1) {
             $text = $text . '</fn>';
@@ -128,7 +128,7 @@ function footnotes_filter($op, $delta = 
             trigger_error(t("You have unclosed fn tags. This is invalid and will produce unpredictable results."));
           }
 
-          $pattern = '|<fn>(.*?)</fn>|s';
+          $pattern = '|<fn([^>]*)>(.*?)</fn>|s';
           $text = preg_replace_callback($pattern , '_footnotes_replace_callback', $text);
 
           // Replace tag <footnotes> with the list of footnotes.
@@ -213,15 +213,16 @@ function _footnotes_replace_callback( $m
   static $n = 0;
   static $store_matches = array();
   $str = '';
-
+  
   if( $op == 'output footer' ) {
-    if( $n > 0 ) {
+    if (count($store_matches) > 0) {
       $str = '<ol class="footnotes">';
-      for( $m = 1; $m <= $n; $m++ ){
-        $text = $store_matches[ $m - 1 ][0];
-        $randstr = $store_matches[ $m - 1 ][1];
-        $str .= '<li><a class="footnote" name="footnote' . $m . '_' . $randstr .
-                '" href="#footnoteref' . $m . '_' . $randstr . '">' . $m . '.</a> ';
+      // loop through the stored footnotes
+      foreach ($store_matches as $fn_attr) {
+        list($text,$label,$randstr) = $fn_attr; 
+        $str .= '<li><a class="footnote" name="footnote' . $label . '_' .
+                $randstr .'" href="#footnoteref' . $label . '_' . 
+                $randstr . '">' . $label . '.</a> ';
         $str .= $text . "</li>\n";
       }
       $str .= "</ol>\n";
@@ -236,18 +237,44 @@ function _footnotes_replace_callback( $m
   //Random string used to ensure footnote id's are unique, even 
   //when contents of multiple nodes reside on same page. (fixes http://drupal.org/node/194558)
   $randstr = _footnotes_helper_randstr();
+  
+  $label = '';
+  //did the pattern match anything in the <fn> tag?
+  if ($matches[1]) {
+    // see if label can parsed, either well-formed in quotes eg <fn value="3">
+  	if (preg_match('|value=["\'](.*?)["\']|',$matches[1],$label_match)) {
+      $label = $label_match[1];
+    // or without quotes eg <fn value=8>  
+  	} elseif (preg_match('|value=(\S*)|',$matches[1],$label_match)) {
+      $label = $label_match[1];
+  	} 
+  } 
+  
+  if ($label) {
+    // A label was found. If it is numeric, record it in $n so further notes 
+    // can increment from there.
+    if (is_numeric($label)) {
+      $n = $label;
+    }
+  } else {
+    // No label, either a plain <fn> or unparsable attributes. Increment the 
+    // footnote counter, set label equal to it.
+    $n++;
+    $label = $n;
+  }
+  
+  // store the footnote text, the footnote label, and randstr 
+  array_push( $store_matches, array( $matches[2], $label, $randstr) );
 
-  array_push( $store_matches, array( $matches[1], $randstr ) );
-  $n++;
   $allowed_tags = array();
-  $title = filter_xss($matches[1], $allowed_tags);
+  $title = filter_xss($matches[2], $allowed_tags);
   //html attribute cannot contain quotes
   $title = str_replace('"', "&quot;", $title);
   //remove newlines. Browsers don't support them anyway and they'll confuse line break converter in filter.module
   $title = str_replace("\n", " ", $title);
   $title = str_replace("\r", "", $title);
-  return '<a class="see_footnote" id="footnoteref' . $n . '_' . $randstr .
-         '" title="' . $title . '" href="#footnote' . $n . '_' . $randstr . '">' . $n . '</a>';
+  return '<a class="see_footnote" id="footnoteref' . $label . '_' . $randstr .
+         '" title="' . $title . '" href="#footnote' . $label . '_' . $randstr . '">' . $label . '</a>';
 }
 
 
