Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#35514 closed defect (bug) (invalid)

Shortcodes escape from HTML tables

Reported by: grzegorzjanoszka's profile Grzegorz.Janoszka Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: TinyMCE Keywords: 2nd-opinion
Focuses: Cc:

Description (last modified by ocean90)

I have WP 4.4.1 and I am trying to use shortcodes with different arguments to create repetitive content, like rows in HTML tables. The problem is the editor removes the block from between <table> and </table> if it is not within <td> or <th> tags.

Example, I have a shortcode that displays a nice HTML output containing a table row starting with <tr> and ending with </tr>.

I open a new post, go to the text editor and type:

<table>
<tbody>
[tablerow param1=blah param2=blah]
</tbody>
</table>

Then I switch to the visual editor and back to text editor and I see:

<table>
<tbody></tbody>
</table>

When I try to add some more content to the table, like:

<table>
<tbody>
<tr><td>Initial data</td></tr>
[tablerow param1=blah param2=blah]
</tbody>
</table>

it is being changed to:

[tablerow param1=blah param2=blah]
<table>
<tbody>
<tr>
<td>Initial data</td>
</tr>
</tbody>
</table>

There is workaround to avoid putting <table> in the editor, but you have to use more shortcodes and no HTML code:

[shortcode with table header]
[shortcode with table row]
[shortcode with table row]
[shortcode with table row]
[shortcode with table row]
[shortcode with table footer]

but it is not very handy.

Is it possible that shortcodes are not moved out or removed from within <table> tags? They may simplify a lot creating repetitive content, including tables in Wordpress, but now it is difficult to achieve it with shortcodes.

I think it is related to TinyMCE, so I have assigned this ticket to this component. Please feel free to reassign it.

Thank you in advance for looking into it.

Change History (3)

#1 @ocean90
8 years ago

  • Description modified (diff)
  • Keywords 2nd-opinion added; html table shortcode removed
  • Version 4.4.1 deleted

Hello @Grzegorz.Janoszka, welcome to Trac!

Thanks for your report, I could reproduce the issue on the demo site at https://www.tinymce.com/docs/demo/basic-example/ and also in other versions of WordPress. I'm not sure if core or TinyMCE can do something to prevent this behaviour since the HTML markup isn't valid.

#2 @Grzegorz.Janoszka
8 years ago

Thank you for reeditting my initial post. Indeed the HTML markup is not valid, but if you let shortcodes in, you can never ensure full HTML validity as shortcodes can enter any HTML code.

For me ideally would be if TinyMCE could check and fix HTML if no shortcodes are used. If there is a block with a broken HTML _and_ shortcodes, the editor can mark it as a potential error, but it shouldn't attempt to fix it.

What is interesting, TinyMCE is not so strict when it comes to other pieces of HTML code, for example:

<ul>
[listitem id=3]
[listitem id=4]
</ul>

is allowed.

#3 @azaozz
8 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi @Grzegorz.Janoszka, don't think we can fix this. In HTML context all shortcodes are "plain text". Looking at the examples, you are adding text inside <tbody> which is invalid HTML, so it gets removed on cleanup. I'm not sure why you don't want to insert the <tr> and <td> but the HTML has to be valid inside the editor.

Note: See TracTickets for help on using tickets.