Index: tableofcontents.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/tableofcontents/tableofcontents.module,v
retrieving revision 1.2.4.2.2.2.2.12
diff -u -r1.2.4.2.2.2.2.12 tableofcontents.module
--- tableofcontents.module	22 Oct 2008 21:19:18 -0000	1.2.4.2.2.2.2.12
+++ tableofcontents.module	30 Oct 2008 16:42:30 -0000
@@ -248,6 +248,13 @@
     '#default_value' => variable_get('tableofcontents_allow_override_' . $format, TRUE),
   );
   
+  $form['tableofcontents']['tableofcontents_remove_teaser_' . $format] = array(
+    '#title' => t('Remove Table of Contents tags from teasers'),
+    '#type' => 'checkbox',
+    '#default_value' => variable_get("tableofcontents_remove_teaser_$format", TRUE),
+    '#description' => t('If this setting is changed, each node may need to be re-edited to reflect the new setting. This will also cause every node with a Table of Contents to have a split teaser. If you have many nodes, the <a href="@retease">Retease module</a> can help to do this automatically.', array('@retease' => url('http://drupal.org/project/retease'))),
+  );
+  
   $form['tableofcontents']['tableofcontents_title_' . $format] = array(
     '#title' => t('Table of Contents Title'),
     '#type' => 'textfield',
@@ -323,6 +330,32 @@
         cache_clear_all($cid, 'cache_filter');
       }
       break;
+      
+    case 'presave':
+      if (variable_get("tableofcontents_remove_teaser_$node->format", TRUE)) {
+        $filters = filter_list_format($node->format);
+        if (isset($filters['tableofcontents/0'])) {
+          if ($node->teaser && ($node->teaser != $new_teaser = preg_replace('!<\!-- ?tableofcontents(.*)-->!', '', $node->teaser))) {
+            if (strpos($node->body, '<!--break-->') > 0) {
+              // We've specfied the split, but the summary is shown in the full
+              // view. So, we now have to convert it so that the summary is
+              // hidden.
+              $node->body = preg_replace('/(.*)<!--break-->/s', '<!--break-->$1', $node->body);
+              drupal_set_message(t("Your summary was split from the body as site settings don't allow Table of Contents in summaries."));
+            }
+            else {
+              // This is the case where no specific break or summary was
+              // specified, so now it becomes a split teaser.
+              $node->body = '<!--break-->' . $node->body;
+              drupal_set_message(t("A split summary was automatically created as site settings don't allow Table of Contents in summaries."));
+            }
+            
+            // Remove toc from teasers.
+            $node->teaser = $new_teaser;
+          }
+        }
+      }
+      break;
   }
 }
 
