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

Transform pasted div tags to p tags #38042

Merged
merged 5 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/blocks/src/api/raw-handling/div-normaliser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Internal dependencies
*/
import normaliseBlocks from './normalise-blocks';

export default function divNormaliser( node ) {
if ( node.nodeName !== 'DIV' ) {
return;
}

node.innerHTML = normaliseBlocks( node.innerHTML );
}
2 changes: 2 additions & 0 deletions packages/blocks/src/api/raw-handling/paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import msListConverter from './ms-list-converter';
import listReducer from './list-reducer';
import imageCorrector from './image-corrector';
import blockquoteNormaliser from './blockquote-normaliser';
import divNormaliser from './div-normaliser';
import figureContentReducer from './figure-content-reducer';
import shortcodeConverter from './shortcode-converter';
import markdownConverter from './markdown-converter';
Expand Down Expand Up @@ -192,6 +193,7 @@ export function pasteHandler( {
iframeRemover,
figureContentReducer,
blockquoteNormaliser,
divNormaliser,
];

const schema = {
Expand Down
1 change: 1 addition & 0 deletions test/integration/blocks-raw-handling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ describe( 'Blocks raw handling', () => {
[
'plain',
'classic',
'nested-divs',
'apple',
'google-docs',
'google-docs-table',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fixtures/documents/evernote-in.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
</div></td><td style="border: 1px solid rgb(219, 219, 219);"><div>Five
</div></td><td style="border: 1px solid rgb(219, 219, 219);"><div>Six
</div></td>
</tr></tbody></table><div><img name="en-media:image/jpeg:65a793f8561f84729d27425384062867:none:none" src="data:image/jpeg;base64,###" /></div></div>
</tr></tbody></table><div><img name="en-media:image/jpeg:65a793f8561f84729d27425384062867:none:none" src="data:image/jpeg;base64,###" /></div></div>
6 changes: 5 additions & 1 deletion test/integration/fixtures/documents/evernote-out.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<!-- wp:paragraph -->
<p>This is a <em>paragraph</em>.<br>This is a <a href="https://w.org">link</a>.</p>
<p>This is a <em>paragraph</em>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This is a <a href="https://w.org">link</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
Expand Down
12 changes: 12 additions & 0 deletions test/integration/fixtures/documents/nested-divs-in.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div>
<div>First paragraph</div>
<p><!--more--></p>
<div>Second paragraph</div>
<div>
<div>Third paragraph</div>
</div>
</div>

<p>Fourth <!--more--> paragraph</p>
<p>Fifth paragraph</p>
<p>Sixth paragraph</p>
31 changes: 31 additions & 0 deletions test/integration/fixtures/documents/nested-divs-out.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!-- wp:paragraph -->
<p>First paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:paragraph -->
<p>Second paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Third paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Fourth paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:paragraph -->
<p>Fifth paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Sixth paragraph</p>
<!-- /wp:paragraph -->