You are not logged in.

#1 2008-07-21 02:27:43

peet.j
Member
Registered: 2007-10-05
Posts: 15

Paste from Word not converting Word comments

Hi,

One of our testers pasted in some text (from MS Word) and it managed to paste in this comment (see below):

<!--[if gte mso 9]><xml> Normal   0         false   false   false                             MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><xml> </xml><![endif]--><!--[if !mso]><object  classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object> <style>
st1\:*{behavior:url(#ieooui) }
</style> <![endif]--> <!--[if gte mso 10]> <style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style> <![endif]-->


The paste from Word didn't manage to fix it so we put in a regex like this which worked (see the last line):

                content = content.replace(new RegExp('tab-stops: list [0-9]+.0pt">', 'gi'), '">' + "--list--");
                content = content.replace(new RegExp(bull + "(.*?)<BR>", "gi"), "<p>" + middot + "$1</p>");
                content = content.replace(new RegExp('<SPAN style="mso-list: Ignore">', 'gi'), "<span>" + bull); // Covert to bull list
                content = content.replace(/<o:p><\/o:p>/gi, "");
                content = content.replace(new RegExp('<br style="page-break-before: always;.*>', 'gi'), '-- page break --'); // Replace pagebreaks
                content = content.replace(new RegExp('<(!--)([^>]*)(--)>', 'g'), "");  // Word comments
               
                /* FIX PJ - Match zero or more of alphanumeric, non-word and whitespace characters */
                content = content.replace(new RegExp('<(!--)([\w\W\s]*)(--)>', 'g'), "");  // Word comments 2


This goes in: plugins/paste/editor_plugin.js line 207

Hope this is useful

Cheers

peet...

Offline

 

#2 2008-07-21 10:49:14

peet.j
Member
Registered: 2007-10-05
Posts: 15

Re: Paste from Word not converting Word comments

I feel a bit daft replying to my own message but I discovered that my regex was wrong. It should have read:


// Match any character
content = content.replace(/<(!--)([\s\S]*)(--)>/gi, "");



For some reason the RegExp() version doesn't work.

Offline

 

#3 2008-07-23 12:20:20

Zooey
Member
Registered: 2008-07-11
Posts: 15

Re: Paste from Word not converting Word comments

I posted about this in a separate thread, but as I'm getting a similar issue to this I am hoping that you might be able to help.

When I use Firefox, the paste from Word option inserts code like this. It shows up in html view, and in the posted content, but not in the editor view.

Code:

<!--[if gte mso 9]><xml> Normal 0 false false false MicrosoftInternetExplorer4 </xml><![endif]--><!--[if gte mso 9]><xml> </xml><![endif]--><!-- --><!--[if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!--[endif]-->

The content that I'm testing with doesn't include any special formatting - no tables, Word comments, etc - it's just left-aligned text with a few paragraph breaks. The rogue code does not manifest itself in Internet Explorer or any other browser that I've tested.

I tried adding in the regex you suggest, peet. In my plugin folder I have editor_plugin_src.js and  editor_plugin.js - editor_plugin.js doesn't seem to contain any of the other code that was shown in your example so I added it into editor_plugin_src.js (my js files are the latest release of Tiny MCE and I'm using Tiny MCE as part of a Rails app, but not using the Rails plugin). Neither the original regex code you offered nor the corrected version seem to deal with my problem.

I'd really appreciate it if anyone can shed some light on this issue. I'm a novice when it comes to js so I'm finding it difficult to figure out where the issue is arising.

Thanks!

Offline

 

#4 2008-07-23 15:27:41

pete.j
Member
Registered: 2008-07-23
Posts: 3

Re: Paste from Word not converting Word comments

Hi Zooey,

I saw your other thread. The reply by krzyko looks correct to me. I would suggest that you use this solution. Also the editor_plugin_src.js files are not used unless you have downloaded the dev version of TinyMCE tinymce_3_x_dev.zip, therefore if you want to use my solution, save the plugins/paste/editor_plugin_src.js file as editor_plugin.js which is the minified obfuscated version of the same file. the _src version is there so you can make sense of the code!

Back to krzyko's reply. This is ok but the plugin should really be fixed so that you don't need to 'cleanup' in a callback function. That's the whole point of the plugin.

I don't know why it happens in firefox, but the fact that IE works is not that surprising since Word to IE = Microsoft. Maybe it does some internal cleanup ??

I hope this reply makes sense and you can get it to work

Cheers

Pete
(aka peet.j)

Offline

 

#5 2008-07-24 00:16:12

esd
Member
Registered: 2008-07-24
Posts: 4

Re: Paste from Word not converting Word comments

Rather than patching the plugin, you can just use its handy callback function:

Code:

    tinyMCE.init({
            .....
                    
            paste_insert_word_content_callback : "convertWord",

            .....
    });

        function convertWord(type, content) {
            switch (type) {
                // Gets executed before the built in logic performes it's cleanups
                case "before":
                    // do nothing
                    break;
        
                // Gets executed after the built in logic performes it's cleanups
                case "after":
                    content = content.replace(/<(!--)([\s\S]*)(--)>/gi, "");
                    break;
            }
        
            return content;
        }

Last edited by esd (2008-07-24 00:16:33)

Offline

 

#6 2008-07-24 13:11:13

pete.j
Member
Registered: 2008-07-23
Posts: 3

Re: Paste from Word not converting Word comments

You are correct but the patch better in the long term. The callback should be used for other tasks. The plugin's job is to cleanup a word paste so this is what it should do.

Cheers

Pete...

Offline

 

#7 2008-07-24 16:21:58

esd
Member
Registered: 2008-07-24
Posts: 4

Re: Paste from Word not converting Word comments

Sure, until a new version of tinymce comes out. Now instead of just overwriting the directory, you've got to remember what you patched, reapply the patch to the new version, and re-minify it.

But to each his own smile

Offline

 

#8 2008-07-24 20:06:57

kelmer
Member
Registered: 2008-07-24
Posts: 3

Re: Paste from Word not converting Word comments

Hi,

I tried both solutions, modifying editor_plugin.js and using the workaround of convertWord function, but none of them worked, I'm still getting this piece of code:

Code:

<!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:70.85pt 3.0cm 70.85pt 3.0cm; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

inserted into my database.

Any more help?

Offline

 

#9 2008-07-24 20:13:54

esd
Member
Registered: 2008-07-24
Posts: 4

Re: Paste from Word not converting Word comments

Kelmer- I wonder, do you have

Code:

paste_auto_cleanup_on_paste : true,

in your init?

Offline

 

#10 2008-07-24 20:16:32

kelmer
Member
Registered: 2008-07-24
Posts: 3

Re: Paste from Word not converting Word comments

I didn't - but now I do, with no better results:

My current init:

Code:

tinyMCE.init({
    mode : "textareas",
    paste_remove_styles: true,
    paste_auto_cleanup_on_paste : true

});

Offline

 

#11 2008-07-24 20:20:31

esd
Member
Registered: 2008-07-24
Posts: 4

Re: Paste from Word not converting Word comments

Is that the whole init? You've got to include the "paste" plugin too. Like:

Code:

tinyMCE.init({
    mode : "textareas",
    plugins : "paste",
    paste_remove_styles: true,
    paste_auto_cleanup_on_paste : true

});

See: http://wiki.moxiecode.com/index.php/Tin … gins/paste

Offline

 

#12 2008-07-24 21:09:34

kelmer
Member
Registered: 2008-07-24
Posts: 3

Re: Paste from Word not converting Word comments

Oops, I thought it was already activated by default, as it worked perfectly with IE.

Anyway, I put that line and now each time I press Ctrl + V I get a dialog, even when I have the following init:

Code:

tinyMCE.init({
    mode : "textareas",
    plugins: "paste",
    paste_use_dialog: false,
    paste_auto_cleanup_on_paste : true

});

On the other hand, using context menu and clicking "Paste" seems to work, but I'm still getting that friggin piece of code sad

Last edited by kelmer (2008-07-24 21:10:48)

Offline

 

#13 2008-07-25 09:10:36

peet.j
Member
Registered: 2007-10-05
Posts: 15

Re: Paste from Word not converting Word comments

Hi Kelmer,

I am assuming that you are pasting from Word? Your Word comment should be cleaned up be the regular expression above, ie.

<!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:612.0pt 792.0pt; margin:70.85pt 3.0cm 70.85pt 3.0cm; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->

should be cleaned by:

/<(!--)([\s\S]*)(--)>/

I tried in at: http://www.regular-expressions.info/jav … ample.html

When you do a control-v for the first time (in Firefox), you should get a dialog to paste into. This is slightly annoying but paste the content again with another control-v. When you click insert, the content should be cleaned up.

The paste options are in: http://wiki.moxiecode.com/index.php/Tin … gins/paste

One suggestion would be to debug the plugin with firebug to check the replaced content. Just trap plugins/paste/editor_plugin.js on or around line 206 and check the content.

I hope you have better luck this time.

Cheers

Pete...

Offline

 

#14 2008-07-31 13:46:45

Zooey
Member
Registered: 2008-07-11
Posts: 15

Re: Paste from Word not converting Word comments

Peet, thanks very much for your help. I'm going to go with the callback as a fix - I hope this will be patched in the official release eventually, though.

Offline

 

#15 2008-08-08 10:38:22

peet.j
Member
Registered: 2007-10-05
Posts: 15

Re: Paste from Word not converting Word comments

no problem - bear in mind that in the callback - the content is ALL the content rather than the pasted content

Cheers

peet...

Offline

 

#16 2008-08-21 07:54:47

rayleigh
Member
Registered: 2008-08-09
Posts: 2

Re: Paste from Word not converting Word comments

How about using html_entity_decode() and htmlspecialchars_decode()? Can this be a reliable solution?

Offline

 

#17 2008-09-29 15:22:16

mla
Member
Registered: 2008-09-29
Posts: 2

Re: Paste from Word not converting Word comments

What do you think about the modifications from fckeditor :

http://dev.fckeditor.net/ticket/2272
http://dev.fckeditor.net/changeset/2174

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2008 PunBB