-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iframe raw handling (e.g. Google Maps) (#4660)
* Allow pasting iframes (squashed 7 commits) * Polish
- Loading branch information
Showing
12 changed files
with
139 additions
and
37 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { isEmbedded } from './utils'; | ||
|
||
/** | ||
* Browser dependencies | ||
*/ | ||
const { ELEMENT_NODE } = window.Node; | ||
|
||
/** | ||
* This filter takes embedded content out of paragraphs. | ||
* | ||
* @param {Node} node The node to filter. | ||
* | ||
* @return {void} | ||
*/ | ||
export default function( node ) { | ||
if ( node.nodeType !== ELEMENT_NODE ) { | ||
return; | ||
} | ||
|
||
if ( ! isEmbedded( node ) ) { | ||
return; | ||
} | ||
|
||
let wrapper = node; | ||
|
||
while ( wrapper && wrapper.nodeName !== 'P' ) { | ||
wrapper = wrapper.parentElement; | ||
} | ||
|
||
if ( wrapper ) { | ||
wrapper.parentNode.insertBefore( node, wrapper ); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
blocks/api/raw-handling/test/embedded-content-corrector.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,12 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import embeddedContentReducer from '../embedded-content-reducer'; | ||
import { deepFilterHTML } from '../utils'; | ||
|
||
describe( 'embeddedContentReducer', () => { | ||
it( 'should move embedded content from paragraph', () => { | ||
expect( deepFilterHTML( '<p><strong>test<img class="one"></strong><img class="two"></p>', [ embeddedContentReducer ] ) ) | ||
.toEqual( '<img class="one"><img class="two"><p><strong>test</strong></p>' ); | ||
} ); | ||
} ); |
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 @@ | ||
<iframe src="https://www.google.com/maps/embed" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe> |
3 changes: 3 additions & 0 deletions
3
blocks/api/raw-handling/test/integration/iframe-embed-out.html
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,3 @@ | ||
<!-- wp:html --> | ||
<iframe src="https://www.google.com/maps/embed" width="600" height="450" allowfullscreen=""></iframe> | ||
<!-- /wp:html --> |
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
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