-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comment, test, clean up Do not allow figures without embedded content Adjust getContentSchema signature Destructure where possible Fix typo Add test for 315819d Move schemas to blocks Simplify Restore iframe filter Add Markdown integration test Address feedback Separate Markdown converter Remove unneeded nodeType checks
- Loading branch information
Showing
57 changed files
with
1,134 additions
and
891 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,88 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { has } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { isPhrasingContent } from './utils'; | ||
|
||
/** | ||
* Whether or not the given node is figure content. | ||
* | ||
* @param {Node} node The node to check. | ||
* @param {Object} schema The schema to use. | ||
* | ||
* @return {boolean} True if figure content, false if not. | ||
*/ | ||
function isFigureContent( node, schema ) { | ||
const tag = node.nodeName.toLowerCase(); | ||
|
||
// We are looking for tags that can be a child of the figure tag, excluding | ||
// `figcaption` and any phrasing content. | ||
if ( tag === 'figcaption' || isPhrasingContent( node ) ) { | ||
return false; | ||
} | ||
|
||
return has( schema, [ 'figure', 'children', tag ] ); | ||
} | ||
|
||
/** | ||
* Whether or not the given node can have an anchor. | ||
* | ||
* @param {Node} node The node to check. | ||
* @param {Object} schema The schema to use. | ||
* | ||
* @return {boolean} True if it can, false if not. | ||
*/ | ||
function canHaveAnchor( node, schema ) { | ||
const tag = node.nodeName.toLowerCase(); | ||
|
||
return has( schema, [ 'figure', 'children', 'a', 'children', tag ] ); | ||
} | ||
|
||
/** | ||
* This filter takes figure content out of paragraphs, wraps it in a figure | ||
* element, and moves any anchors with it if needed. | ||
* | ||
* @param {Node} node The node to filter. | ||
* @param {Document} doc The document of the node. | ||
* @param {Object} schema The schema to use. | ||
* | ||
* @return {void} | ||
*/ | ||
export default function( node, doc, schema ) { | ||
if ( ! isFigureContent( node, schema ) ) { | ||
return; | ||
} | ||
|
||
let nodeToInsert = node; | ||
const parentNode = node.parentNode; | ||
|
||
// If the figure content can have an anchor and its parent is an anchor with | ||
// only the figure content, take the anchor out instead of just the content. | ||
if ( | ||
canHaveAnchor( node, schema ) && | ||
parentNode.nodeName === 'A' && | ||
parentNode.childNodes.length === 1 | ||
) { | ||
nodeToInsert = node.parentNode; | ||
} | ||
|
||
let wrapper = nodeToInsert; | ||
|
||
while ( wrapper && wrapper.nodeName !== 'P' ) { | ||
wrapper = wrapper.parentElement; | ||
} | ||
|
||
const figure = doc.createElement( 'figure' ); | ||
|
||
if ( wrapper ) { | ||
wrapper.parentNode.insertBefore( figure, wrapper ); | ||
} else { | ||
nodeToInsert.parentNode.insertBefore( figure, nodeToInsert ); | ||
} | ||
|
||
figure.appendChild( nodeToInsert ); | ||
} |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { remove } from '@wordpress/utils'; | ||
|
||
/** | ||
* Removes iframes. | ||
* | ||
* @param {Node} node The node to check. | ||
* | ||
* @return {void} | ||
*/ | ||
export default function( node ) { | ||
if ( node.nodeName === 'IFRAME' ) { | ||
remove( node ); | ||
} | ||
} |
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
Oops, something went wrong.