Sunday, 15 January 2012

javascript - Chrome inserts non-breaking spaces into copy and pasted content -


I'm talking about content inside a contentedable div, and the goal is the same contenteditable div so no external program Not included.

The structure of HTML in this div is that we have a span with some data to track each word. Then the white space is left as the text nodes between the spaces. It works fine for most part (you make new screws) but I have to face a strange problem while copying and pasting.

Chrome turns it on

  & lt; Span attrs = "luggage" & gt; The word & lt; / Span & gt; & Lt; Span attrs = "luggage" & gt; Another & lt; / Span & gt;  

In:

  & lt; Span attrs = "stuff" & gt; Words & amp; Nbsp; & Lt; / Span & gt; & Lt; Span attrs = "luggage" & gt; Another & lt; / Span & gt;  

Or this:

  & lt; Span attrs = "stuff" & gt; The word & lt; / Span & gt; & Lt; Span style = "row-height: 16.79999" & gt; & Amp; Nbsp; & Lt; / Span & gt; & Lt; Span etter = "luggage" & gt; Another & lt; / Span & gt;  

It clearly means that if the user copies and pastes in more than one line, then the formatting gets completely defective, and the content of the duration has changed Invalidates the data that we need to track.

The main problem is that in other parts of the div, non-breaking spaces may be included for real reasons, so if I start swapping them globally, then I can break it I am

My spawn with my ethers, so I know what they should be so easy to touch and restore non-breaking spaces. But with the height of the strange line for these strange spans, I do not know how to clean everything without any things.

Right now, I've snatched all the included spans in which only one non-breaking space But in reality I really want Chrome to stop it from doing so in the first place, or to have a clear means to identify the problematic additional spans, so that I can break them without any kind of spans present for real reasons Can I clean in security I can guess this strange line-height, but it looks very brittle and unsafe.

How can I see Span or not recognize it clearly?

The problem is not just Chrome problem, whenever you copy the HTML code, something like this can happen is.

That's why you can use editors like CKEdit. They have advanced filtering technologies to remove such bad HTML code.

I recommend using a clipboard program to see when the HTML code is when you copy from different locations:

but implement it In my opinion there will be a waste of time.

CKEditor can be configured very well to prevent bad HTML code.

Recent editions of CKAditor are very refined content filtering approaches. This is called "advanced content filter".

Actually "Advanced Content Filter" means: the entire HTML code is parsed or checked. There is no rule in this case that matches the given HTML code, it is filtered is done.


No comments:

Post a Comment