Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#9330 closed Bug (fixed)

CKEditor Paste From Word strips anchor tags

Reported by: Jake Berkes Owned by: Piotrek Koszuliński
Priority: Normal Milestone: CKEditor 4.2.1
Component: Plugin : Paste from Word Version: 3.0
Keywords: IBM Cc: monahant@…

Description

When using Paste From Word option, anchor tags (<a name=...>) are stripped from the code.

I have set PasteFromWordRemoveFontStyles="false" and PasteFromWordRemoveStyles="false". The only way to retain these tags is to skip cleanup using PasteFromWordPromptCleanup="true" and choose no at the prompt.

Attached file contains an anchor and hyperlink. Pasting the content into CKEditor without cleanup results in the following:

<a name="Anchor1"><span style="font-size:12.0pt;font-family:
&quot;Times New Roman&quot;,&quot;serif&quot;">Anchor for text above.</span></a><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;"><o:p></o:p></span></p>

Pasting with cleanup strips the <a name=..> tag completely:

<span style="font-family:times new roman,serif;"><span style="font-size:12.0pt;">Anchor for text above.</span></span>

Attachments (1)

Sample Anchor Document.docx (12.5 KB) - added by Jake Berkes 6 years ago.
Simple document with link and anchor

Download all attachments as: .zip

Change History (16)

Changed 6 years ago by Jake Berkes

Attachment: Sample Anchor Document.docx added

Simple document with link and anchor

comment:1 Changed 6 years ago by Jakub Ś

Keywords: paste word anchor removed
Resolution: invalid
Status: newclosed

I have tried your sample file on demo page and in latest CKEditor 3.6.4 and anchor was never removed.

Please use latest version of CKEditor and if you have done any customizations please check if they are not causing this error.

I'm closing this issue as invalid. If you think otherwise please provide detailed TC explaining step by step what to do to get this error (Perhaps configuration setting also matter).

comment:2 Changed 6 years ago by Jake Berkes

I have updated to 3.6.4 as well as tested on the demo page, and am able to reproduce the issue still on both. The following steps will show the error:

  1. Using the attached "Sample Anchor Document.docx" file, select all and copy.
  2. Using http://ckeditor.com/demo page, paste the text using Paste From Word.
  3. The problem is immediately evident visibly - the line "Anchor for text above." should be preceded by an anchor tag; it is not.

Pasted:
http://i.imgur.com/5nZO4.png

After manually adding anchor:
http://i.imgur.com/l0GG9.png

Also evident in the source code view; the following line:

<p>Anchor for text above.</p>

Should be:

<p><a name="Anchor1">Anchor for text above.</a></p>

comment:3 Changed 6 years ago by Jake Berkes

I was able to locate the function that is causing this behavior in the pastefromword filter default.js file:

a:function(O){var P=O.attributes;if(P&&!P.href&&P.name)delete O.name;else if(CKEDITOR.env.webkit&&P.href&&P.href.match(/file:\/\/\/[\S]+#/i))P.href=P.href.replace(/file:\/\/\/[^#]+/i,'');}

if an <a> tag is pasted with a name and no href, it deletes the name. Is this behavior intentional? If so, can you supply the reasoning behind this?

Last edited 6 years ago by Jake Berkes (previous) (diff)

comment:4 Changed 6 years ago by Jakub Ś

Resolution: invalid
Status: closedreopened

comment:5 Changed 6 years ago by Jakub Ś

Status: reopenedconfirmed
Version: 3.6.23.0

In source version of this file \ckeditor\_source\plugins\pastefromword\filter\default.js There is a comment saying that anchors with content are dropped due to #3582.

This issue is now fixed thus pasteFromWord filter should also allow for anchors with text.

I think that current way how filter works is invalid. Filter should not remove anchors with but instead let them go through and if user decides to remove (putting text in anchor is probably not very popular) or edit text of such anchor he should have this possibility through anchor dialog (#9406).

comment:6 Changed 6 years ago by Jakub Ś

@jberkes I think that workaround for you is to remove this part of code:

if(P&&!P.href&&P.name)delete O.name;else

that way you will be able to paste such tags.

If you get any errors after this change it would be nice if you could report them here.

comment:7 Changed 6 years ago by Jake Berkes

I have applied the workaround as recommended and can confirm that it does work properly. I apologize if this is an unnecessary comment but I wanted to provide confirmation in case it might help others.

comment:8 Changed 5 years ago by Teresa Monahan

Cc: monahant@… added
Keywords: IBM added

Can a fix for this be incorporated into an official release? Anchors are still getting removed from content pasted from Word in CKEditor 4.x builds.

comment:9 Changed 5 years ago by Frederico Caldeira Knabben

Milestone: CKEditor 4.2.1

It looks like the code that is filtering these anchors is a bit outdated. It's there because of #3582, which is not any more an issue.

This needs to be reviewed and we should be able to have anchors working at that point.

comment:10 Changed 5 years ago by Frederico Caldeira Knabben

Component: GeneralCore : Pasting

comment:11 Changed 5 years ago by Piotrek Koszuliński

Owner: set to Piotrek Koszuliński
Status: confirmedassigned

comment:12 Changed 5 years ago by Piotrek Koszuliński

Status: assignedreview

Pushed t/9330 on dev and tests.

I fixed two things:

  1. PFW filter stripping anchors.
  2. No fix for link's to anchor absolute path on IE.

Branch t/9330 on tests shares one commit with #8103 ticket (t/8103) which is on review too.

comment:13 Changed 5 years ago by Jakub Ś

Status: reviewreview_passed

Only Opera filters anchor and pastes below:

<p><a href="#Anchor1">Link to text below.</a></p>
<p>Anchor for text above.</p>

instead of pasting:

<p><a href="#Anchor1">Link to text below.</a></p>
<p><a name="Anchor1">Anchor for text above.</a></p>

as explained by @Reinmar this will be gone when official Opera on Blink engine will be released.

comment:14 Changed 5 years ago by Piotrek Koszuliński

Resolution: fixed
Status: review_passedclosed

Fixed on master with git:bde01c9 and f029dec on tests.

comment:15 Changed 5 years ago by Frederico Caldeira Knabben

Component: Core : PastingPlugin : Paste from Word
Note: See TracTickets for help on using tickets.
© 2003 – 2017 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy