I just updated to TinyMCE 3.3.2.
When I toggle the "paste as plain text" function on, the text is pasted with html markup, not as plain text.
Maybe this is an issue that belongs to TinyMCE and not Wysiwyg.

Does someone have a solution? Thanks

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TwoD’s picture

Status: Active » Fixed

Wysiwyg doesn't have a GUI option to toggle any "paste as plain text" option. If you mean "Force cleanup on standard paste", it won't remove all markup from an HTML selection, just the most annoying parts of what Word produces.

There's also the "Paste text" button you can enable, but it uses a dialog which forces the browser to use the text/plain variant if the clipboard has an HTML selection. (Note that selecting "source HTML markup" from text editors like Notepad will still select it as text/plain, which isn't a HTML selection. Then all the < and > will be escaped by the editor to &lt; and &gt; etc.

The rewritten Paste plugin will try to autodetect Word contents when pasting and clean it up. But to paste plain text, you need to use the "Paste text" button/dialog.

I don't think TinyMCE even has a way to force text/plain pastes like CKEditor does (need to enabled that via hook_wysiwyg_editor_settings_alter() for now).

tomsm’s picture

When I revert back to TinyMCE version 3.2.7 the problem is fixed because "paste as plain text" uses a popup window in which the text needs to be pasted.
In version 3.3.2 this popup window has been replaced by a toggle function that does not work.

TwoD’s picture

Status: Fixed » Active

Ah, you meant the button in the toolbar. I thought you were talking about an option provided by Wysiwyg.

I can confirm that contents are not pasted as text when the button is toggled, but it works in the official TinyMCE demo. I don't know why it doesn't work yet, but I suspect it may be something related to the invisible div TinyMCE uses to catch the pasted contents.

tomsm’s picture

Indeed, that is the button I meant.

superfedya’s picture

same here, with tinymce 3.3.8. any fix?

tomsm’s picture

Version: 6.x-2.1 » 6.x-2.2

same with 6.x-2.2 and tinyMCE 3.3.9.3

TwoD’s picture

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

I tested this with Wysiwyg 6.x-2.x-dev and TinyMCE 3.3.9.3 (and the 3.4beta) and it does work, but one must check the "Force cleanup on standard paste" option under "Cleanup and output" when configuring the editor profile.

The description for that checkbox is wrong:

If enabled, the default paste function (CTRL-V or SHIFT-INS) behaves like the "paste from word" plugin function.

It should instead look more like the official description of TinyMCE's paste_auto_cleanup_on_paste setting:

If enabled contents will be automatically processed when you paste using Ctrl+V or similar methods. This is enabled by default.

Note that this applies to TinyMCE only, other editors use this options in other ways, and that Wysiwyg currently has this disabled by default. It used to disabled in TinyMCE too but later versions changed that.

When "Force cleanup on standard paste" has been checked (or in practice, the paste_auto_cleanup_on_paste setting is enabled) TinyMCE will process the pasted contents, but plain text will only be generated if the "Plain text" button is ON.
TinyMCE automatically detects pasted MS Word contents by matching against a Regular Expression: /class="?Mso|style="[^"]*\bmso-|w:WordDocument/i. If it's a positive match, MS Word cleanup will happen automatically as part of the paste processing.

When "Force cleanup on standard paste" is not checked, TinyMCE doesn't care much what happens when pasting, it's all up to the browser.

Paste processing always takes place if the mceInsertClipboardContent command is fired by some "external" script - such as the "Paste from Word" dialog, or the "Paste as text" dialog if the paste_text_use_dialog option has been set. The "Paste from Word" dialog additionally sets an internal "wordContent" flag to always force the MS Word cleanup, but users can't request this without going through that dialog.

paste_text_use_dialog can currently only be enabled via Wysiwyg by implementing hook_wysiwyg_editor_settings_alter():

function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
  if($context['profile']->editor == 'tinymce') {
    $settings['paste_text_use_dialog'] = TRUE;
  }
}

To summarise

There seems to be no setting to always force a paste (keyboard shortcut or via context-menu) to be inserted as plain text or go through a MS Word cleanup. Hence, the checkbox description is wrong and needs to change. For some editors it should even be removed because they don't support this kind of operation.

I'm not sure yet if we should mark this issue a duplicate of #313497: Allow configuration of advanced editor settings - we'll have to go through all the settings for every editor in there anyway - or leave it open for now.

Jorrit’s picture

I have made a module with the following callback:

function mymodule_wysiwyg_editor_settings_alter(&$settings, $context) {
  if($context['editor']['name'] == 'tinymce' && $context['profile']->settings['paste_auto_cleanup_on_paste'] && isset($context['profile']->settings['buttons']['paste']['pastetext'])) {
    $settings['paste_text_sticky_default'] = TRUE;
    $settings['paste_text_sticky'] = TRUE;
  }
}

Using CSS I hide the paste as text button:

 .mce_pastetext {
display: none;
}

Now the user can't disable the paste as text button, it is on by default and it will not toggle after one paste.

fenstrat’s picture

The method in #8 works flawlessly for those looking to silently run all paste commands through a plain text cleanup.

chromix’s picture

#8 works like a charm. I would just change the CSS to the following:

.mce_pastetext { 
  visibility: hidden; 
}

Depending on what skin you're using the display:none property might get overridden.

Roobarb’s picture

The attached patch adds a new option to Wysiwyg (for TinyMCE only), called Activate "Paste as Plain Text" button and make it sticky. If you select this option and display the Paste as Plain Text button, that button will be enabled by default and won't be deactivated after pasting text (you can deactivate it manually by clicking the button though).

janchojnacki’s picture

Version: 6.x-2.x-dev » 7.x-2.1
FileSize
2.54 KB

Thanks Roobarb!

Created D7 version of patch

TwoD’s picture

Status: Active » Closed (won't fix)

Please follow #1963766: Improve support for paste related options for the current status of support for paste related settings.
Even though I mark this a "won't fix", much of the code from #12 will be incorporated within the patch for that issue and the authors will be credited for it.