Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table's figcaption/caption elements are not persisted when pasted into the editor #30876

Open
Tracked by #32400
codebymikey opened this issue Apr 15, 2021 · 3 comments
Open
Tracked by #32400
Assignees
Labels
[Block] Table Affects the Table Block [Feature] Raw Handling Related to the ability to convert content to blocks, paste handling, etc [Package] Blocks /packages/blocks [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Bug An existing feature does not function as intended

Comments

@codebymikey
Copy link

Description

When pasting raw HTML into the editor, the figcaption element isn't properly persisted.

This appears to be because the figure element isn't included when pasted in the first place, and this piece of code should have logic in place which attempts to move figcaptions into a figure element if one does exist.

Step-by-step reproduction instructions

  1. Copy following HTML into a tool like https://www.onlinehtmleditor.net/
  2. Copy and paste the formatted HTML into the Gutenberg editor
  3. The figcaption element is moved outside of the original figure element.

The behaviour is also replicable by pasting the formatted HTML into https://wordpress.org/gutenberg/

Expected behaviour

The figcaption should be present as a child of the figure.

Actual behaviour

The figcaption is without a parent and subsequently converted into a p tag.

WordPress information

  • WordPress version: "5.8.0"
  • Gutenberg version: "9.4.0"
  • Are all plugins except Gutenberg deactivated? "Yes"
  • Are you using a default theme (e.g. Twenty Twenty-One)? "Yes"

Device information

  • Device: "Desktop"
  • Operating system: "Windows 10"
  • Browser: "Chrome 86.0"
@dhruvkb
Copy link
Member

dhruvkb commented Apr 16, 2021

Reproduced. Looks like the code responsible for this is

if ( tag === 'figcaption' || isTextContent( node ) ) {

Strangely enough, the markup generated for the table after adding the caption from the UI is identical to the one pasted into the editor.

@dhruvkb dhruvkb added [Block] Table Affects the Table Block [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Bug An existing feature does not function as intended [Feature] Raw Handling Related to the ability to convert content to blocks, paste handling, etc [Package] Blocks /packages/blocks labels Apr 16, 2021
@ellatrix ellatrix self-assigned this May 21, 2021
@joedolson
Copy link
Contributor

Just want to draw attention to #24205, and note that the table caption really shouldn't be using the figcaption element, as well.

@codebymikey
Copy link
Author

This issue also affects normal caption elements too. e.g.

<table>
  <caption><h3>Monthly savings</h3></caption>
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
</table>

We need a way to transform table captions into equivalent figcaptions.

@codebymikey codebymikey changed the title Figure table's figcaption HTML is not persistent when pasted Table's figcaption/caption elements are not persisted when pasted into the editor Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Table Affects the Table Block [Feature] Raw Handling Related to the ability to convert content to blocks, paste handling, etc [Package] Blocks /packages/blocks [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

4 participants