Changeset 1398


Ignore:
Timestamp:
02/11/18 07:55:53 (18 months ago)
Author:
gogo
Message:

#1135 - Update SuperClean? to incorporate the UnFormat? functionality.

Location:
trunk/plugins/SuperClean
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/SuperClean/SuperClean.js

    r1348 r1398  
    4747  // filterFunction in the second format above is optional. 
    4848 
    49   'filters': { 'tidy': Xinha._lc('General tidy up and correction of some problems.', 'SuperClean'), 
    50                'word_clean': Xinha._lc('Clean bad HTML from Microsoft Word', 'SuperClean'),                
    51                'word': {label:Xinha._lc('Vigorously purge HTML from Microsoft Word', 'SuperClean'), checked:false}, 
    52                'remove_faces': Xinha._lc('Remove custom typefaces (font "styles").', 'SuperClean'), 
    53                'remove_sizes': Xinha._lc('Remove custom font sizes.', 'SuperClean'), 
    54                'remove_colors': Xinha._lc('Remove custom text colors.', 'SuperClean'), 
    55                'remove_lang': Xinha._lc('Remove lang attributes.', 'SuperClean'), 
     49  'filters': { 'tidy':          {label:Xinha._lc('General tidy up and correction of some problems.', 'SuperClean'), checked:true, fullonly: true}, 
     50               'word_clean':    {label:Xinha._lc('Clean bad HTML from Microsoft Word.', 'SuperClean'), checked:true, fullonly: true},               
     51               'word':          {label:Xinha._lc('Vigorously purge HTML from Microsoft Word.', 'SuperClean'), checked:false, fullonly: true}, 
     52               'remove_faces':  {label:Xinha._lc('Remove custom typefaces (font "styles").', 'SuperClean'),checked:true}, 
     53               'remove_sizes':  {label:Xinha._lc('Remove custom font sizes.', 'SuperClean'),checked:true}, 
     54               'remove_colors': {label:Xinha._lc('Remove custom text colors.', 'SuperClean'),checked:true}, 
     55               'remove_emphasis': {label:Xinha._lc('Remove emphasis and annotations.', 'SuperClean'), checked:true}, 
     56               'remove_sup_sub':  {label:Xinha._lc('Remove superscripts and subscripts.', 'SuperClean'), checked:false}, 
     57               'remove_alignment': {label:Xinha._lc('Remove alignment (left/right/justify).', 'SuperClean'),checked:true}, 
     58               'remove_all_css_classes': {label:Xinha._lc('Remove all classes (CSS).', 'SuperClean'), checked: false}, 
     59               'remove_all_css_styles':         {label:Xinha._lc('Remove all styles (CSS).', 'SuperClean'),checked:true}, 
     60               'remove_lang': {label:Xinha._lc('Remove lang attributes.', 'SuperClean'),checked:true}, 
    5661               'remove_fancy_quotes': {label:Xinha._lc('Replace directional quote marks with non-directional quote marks.', 'SuperClean'), checked:false}, 
    5762  //additional custom filters (defined in plugins/SuperClean/filters/word.js) 
    58                'paragraph':{label:Xinha._lc('Remove Paragraphs', 'SuperClean'), checked:false} 
     63               'paragraph':{label:Xinha._lc('Remove Paragraphs', 'SuperClean'), checked:false}, 
     64               'remove_all_tags': {label:Xinha._lc('Remove All HTML Tags'), checked:false } 
    5965             }, 
    6066  //if false all filters are applied, if true a dialog asks what filters should be used 
     
    6470SuperClean.filterFunctions = { }; 
    6571 
     72/** Helper function to strip tags from given html. 
     73 *  
     74 * @param string 
     75 * @param array|string An array pf tag names, or a tag name string 
     76 * @param bool         true == completely remove tag and contents, false == remove tag only 
     77 * @return string 
     78 */ 
     79 
     80SuperClean.stripTags = function(html, tagNames, completelyRemove) 
     81{ 
     82  if(typeof tagNames == 'string') 
     83  { 
     84    tagNames = [ tagNames ]; 
     85  } 
     86   
     87  for(var i = 0; i < tagNames.length; i++) 
     88  { 
     89    var tagName = tagNames[i]; 
     90    if(completelyRemove) 
     91    { 
     92      html = html.replace(new RegExp('<'+tagName+'( [^>]*)?>.*?</'+tagName+'( [^>]*)?>', 'gi'), ''); 
     93    } 
     94    else 
     95    { 
     96      html = html.replace(new RegExp('</?'+tagName+'( [^>]*)?>', 'gi'), ''); 
     97    } 
     98  } 
     99   
     100  return html; 
     101} 
     102 
     103SuperClean.stripAttributes = function(html, attributeNames) 
     104{ 
     105  if(typeof attributeNames == 'string') 
     106  { 
     107    attributeNames = [ attributeNames ]; 
     108  } 
     109   
     110  for(var i = 0; i < attributeNames.length; i++) 
     111  { 
     112    var attributeName = attributeNames[i]; 
     113     
     114    // @TODO - make this less likely to false-positive outside of tags 
     115    html = html.replace(new RegExp(' ('+attributeName+'="[^"]*"|'+attributeName+'=\'[^\']*\'|'+attributeName+'=[^ >]*)', 'gi'), ' ');     
     116  } 
     117   
     118  return html; 
     119} 
    66120 
    67121SuperClean.prototype.onGenerateOnce = function() 
     
    106160  for(var filter in this.editor.config.SuperClean.filters) 
    107161  { 
    108     if (/^(remove_colors|remove_sizes|remove_faces|remove_lang|word_clean|remove_fancy_quotes|tidy)$/.test(filter)) continue; //skip built-in functions 
     162    if (/^(remove_colors|remove_sizes|remove_faces|remove_lang|word_clean|remove_fancy_quotes|tidy|remove_emphasis|remove_sup_sub|remove_alignment|remove_all_css_classes|remove_all_css_styles|remove_all_tags)$/.test(filter)) continue; //skip built-in functions 
    109163     
    110164    if(!SuperClean.filterFunctions[filter]) 
  • trunk/plugins/SuperClean/dialog.html

    r1044 r1398  
    11<h1 id="[h1]"><l10n>Clean up HTML</l10n></h1> 
    2 <div style="margin-left: 10px;" id="[main]"> 
     2<div style="margin-left: 10px;margin-right:10px;" id="[main]"> 
    33    <l10n>Please select from the following cleaning options...</l10n> 
    44    <!--filters--> 
     5     
     6     
     7     
     8    <fieldset style="margin-top:10px;"> 
     9      <legend><l10n>Cleaning Scope</l10n></legend> 
     10      <select name="[scope]"> 
     11        <option value="full"><l10n>Clean Entire Editor Contents<l10n></option> 
     12        <option value="selection"><l10n>Clean Selection Only</l10n></option> 
     13      </select> 
     14      <p id="[note]"><l10n>^ - Items so marked operate on the entire editor contents regardless of this setting.</l10n></p> 
     15    </fieldset> 
    516</div> 
    617 
  • trunk/plugins/SuperClean/pluginMethods.js

    r1199 r1398  
    1818 
    1919    if(opts.word_clean) editor._wordClean(); 
    20     var D = editor.getEditorContent(); 
     20     
     21    var D; 
     22     
     23    if(opts['scope'].value == 'selection') 
     24    { 
     25      D = editor.getSelectedHTML(); 
     26    } 
     27    else 
     28    { 
     29      D = editor.getEditorContent(); 
     30    } 
    2131 
    2232    for(var filter in editor.config.SuperClean.filters) 
    2333    { 
    2434      if(filter=='tidy' || filter=='word_clean') continue; 
     35       
     36      // Any full only ones need to happen later 
     37      if(typeof filter == 'object' && filter.fullonly) continue; 
     38       
    2539      if(opts[filter]) 
    2640      { 
     
    3246    D = D.replace(/<(font|span)\s*>/gi, ''); 
    3347 
    34     editor.setEditorContent(D); 
    35  
     48    if(opts['scope'].value == 'selection') 
     49    { 
     50      editor.insertHTML(D); 
     51    } 
     52    else 
     53    { 
     54      editor.setEditorContent(D); 
     55    } 
     56 
     57    // Do the full only ones 
     58    D = editor.getEditorContent(); 
     59    for(var filter in editor.config.SuperClean.filters) 
     60    { 
     61      // Skip tidy we do that last, and word_clean was done 
     62      // first 
     63      if(filter=='tidy' || filter=='word_clean') continue; 
     64       
     65      // Any full only ones need to happen last 
     66      if(typeof filter == 'object' && filter.fullonly && opts[filter]) 
     67      { 
     68        D = SuperClean.filterFunctions[filter](D, editor); 
     69      } 
     70    } 
     71     
    3672    if(opts.tidy) 
    3773    { 
     
    173209}; 
    174210 
     211SuperClean.filterFunctions.remove_emphasis = function(html) 
     212 
     213  html = SuperClean.stripTags(html, [ 'b', 'strong', 'i', 'em', 'u', 'mark', 'ins','abbr', 'acronym', 'kbd', 'samp', 'strike', 's'  ]); 
     214   
     215  // for del we delete it entirely or it would be confising (<del>old thing</del> <ins>new thing</ins> would become old thing new thing)   
     216  html = SuperClean.stripTags(html, [ 'del' ], true); 
     217   
     218  html = html.replace(/font-weight:[^;}"']+;?/gi, ''); 
     219  html = html.replace(/font-style:[^;}"']+;?/gi, ''); 
     220  return html; 
     221}; 
     222 
     223SuperClean.filterFunctions.remove_sup_sub = function(html) 
     224{ 
     225  return SuperClean.stripTags(html, ['sup', 'sub']).replace(/vertical-align:\s*(sub|super)[^;}"']+;?/gi); 
     226}; 
     227 
     228SuperClean.filterFunctions.remove_alignment = function(html) 
     229{ 
     230  return html.replace(/ align=[^\s|>]*/gi,'').replace(/(text-align|vertical-align|float):[^;}"']+;?/gi, ''); 
     231}; 
     232 
     233SuperClean.filterFunctions.remove_all_css_classes = function(html) 
     234{ 
     235  return SuperClean.stripAttributes(html, 'class'); 
     236}; 
     237 
     238SuperClean.filterFunctions.remove_all_css_styles = function(html) 
     239{ 
     240  return SuperClean.stripAttributes(html, 'style'); 
     241}; 
     242 
     243SuperClean.filterFunctions.remove_all_tags = function(html) 
     244{ 
     245  return  html.replace(/<[\!]*?[^<>]*?>/g, ""); 
     246}; 
    175247 
    176248SuperClean.Dialog = function (SuperClean) 
     
    209281    { 
    210282      htmlFilters += "        <input type=\"checkbox\" name=\"["+filter+"]\" id=\"["+filter+"]\" value=\"on\"" + (filtDetail.checked ? "checked" : "") + " />\n"; 
    211       htmlFilters += "        <label for=\"["+filter+"]\">"+filtDetail.label+"</label>\n"; 
     283      htmlFilters += "        <label for=\"["+filter+"]\">"+filtDetail.label+(filtDetail.fullonly?'^ ':'')+"</label>\n"; 
    212284    } 
    213285    htmlFilters += "    </div>\n"; 
     
    254326  } 
    255327 
     328  // If there is selected text, set that the default scope 
     329  if(this.SuperClean.editor.hasSelectedText()) 
     330  { 
     331    this.dialog.getElementsByName('scope')[0].selectedIndex = 1; 
     332  } 
     333  else 
     334  { 
     335    this.dialog.getElementsByName('scope')[0].selectedIndex = 0; 
     336  } 
     337   
    256338  // Show the dialog 
    257339  this.SuperClean.editor.disableToolbar(['fullscreen','SuperClean']); 
Note: See TracChangeset for help on using the changeset viewer.