Opened 9 years ago
Closed 9 years ago
#16811 closed Bug (fixed)
No table align when pasted from Word
| Reported by: | Marek Lewandowski | Owned by: | Marek Lewandowski |
|---|---|---|---|
| Priority: | Nice to have (we want to work on it) | Milestone: | CKEditor 4.7.0 |
| Component: | General | Version: | 4.6.0 |
| Keywords: | Cc: |
Description (last modified by )
Steps to reproduce
- Open attached
Table_alignment.docxdocument in Word. - Copy it's content.
- Paste into a full featured editor.
Expected result
Tables are aligned as in the docx document.
Actual result
Alignments are stripped.
More details
It looks in Word pretty much like this:
The problem is that Word generates following markup:
<div align=right> <table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 style='(...)'> <tr style='(...)'> (...) </tr> </table> </div>
Which displays it correctly, but uses deprecated align attribute.
We have a style transformation in core which transforms any align into float CSS prop, which is fine for elements like table, img, iframe, but it's wrong for div and p. Becasue for div and p it defines the alignment of content elements within this element.
It's also worth to remember that align is a little more aggresive than text-align CSS prop, as it affects anything, whereas for text-align you need to apply margin: x auto for block-alike elements, otherwise they won't be aligned.
Attachments (1)
Change History (9)
Changed 9 years ago by
| Attachment: | Table_alignment.docx added |
|---|
comment:1 Changed 9 years ago by
| Status: | new → confirmed |
|---|
comment:2 Changed 9 years ago by
| Description: | modified (diff) |
|---|
comment:3 Changed 9 years ago by
comment:4 Changed 9 years ago by
| Priority: | Normal → Must have (possibly next milestone) |
|---|
TBH, I'd go with the simplest solution which is possible to implement.
- Is it possible to just wrap a table into
<div overflow:hidden>and<table float:right>? When the user changes alignment to left, or anything else, the algorithm would discover that<div>(one child (table) && one attribute (style) && one value (ov:hidden)) and remove it or take care of it so the new structure reflects the needs of the alignment?
- Is
<table float: right; clear: both;>an option? Would it work?
- It sounds like a use nice case for widgets: magical alignment old
alignin the V(editing)-layer and floats/wrappers in the editor output (model)–layer. WDYT?
comment:5 Changed 9 years ago by
Thanks for the thoughts @a.nowodzinski.
Out of curiosity checked approach 2. and without overflow:hidden it doesn't consume vertical space: http://codepen.io/mlewand/pen/OWgJbp
We've had a lot of discussion on this, and we came to conclusion that in fact we can't create a markup that we don't support in editor. Look at div[align] if we implement it, the end user has now way to control it's alignment. That doesn't make sense. Instead we'll provide a handling that is as close to expected as it could be, which means to align the table itself to a given position, so that it can be changed using tabletools dialog.
comment:6 Changed 9 years ago by
| Priority: | Must have (possibly next milestone) → Nice to have (we want to work on it) |
|---|
comment:7 Changed 9 years ago by
| Owner: | set to Marek Lewandowski |
|---|---|
| Status: | confirmed → review |
Pushed to branch:t/16811.
comment:8 Changed 9 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | review → closed |
Overall the fix looks good to me, especially that the alternative method - using replaceWithChildren - is notorious for not cooperating with the filter.


We can't convert it to
floatalone as it would allow for wrapping text around the table.My through here is to go with simplest possible option, so let for
div[align]where that's necessary.