#22477 closed defect (bug) (fixed)
The WYSIWYG editor deletes empty em, strong, b, i tags
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5.1 |
| Component: | TinyMCE | Version: | 3.5 |
| Severity: | normal | Keywords: | |
| Cc: | mdhansen@…, ruud@… |
Description
I recently was working on a clients website and used a span tag to insert an image true CSS and after I viewed the content in visual and switched in html mode all my empty span tags ware gone..
Change History (21)
comment:1
MikeHansenMe — 6 months ago
- Cc mdhansen@… added
comment:2
SergeyBiryukov — 6 months ago
- Component changed from General to TinyMCE
Thank you I changed the editor but this is a problem that needs to be solved at some point. I will be glad to help out it seams that the general editor has issues rendering the HTML visual. I just found another problem with the <tr> tag if you put a space like < tr> it will change it to "<tr >" I'm not sure if this is a bug.. I know writing code on the page directly is not the right way but I'm forced to do it sometimes...
- Keywords close added
Yes, TinyMCE treats all empty elements that don't have meaning in html as empty space, same as browsers treat them. <span></span>, <div></div>, even <p></p> are not displayed in the browser. If they have any attributes, they are not removed.
< tr> is invalid html, you can't have a space after the opening <. You can have space before the closing >, so <tr > is valid and works as expected.
comment:5
in reply to:
↑ 4
SergeyBiryukov — 5 months ago
Replying to azaozz:
<span></span>, <div></div>, even <p></p> are not displayed in the browser. If they have any attributes, they are not removed.
From my testing, <div></div> actually persists even without an attribute.
However, <span class="test"></span> disappears anyway.
comment:6
SergeyBiryukov — 5 months ago
Related: #23037
- Cc ruud@… added
Tried something similar as Sergey:
3.4.2: <i class="test"></i> gets 'translated' into <em class="test"></em>
3.5: <i class="test"></i> disappears
- Milestone changed from Awaiting Review to 3.5.1
- Severity changed from normal to major
Replying to azaozz:
Yes, TinyMCE treats all empty elements that don't have meaning in html as empty space, same as browsers treat them. <span></span>, <div></div>, even <p></p> are not displayed in the browser. If they have any attributes, they are not removed.
Apparently that's not entirely the case, see comment:7.
Yeah, that's wrong.
A list of elements to remove when empty is defined in TinyMCE's Schema class: http://core.trac.wordpress.org/browser/trunk/wp-includes/js/tinymce/wp-tinymce-schema.js#L705
Also replacing <i> with <em> and <b> with <strong> is affected by the schema. In 'html5' they are not replaced: http://core.trac.wordpress.org/browser/trunk/wp-includes/js/tinymce/wp-tinymce-schema.js#L694
The elements listed for removal when empty 'ol,ul,sub,sup,blockquote,span,font,a,table,tbody,tr,strong,em,b,i' will not be removed if they have an id or name attribute: https://github.com/tinymce/tinymce/blob/master/jscripts/tiny_mce/classes/html/DomParser.js#L516
So we have couple of options: edit the "remove when empty" list in the Schema class and/or extend the DomParser class to not remove these elements when they have any attribute (both would be good to submit for merging upstream).
comment:10
azaozz — 5 months ago
#23037 was marked as a duplicate.
comment:11
nacin — 5 months ago
Per IRC with azaozz:
- Deleting <span> tags is not a regression. Leave this for 3.6 or later. We can possibly submit a patch for TinyMCE's DomParser to leave removeEmpty elements that still have certain other attributes (class, specifically) just as it handles id and name.
- For 3.5.1, revert https://github.com/tinymce/tinymce/commit/6e2a6b5ff657f58c66859256f4ad87f4d9f27423 to restore TinyMCE 3.4.9 (and WP 3.4) behavior. We should be able to make this change in our wp-tinymce-schema.js file.
comment:12
follow-up:
↓ 20
hali6sic6 — 5 months ago
- Type changed from defect (bug) to enhancement
I just create a template page when I'm using advanced html/css... What could be a nice fix is a html tag inside tinyMCE like
[DONT_FORMAT]DONT_FORMAT
And inside these tags there will be no formatting it will simply generate the html inside without touching it...
comment:13
azaozz — 5 months ago
- Owner set to azaozz
- Resolution set to fixed
- Status changed from new to closed
In 23221:
comment:14
azaozz — 5 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopen for trunk.
This doesn't fix removal of empty spans, only restores the TinyMCE behavior for <i>, <b>, <em> and <strong>. There are other fixes/improvements that are needed, so leaving this open until these are patched upstream.
comment:15
azaozz — 5 months ago
- Milestone changed from 3.5.1 to Future Release
- Severity changed from major to normal
comment:16
azaozz — 5 months ago
In 23222:
comment:17
azaozz — 5 months ago
For reference: [23222] reverts this commit in TinyMCE:
https://github.com/tinymce/tinymce/commit/6e2a6b5ff657f58c66859256f4ad87f4d9f27423
comment:18
nacin — 5 months ago
- Keywords close removed
- Milestone changed from Future Release to 3.5.1
- Resolution set to fixed
- Status changed from reopened to closed
- Summary changed from The WYSIWYG editor deletes all empty <span> tags to The WYSIWYG editor deletes empty em, strong, b, i tags
- Version changed from 3.4.2 to 3.5
Hijacking this ticket, that way milestone:3.5.1 is an accurate reflection of all of its changes.
We can open a new ticket for the upstream adjustments.
comment:19
SergeyBiryukov — 5 months ago
- Type changed from enhancement to defect (bug)
comment:20
in reply to:
↑ 12
azaozz — 5 months ago
Replying to hali6sic6:
...And inside these tags there will be no formatting it will simply generate the html inside without touching it...
Thinking you're looking for "previews" that use elements with contenteditable="false" inside the editor. That prevents any editing/changes in them. This is on the "to do" list: #21812.
comment:21
ruud@… — 5 months ago
Thanks for the fixes! this allows me to use twitter-bootstrap icons by using the method shown on their site. see #23037

I was able to reproduce this. It seems to only happen when switching between visual and text tabs. If you edit in text and add <span></span> the publish/update it does save the tag.