Index: tinymce.inc
===================================================================
--- tinymce.inc	(revision 25994)
+++ tinymce.inc	(working copy)
@@ -128,7 +128,21 @@ function wysiwyg_tinymce_settings($editor, $config
     // TinyMCE's URL conversion magic breaks Drupal modules that use a special
     // syntax for paths. This makes 'relative_urls' obsolete.
     'convert_urls' => FALSE,
+    
   );
+  
+  /*
+   * Build list of valid elements to match configured buttons.
+   * 
+   * I want the cleanup button to remove all elements that I haven't enabled by adding buttons for them.
+   * 
+   * Maybe other people want a short list of buttons but don't want cleanup to be so restrictive - so I giess this should really be optional
+   */
+  $valid =   $config['block_formats'];
+  $valid = preg_replace('/[^0-9-A-Za-z,]/', '', $valid);
+  $valid = explode(',', $config['block_formats']);
+
+  $init['valid_elements']  = $valid;//_elements;
   if (isset($config['apply_source_formatting'])) {
     $init['apply_source_formatting'] = $config['apply_source_formatting'];
   }
@@ -213,6 +227,10 @@ function wysiwyg_tinymce_settings($editor, $config
           if (!empty($plugins[$plugin]['extended_valid_elements'])) {
             $init['extended_valid_elements'] = array_merge($init['extended_valid_elements'], $plugins[$plugin]['extended_valid_elements']);
           }
+          // Allow plugins to add valid html elements - per button
+          if (!empty($plugins[$plugin]['button_extended_valid_elements'][$button])) {
+            $init['extended_valid_elements'] = array_merge($init['extended_valid_elements'], $plugins[$plugin]['button_extended_valid_elements'][$button]);
+          }
           // Allow plugins to add or override global configuration settings.
           if (!empty($plugins[$plugin]['options'])) {
             $init = array_merge($init, $plugins[$plugin]['options']);
@@ -270,7 +288,6 @@ function wysiwyg_tinymce_settings($editor, $config
       $init[$key] = implode(',', $init[$key]);
     }
   }
-
   return $init;
 }
 
@@ -392,6 +409,35 @@ function wysiwyg_tinymce_plugins($editor) {
         'removeformat' => t('Remove format'),
         'charmap' => t('Character map'),
         'help' => t('Help')),
+  /*
+   * Which buttons add which elemments
+   * This isn't complete - I only want bold italic and H3 !
+   * I've added the others which are obvious - but not all
+   */
+        'button_extended_valid_elements' => array(
+                     'bold' => array('b'),
+                     'italic' => array('i'),
+                     'underline' => array('u'),
+                     'strikethrough' => array('strike'),
+                     'justifyleft' => array('align'),
+                     'justifycenter' => array('align'),
+                     'justifyright' => array('align'),
+                     'bullist' => array('ul,li'),
+                     'numlist' => array('ol,li'),
+                     'outdent' => array(''),
+                     'indent' => array(''),
+                     'link' => array('a'), 
+//                     'anchor' => array(''),
+                     'image' => array('img'),
+//                     'forecolor' => array('color'), 
+//                     'backcolor' => array('background-color'),
+                     'sup' => array('sup'), 
+                     'sub' => array('sub'),
+                     'blockquote' => array('blockquote'), 
+                     'code' => array('code'),
+                     'hr' => array('hr'),
+  
+         ),
       'internal' => TRUE,
     ),
     'advhr' => array(
@@ -457,7 +503,10 @@ function wysiwyg_tinymce_plugins($editor) {
     'font' => array(
       'path' => $editor['library path'] .'/plugins/font',
       'buttons' => array('formatselect' => t('HTML block format'), 'fontselect' => t('Font'), 'fontsizeselect' => t('Font size'), 'styleselect' => t('Font style')),
-      'extended_valid_elements' => array('font[face|size|color|style],span[class|align|style]'),
+      'button_extended_valid_elements' => array('fontselect' => array('font[face|size|color|style],span[class|align|style]'),
+                                            'fontsizeselect' => array('font[size],span[class|style]'),
+                                               'styleselect' => array('font[face|color|style],span[class|align|style]'),
+                                                ),
       'url' => 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/font',
       'internal' => TRUE,
     ),
