-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Support colspan
attribute in table
HTML, including when pasting
#45981
Merged
danielbachhuber
merged 4 commits into
WordPress:trunk
from
mpkelly:add/colspan-support-to-tables
Nov 30, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
packages/blocks/src/api/raw-handling/test/paste-handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { pasteHandler } from '@wordpress/blocks'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { init as initAndRegisterTableBlock } from '../../../../../block-library/src/table'; | ||
|
||
const tableWithHeaderFooterAndBodyUsingColspan = ` | ||
<table> | ||
<thead> | ||
<tr> | ||
<th colspan="2">Colspan 2</th> | ||
<th>Header Cell</th> | ||
</tr> | ||
</thead> | ||
<tfoot> | ||
<tr> | ||
<th colspan="2">Footer Cell</th> | ||
<th>Footer Cell</th> | ||
</tr> | ||
</tfoot> | ||
<tbody> | ||
<tr> | ||
<td colspan="2">Colspan 2</td> | ||
<td>Cell Data</td> | ||
</tr> | ||
</tbody> | ||
</table>`; | ||
|
||
const googleDocsTableWithColspan = ` | ||
<meta charset="utf-8"><b style="font-weight:normal;" id="docs-internal-guid-b0f68bdd-7fff-a054-94d1-43c2fdedca2a"> | ||
<div dir="ltr" style="margin-left:0pt;" align="left"> | ||
<table style="border:none;border-collapse:collapse;"> | ||
<colgroup> | ||
<col width="185"/> | ||
<col width="439"/> | ||
</colgroup> | ||
<tbody> | ||
<tr style="height:21pt"> | ||
<td colspan="2" | ||
style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:5pt 5pt 5pt 5pt;overflow:hidden;overflow-wrap:break-word;"> | ||
<p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt;"><span | ||
style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Test colspan</span> | ||
</p></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
<br/><br/></b> | ||
`; | ||
|
||
describe( 'pasteHandler', () => { | ||
beforeAll( () => { | ||
initAndRegisterTableBlock(); | ||
} ); | ||
|
||
it( 'can handle a table with thead, tbody and tfoot using colspan', () => { | ||
const [ result ] = pasteHandler( { | ||
HTML: tableWithHeaderFooterAndBodyUsingColspan, | ||
tagName: 'p', | ||
preserveWhiteSpace: false, | ||
} ); | ||
|
||
expect( console ).toHaveLogged(); | ||
|
||
expect( result.attributes ).toEqual( { | ||
hasFixedLayout: false, | ||
caption: '', | ||
head: [ | ||
{ | ||
cells: [ | ||
{ content: 'Colspan 2', tag: 'th', colspan: '2' }, | ||
{ content: 'Header Cell', tag: 'th' }, | ||
], | ||
}, | ||
], | ||
body: [ | ||
{ | ||
cells: [ | ||
{ content: 'Colspan 2', tag: 'td', colspan: '2' }, | ||
{ content: 'Cell Data', tag: 'td' }, | ||
], | ||
}, | ||
], | ||
foot: [ | ||
{ | ||
cells: [ | ||
{ content: 'Footer Cell', tag: 'th', colspan: '2' }, | ||
{ content: 'Footer Cell', tag: 'th' }, | ||
], | ||
}, | ||
], | ||
} ); | ||
expect( result.name ).toEqual( 'core/table' ); | ||
expect( result.isValid ).toBeTruthy(); | ||
} ); | ||
|
||
it( 'can handle a google docs table with colspan', () => { | ||
const [ result ] = pasteHandler( { | ||
HTML: googleDocsTableWithColspan, | ||
tagName: 'p', | ||
preserveWhiteSpace: false, | ||
} ); | ||
|
||
expect( console ).toHaveLogged(); | ||
|
||
expect( result.attributes ).toEqual( { | ||
body: [ | ||
{ | ||
cells: [ | ||
{ | ||
align: undefined, | ||
colspan: '2', | ||
content: 'Test colspan', | ||
scope: undefined, | ||
tag: 'td', | ||
}, | ||
], | ||
}, | ||
], | ||
caption: '', | ||
foot: [], | ||
hasFixedLayout: false, | ||
head: [], | ||
} ); | ||
expect( result.name ).toEqual( 'core/table' ); | ||
expect( result.isValid ).toBeTruthy(); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: this maybe makes more sense to add to the integration tests, which has all blocks loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ellatrix Would it make sense to keep this existing test and add it to integration tests?