Bug #22512
closedhtmlArea RTE: Tables may get lost when using remove format feature
0%
Description
If you copy and paste some word content with a table and use the word copy content clean up feature -> "Remove format" button, the table get lost.
If i just save the document without using the "Remove format" feature everything will be saved correctly but ugly.
(issue imported from #M14202)
Files
Updated by Stanislas Rolland over 14 years ago
What version of TYPO3 and what version of what browser?
Updated by Dimitri Koenig over 14 years ago
i could isolate the problem at least to the line "140" in remove-format.js where it's about "keep tags, strip attributes"
Updated by Dimitri Koenig over 14 years ago
ok, i found a solution but it's a very interesting one.
these are the original lines:
// keep tags, strip attributes
var regMS3 = new RegExp(" style=\"[^>\"]*\"", "gi");
var regMS4 = new RegExp(" (class|align)=(([^>\s\"]+)|(\"[^>\"]*\"))", "gi");
these are the fixed ones:
// keep tags, strip attributes
var regMS3 = new RegExp("style=\"[^>\"]*\"", "gi");
var regMS4 = new RegExp("(class|align)=(([^>\s\"]+)|(\"[^>\"]*\"))", "gi");
i just removed a whitespace and that's it. but how will this affect some other stuff?
Updated by Stanislas Rolland over 14 years ago
Please try
var regMS4 = new RegExp(" (class|align)=\"[^>\"]*\"", "gi");
without changing the other line.
Updated by Rik Wasmus over 14 years ago
Shouldn't that be:
var regMS4 = new RegExp("( |\t|\n)(class|v?align)=\"[^>\"]*\"", "gi");
An HTML-tag can be spread out over several lines, and if an attribute can start at the beginning that line, hence a newline (\r, \n) instead of a space (or in general, tabs for that matter).
Removing the leading whitespace all together would work in about 99% of cases, but in HTML5 custom attributes are allowed AFAIK, so let's take it into account.
<script type="text/javascript">
var re_space = new RegExp(" (class|v?align)=\"[^>\"]*\"", "gi");
var re_whitespace = new RegExp("( |\t|\n)(class|v?align)=\"[^>\"]*\"", "gi");
alert('<input\nclass="bar"/>'.replace(re_space,''));
alert('<input class="bar"/>'.replace(re_space,''));
alert('<input class="bar"/>'.replace(re_space,''));
alert('<input\nclass="bar"/>'.replace(re_whitespace,''));
alert('<input class="bar"/>'.replace(re_whitespace,''));
alert('<input class="bar"/>'.replace(re_whitespace,''));
</script>
Updated by Dimitri Koenig over 14 years ago
@Stanislas: that works too, thanks.
I wonder why i get different results in Firefox 3.6 and IE8... any ideas?
Updated by Stanislas Rolland over 14 years ago
@Dimitri : In what way are the results different? Do you mean the results of the paste or the results of the remove format operation? Certainly, if you paste content from MS Word, all browsers will do it differently.
Updated by Stanislas Rolland over 14 years ago
@Rik: yes, but newlines are replaced by spaces a few instruction before. Not tabs, though. The attached patch will fix this.
Updated by Stanislas Rolland over 14 years ago
Committed to SVN TYPO3core trunk (revision 7565) and branch TYPO3_4-3 (revision 7566).