Was this page helpful?

Improve pasting from Microsoft Word

    Paste from Word option available in editor along with using the MS Word Connector

    Enforce "paste as plain text" and make users use "Paste from Word" for tables,etc

    If you want to enable plain text paste as default but still keep the option open for users to use the "Paste from Word" button you can either add your own plugin/button or you can edit the Javascript of FCKEditor a bit so that it doesn't disable the "Paste from Word" button when you have enabled "Force Paste Plaintext". Be sure to take backup of your files before editing them.

     

    First of all you need to enable "Force Paste Plaintext" so that your FCKEditor always by default pastes plain text. Do this by going into the Control Panel >> Editor and add this:

    FCKConfig.ForcePasteAsPlainText = true;

     

    Then you're going to have to edit the following files:

    /var/www/dekiwiki/editor/fckeditor/core/editor/js/fckeditorcode_gecko.js
    

    Go to line 108 and look for the following:

    || FCKConfig.ForcePasteAsPlainText

    And remove it

    And:

    /var/www/dekiwiki/editor/fckeditor/core/editor/js/fckeditorcode_ie

    Go to line 76 and look for the following:

    ||FCKConfig.ForcePasteAsPlainText

    And remove it

    Now empty your webbrowser cache as test it out. By default FCKEditor will now clean out all text pasted and only allow plain text to be pasted, except for when users choose to click the "Paste from Word" button which they can use for pasting tables and so on!

    Improved/stricter "Paste from Word" button

    Stevenage had a great tip about hacking the fck_paste.html for improved "Paste from Word", I have added more stuff to it to make the copy & paste from Word even "stricter" (remove more junk)

    First of all, in your Control Panel >> Editor, add this section:

    FCKConfig.CleanWordKeepsStructure = true;

    To remove more junk

    Then edit:

    /var/www/dekiwiki/editor/fckeditor/core/editor/dialog/fck_paste.html

    And under the line:

    var html = oNode.innerHTML ;

    Add this:

    // HACK Remove styles on TD and TABLE
    html = html.replace( /<td([^>]*)>/gi, '<td>' ) ;
    html = html.replace( /<table([^>]*)>/gi, '<table cellspacing="1" cellpadding="1" border="1">' ) ;
    
    

    Then under the line:

    // The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
            html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;

    Add this:

    // HACK Need to remove some more font sizes
    html = html.replace(/<font size=2>(.*)<\/font>/gi,'$1') ;
    html = html.replace(/<font size=3>(.*)<\/font>/gi,'$1') ;
    
    // HACK Clean out A NAME
    html = html.replace(/<a name=.*><em>/gi,'') ;
    html = html.replace(/<\/a><\/em>/gi,'$1') ;
    
    // HACK Lower Heading H1 which is used as TITLE in MindTouch
    html = html.replace( /<H1([^>]*)>/gi, '<H2$1>' ) ;
    html = html.replace( /<\/H1\d>/gi, '<\/H2>' ) ;
    
    // HACK Remove all annoying empty span tags
    html = html.replace( /<span>/gi, '$1' ) ;
    html = html.replace( /<\/span\d>/gi, '' ) ;

     

    I have attached the file I am using as example. You can of course customize the above to suite your needs better, for instance maybe you don't want to clean out styles for the TABLE or TD always..then just remove that!

    Was this page helpful?
    Tag page

    Files 1

    FileVersionSizeModified 
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by