The option "Force cleanup on standard paste" does not appear to be working properly. Here is what happens:

1. TinyMCE: The forced cleanup only works if custom buttons are selected in the buttons and plugins area. In other words, if no buttons and plugins are selected (i.e. the default UI is used) pasting from word gives garbled text.

2. FCK: The forced cleanup does not work at all (i.e. pasting word text with ctrl-v gives garbled text). This happens even though the paste from word button works.

3. Others: The forced cleanup option appears even though it does not work.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tenek’s picture

Selecting the option "Apply source formatting" eliminates the garbled text but the code is still terrible.

sun’s picture

Status: Active » Closed (duplicate)

If it's not working in the default UI, then please file a bug report for the corresponding library (in its own, external bug tracker).

Regarding the first part of 1) and 3)... marking as duplicate of #313497: Allow configuration of advanced editor settings, #328252: Handle compatibility of internal plugins via plugin API, and #277954: Allow to sort editor buttons.

However, thanks for taking the time to report this issue.

brisath’s picture

Part 1 in the original post here doesn't seem to be working for me, even with custom buttons checked. If I understand this correctly, I am to have at least 1 custom button checked for "Force cleanup on standard paste" to work. I currently have "Paste as plain text" button checked and the Ctrl-V isn't forcing a plain text paste.

Also, I haven't seen an issue opened for TinyMCE on this. Am I missing something?

ed_conolly’s picture

You need to have "Paste from Word" ticked under Buttons & Plugins for the editor. Then by having "force cleanup on standard paste" from word will work.

Hope that helps.

www.inetdigital.co.uk

tsayonara’s picture

Priority: Normal » Critical

Even with the "paste from word" butotn enabled this function still does not work for me. Using the button does. Ctrl v doesn't.

TwoD’s picture

Priority: Critical » Normal

@tsayonara, Which editor are you using? Is "this function" "Force cleanup on standard paste"? The editor might not be able to intercept Ctrl+v pastes to clean them up, that depends on security rules, nothing anyone can do about that. Instead, TinyMCE should launch the "Paste from word" dialog. I don't remember what FCKeditor does.

tsayonara’s picture

Hi! Yep I meant "force cleanup" with 'this function'.

Where can I change the security rules? Right now it just pastes (without cleaning), I don't get a popup.

I'm using Tiny btw

tsayonara’s picture

Hi! Yep I meant "force cleanup" with 'this function'.

Where can I change the security rules? Right now it just pastes (without cleaning), I don't get a popup.

I'm using Tiny btw

TwoD’s picture

That's a browser setting, I don't know where exactly. Spocke (main dev of TinyMCE) mentions that clipboard access can be restricted in this thread: http://tinymce.moxiecode.com/punbb/viewtopic.php?pid=68595 but it seems like it shouldn't do that with the default browser settings.

TinyMCE

Over at http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/paste it says the paste_auto_cleanup_on_paste setting is on by default as of TinyMCE 3.2.3. (It's what we enable when the "Force cleanup on standard paste" box is checked.)
By default, Wysiwyg explicitly sets its value to 0/false, but if you check that box it's explicitly set to 1/true, so that part works as it should.
I also looked through the code of the new paste plugin to see what happens: If the 'paste' plugin is enabled (for Wysiwyg to do that, you need to enable one of its buttons); it sets itself up to listen for either the keys [Ctrl]+[v], or the 'paste' event existing in some browsers. When detecting a paste it invokes the new 'mceInsertClipboardContent' command.

'mceInsertClipboardContent' automatically detects contents pasted from Word at all times when using its default pre-/postprocessor functions (EDIT: I think I misread the code, the paste_auto_cleanup_on_paste setting only seems to make it always trigger it for [Ctrl]+[v] pastes). If it detects restricted security settings (atleast in IE according to comments), it routes the paste via the old "Paste from Word" popup using the legacy 'mcePasteWord' command.
However, both the 'mcePasteWord' and 'mcePasteText' commands have had their dialogs rewritten to route the pasted contents back to the 'mceInsertClipboardContent'. So it shouldn't matter if you press the 'paste' buttons and get a dialog or just [Ctrl]+[v], it's the same code which does the actual processing.

If this doesn't work as expected, please check with the official examples/demos. If you can reproduce the pasting issues there, it's a problem in the library itself and should be reported to their bug tracker.

Here's something for us to improve: When TinyMCE 3.2.3 is used it looks like it's enough to have just the 'paste' plugin, and none of its buttons, enabled for everything to work as it should. So we should probably turn this into an 'extension' in the plugin definition so that it can be loaded without any buttons enabled. I'm not sure how to trigger "Paste as [plain] text" without a button though, so we should probably leave them in there. That, and users might want to why installing a new version if the library 'breaks' a feature they depend upon by removing the button for the dialog.

FCKeditor

Fckeditor acts in a similar way, trying to detect [Ctrl]+[v] and uses the same commands as for the buttons with dialogs. The code flow is much more complicated though so I'm not going into details here.
There's one major difference though: FCKeditor's AutoDetectPasteFromWord option (enabled by our "Force cleanup..." checkbox) is IE only!. FCKeditor will not attempt to clean up Word's mess in anything other than Internet Explorer - unless the button to 'manually' trigger the "Paste from Word" dialog is used.

Others

Some other editors have this feature as well, and they also have their quirks for how it works. Until #313497: Allow configuration of advanced editor settings is fixed, the Wysiwyg profile will always show the "Force cleanup..." checkbox but it may not be "connected" to an actual editor setting.

I hope that clears things up a bit and explains why you see the behavior(s) described in this issue.

tsayonara’s picture

That was a very clear answer, thank you

Francewhoa’s picture

FileSize
14.82 KB

Confirming this issue. Force cleanup on standard paste is not working with
*Drupal 6.16
*Wysiwyg 6.x-2.1
*CKEditor 3.2.1.5372
*Internet Explorer 7
*Firefox 3

Find below screenshot to clarify feature location.

Francewhoa’s picture

Title: Force cleanup on standard paste not working properly » 'Force cleanup on standard paste' not working
Version: 6.x-2.x-dev » 6.x-2.1
Component: Miscellaneous » Code
Status: Closed (duplicate) » Active

Forgot to change status. #11 is for Wysiwyg with CKEditor.

TwoD’s picture

Version: 6.x-2.1 » 6.x-2.x-dev
Status: Active » Closed (duplicate)

Issue still exists in -devs, as we don't have #313497: Allow configuration of advanced editor settings in yet. As per #2, this is a duplicate of #313497. When that issue is fixed, 'Force cleanup on standard paste' will be removed for editors which do not support it, or if they only autodetect when cleanup is needed. (Re #11/12: CKEditor autodetects Word pastes if the 'wordpaste' plugin is enabled, and you can invoke it manually using a toobar icon, so it won't need this option).

luco’s picture

confirm: running CKEditor on a mac here (where it's command + V to paste). enabled every paste button I could find; only works when you click the controls in the editor. command + V will paste regularly formatted, and ugly-coded, text ;]

upupax’s picture

subscribing

cleanthes’s picture

subscribing

my-family’s picture

subscribing

advix’s picture

Status: Closed (duplicate) » Active

subscribing. confirm issue in stable 2.1 and dev version also. Tested with ckeditor, fckeditor, tinymce, wymeditro. Tested in Chrome and FF.

tobiasoleary’s picture

Here's nasty way around this problem on the Mac for the CKEditor.
These steps will force the paste pop-up to appear, which will cause all the nasty tags to be stripped out.
Note this is a really bad solution from someone that doesn't really know what they are doing.
This 'solution' will probably breaks some functionality, like per user configurations.

------------STEP 1---------------

In wysiwyg/editors/js/ckeditor-3.0.js is to add a ling at the top of the file.

(function($) {

CKEDITOR.config = function( config ) {}; //<------- add this line to force the CKEditor to use /libraries/ckeditor/config.js

Drupal.wysiwyg.editor.init.ckeditor = function(settings) {

------------STEP 2---------------

Then in libraries/ckeditor/config.js put the following info in:

CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
config.keystrokes =
[
//Custom Keystrokes
[ CKEDITOR.CTRL + 86 /*V*/, 'pastefromword'], //<--- forces cmd+v to show pastefromword popup.

//Default Keystrokes
[ CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus' ],
[ CKEDITOR.ALT + 122 /*F11*/, 'elementsPathFocus' ],

[ CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' ],

[ CKEDITOR.CTRL + 90 /*Z*/, 'undo' ],
[ CKEDITOR.CTRL + 89 /*Y*/, 'redo' ],
[ CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/, 'redo' ],

[ CKEDITOR.CTRL + 76 /*L*/, 'link' ],

[ CKEDITOR.CTRL + 66 /*B*/, 'bold' ],
[ CKEDITOR.CTRL + 73 /*I*/, 'italic' ],
[ CKEDITOR.CTRL + 85 /*U*/, 'underline' ],

[ CKEDITOR.ALT + 109 /*-*/, 'toolbarCollapse' ]
];
};

--------------------------------

Done. Refresh your page and you should and you should get the pastefromword popup when using cmd+v

TwoD’s picture

There is no need to hack ckeditor-3.0.js to get it to load config.js and override the basic settings.
Implement hook_wysiwyg_editor_settings_alter() in a module instead:

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, &$context) {
  if($context['profile']->editor == 'ckeditor') {
    // To load the config file from any location:
    $settings['customConfig'] = 'path-to-config.js';
    // To load it from the CKEditor folder, no matter if it's in sites/all/libraries or sites/site-name/libraries.
    // $settings['customConfig'] = wysiwyg_get_path('ckeditor', TRUE) . '/config.js';
  }
}

Just note that because Wysiwyg passes its settings directly to the editor instance when it's created, it will override any setting that has been previously set in a config.js file. To change settings used by Wyswyg, the above hook can be used as the $settings array is what will be passed to the instance. Settings not used by Wysiwyg will work when put in the config file.

This is one way of working around a limitation of the hook; it can't set settings which require their value to be a JavaScript Function/Object reference or a Regular expression. These can't be automatically "translated" from PHP to JS without problems.

vlad.k’s picture

subscribing...

luco’s picture

+1

perandre’s picture

Sub!

franzkewd’s picture

Subscribe

rnyberg’s picture

Subscribe. The bug still present, and even more important now as WYSIWYG + CKEditor is the only GUI way for inserting Images into node body as Media modules own [{}] style tags.

JohnTarr’s picture

Subscribing. I'm having a similar problem with YUI in IE 8 & 9.

When pasting a link, it automatically converts the text of the link to a hyperlink (i.e. pasting "http://www.youtube.com/watch?v=RlNPRonDxuU" will automatically turn blue and underlined in IE8&9 in the editor). This conflicts with Embedded Inline Media, making it difficult for IE users to quickly embed videos.

TwoD’s picture

@JohnTarr, that's a different bug in YUI itself (or perhaps IE) and not something we can fix in Wysiwyg. It also happens on http://developer.yahoo.com/yui/examples/editor/toolbar_editor.html.

Clean’s picture

FileSize
7.31 KB

This is a noob contribution back o this thead. So I would give a noob module, and noob step-by-step guide.

I've wrapped up comment #19 and #20 to a module for people using Wysiwyg with CKeditor:
1.) Download the attached file, unzip and place module directory as usual in /sites/all/modules
2.) Go to ckeditor directory, sites/all/libraries/ckeditor or sites/'site name'/libraries/ckeditor , rename original config.js to 'config-original.js'
3.) Copy 'config.js' to sites/all/libraries/ckeditor or sites/'site name'/libraries/ckeditor ,
4.) Enabled and enjoy.

@TwoD how to I load config.js directly from module directory?

As the code stated: $settings['customConfig'] = 'path-to-config.js';

But I'm not a developer, just start having fun on building module. And since this is just my third simple custom module, I've no idea what to use for 'path-to-config.js', I've tried something like '/sites/all/modules/wysiwyg_clean_paste/config.js' but no go.

Thanks Gaspy and TwoD!

Clean’s picture

gr33nman’s picture

Drupal 6
Wysiwyg - latest
TinyMCE - latest

I can use the 'paste from word' button, but 'force cleanup on standard paste' does not work when checked in wysiwyg.

This is not working as expected.

However, when you check 'Apply source formatting' in wysiwyg, suddenly it works. I'm not entirely clear why.

Subscribing.

John Pitcairn’s picture

subscribe

zeitlupe’s picture

subscribe

John Pitcairn’s picture

In reply to #28/29

To implement this cleanly, without messing with anything in the CKEditor library, use a custom module "mymodule" (for example). The module directory should contain the usual mymodule.info and mymodule.module files, plus an additional javascript file, ckeditor-config.js.

mymodule.module:

<?php
/**
 * Implementation of hook_wysiwyg_editor_settings_alter().
 */
function mymodule_wysiwyg_editor_settings_alter(&$settings, &$context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['customConfig'] = base_path() . drupal_get_path('module', 'mymodule') . '/ckeditor-config.js';
  }
}

ckeditor-config.js:

if (CKEDITOR) {
  CKEDITOR.editorConfig = function(config) {
    // changes to default configuration
    config.keystrokes = [
      // custom keystrokes
      [ CKEDITOR.CTRL + 86 /*V*/, 'pastefromword'], //force cmd + v to show pastefromword popup.

      //Default Keystrokes
      [ CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus' ],
      [ CKEDITOR.ALT + 122 /*F11*/, 'elementsPathFocus' ],
      [ CKEDITOR.SHIFT + 121 /*F10*/, 'contextMenu' ],
      [ CKEDITOR.CTRL + 90 /*Z*/, 'undo' ],
      [ CKEDITOR.CTRL + 89 /*Y*/, 'redo' ],
      [ CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/, 'redo' ],
      [ CKEDITOR.CTRL + 76 /*L*/, 'link' ],
      [ CKEDITOR.CTRL + 66 /*B*/, 'bold' ],
      [ CKEDITOR.CTRL + 73 /*I*/, 'italic' ],
      [ CKEDITOR.CTRL + 85 /*U*/, 'underline' ],
      [ CKEDITOR.ALT + 109 /*-*/, 'toolbarCollapse' ]
    ];
  }
}

As mentioned earlier, the "paste from Word" toolbar button must be enabled in the wysiwyg configuration for this to work.

rukaya’s picture

I have got the same situation as #30

TwoD’s picture

@rukaya, are you pasting using [Ctrl]+[v] or a toolbar button? Which paste-related buttons do you have enabled?

rukaya’s picture

TwoD:

I was using ctrl+v and it wasn't stripping out word tags and styling. I read reply #30 on this thread and checked 'Apply source formatting', added the paste from word toolbar button and the paste as plain text button, and then ctrl+v started working. Not sure if it will work with one and not the other, I enabled all 3 at the same time.

TwoD’s picture

@rukaya, Could you please check if it works without the "Apply source formatting" option? All it does is to toggle TinyMCE's apply_source_formatting setting (two lines in editors/tinymce.inc), which in turn toggles the new indent setting in TinyMCE's internals.

A quick grep through the TinyMCE code only showed that those settings are being used in the HTML writer class and the fullpage plugin (not supported or used by Wysiwyg).

rukaya’s picture

TwoD: Yes, I just checked, it's working absolutely fine without the apply_source_formatting setting ticked.

TwoD’s picture

Good, that makes sense.
There's been a great deal of confusion about this setting, as you can see above.
For TinyMCE, it only works if the paste plugin/buttons are enabled due to the way it's built.

I'm not sure which problems in this issue are still unresolved, will have to go through it again later.
It's true that "Force cleanup on standard paste" will have no effect at all on some editors though, simply because the have no equivalent setting. The "Advanced settings"-issue has been delayed a lot longer than intended so I intend to focus on that first. Perhaps we can close this issue after that since the checkbox in question would only show up in the GUI when it's actually connected to an editor setting.

norio’s picture

#33 works but I found a solution that suits me better.

Inside ckeditor-config.js replace #33's version with:

if (CKEDITOR) {
  CKEDITOR.editorConfig = function(config) {
    config.forcePasteAsPlainText = true;
  }
}

This works for Ctrl-V and Shift-Insert and it skips the popup entirely, just pasting the plain-text version directly into the editor. Much nicer for my users. Hope this helps someone :)

Anonymous’s picture

I just found this super simple method to enforce paste as plain text in ckeditor - just add the following function to a custom module:

/**
 * Implementation of hook_wysiwyg_editor_settings_alter().
 */
function MODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if ($context['profile']->editor == 'ckeditor') {
    $settings['forcePasteAsPlainText'] = TRUE;
  }
}
brennino’s picture

A possible solution that combine every thing said before and the solution found in this article:
http://stackoverflow.com/questions/5227140/ckeditor-use-pastefromword-fi...

is:

Create a mymodule.module like #33

<?php
/**
 * Implementation of hook_wysiwyg_editor_settings_alter().
 */
function mymodule_wysiwyg_editor_settings_alter(&$settings, &$context) {
  if($context['profile']->editor == 'ckeditor') {
    $settings['customConfig'] = base_path() . drupal_get_path('module', 'mymodule') . '/ckeditor-config.js';
  }
}

in ckeditor-config.js put:

if (CKEDITOR) {
CKEDITOR.on('instanceReady', function(ev) {
    ev.editor.on('paste', function(evt) {    
        evt.data['html'] = '<!--class="Mso"-->'+evt.data['html'];
    }, null, null, 9);
});
}

I tested it and it works like a charm forcing the paste from word command with Ctrl-V!

John Pitcairn’s picture

@brennino: interesting, I wasn't aware that there was an on-paste event available. That allows me to insert an aggressive regexp cleanup function, removing all but a small subset of tags and all attributes, and I may no longer need the paste from word command at all as a result. Thanks!

TwoD’s picture

There's also the pasteFromwordCleanupFile setting.

Umm, if you don't need more than a few tags, why enable the buttons producing them?
Just thinking that removing tags after content has been entered might be a bit confusing to the user, just like when setting the text format to render fewer tags than the editor will generate with the available tools...

John Pitcairn’s picture

@TwoD: Buttons are disabled as appropriate. The issue for me is not about what users can enter manually, which is easily controllable - it's about what paste should preserve or strip out.

Paste on a Mac (not necessarily from Word, many users are pasting formatted content from Apple Mail, Pages, Keynote, etc) will retain things like inline styles, spans, mailto links, attributes and random other disallowed garbage - this remains visible as formatting in the editor but can be very difficult to manually remove cleanly. This really confuses my users.

So I will aggressively clean up as much as I can on paste via custom regexes, then perhaps also run the default pasteFromWord cleanup by adding the html comment in #42.

As far as I can tell the "pasteFromwordCleanupFile" needs to reside in the plugin directory - since I don't really want to be modifying the CKEditor library at all, the paste event is a cleaner solution.

ressa’s picture

Version: 6.x-2.x-dev » 7.x-2.2

Enabling 'Force cleanup on standard paste' didn't work in CKEditor, but the module by brennino in #42 did, thank you for posting the example. The 'Paste from Word'-button doesn't need to be enabled for it to work.

Juan C’s picture

Can someone update the custom module at #42 to work with Ckeditor 4?

Using the latest cool Ckeditor 4, it seems force cleanup using 'Paste from Word' plugin is now working.

However, I prefer to use the custom module at #42 where I can force cleanup on paste without using the popup dialog.

Cheers.

TwoD’s picture

If you need the #42 code to work with CKEditor 4, add an if-statement checking the value of evt.data.type to see that's in HTML mode and then use evt.data.dataValue instead of evt.data.html.

Anyway, since CKEditor doesn't seem to have a "Force cleanup on paste" the way TinyMCE did, I've committed the following patch which changes that checkbox into "Force paste as plain text" instead, which I suppose is the second best thing.

The patch has been committed to 6.x-2.x and 7.x-2.x, the -dev snapshots will be updated within 12 hours and this will be part of the next releases.

As for other editors, the situation outlined in #9 is still true as far as I can tell.
I'll leave this issue open a little while to see if anyone has any more input, but the basic idea is to make the available options on the configuration GUI to better match the actual capabilities of each editor. Settings which are not supported by an editor will be removed or altered to reflect the actual effects they have. That's going to happen in one or more other issues though.

TwoD’s picture

Status: Active » Fixed

Please follow #1963766: Improve support for paste related options for the current status of support for paste related settings.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.