This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eliminate duplication of static markup for editor by doing basic de-a…
…mplification
- Loading branch information
1 parent
912f8c2
commit 2feb47a
Showing
2 changed files
with
97 additions
and
122 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,22 @@ | ||
|
||
const elementMapping = { | ||
'amp-img': 'img' | ||
}; | ||
|
||
/** | ||
* De-AMP a React component. | ||
* | ||
* @param {wp.element.Component|string} element Element or string. | ||
* @return {wp.element.Component|string} Transformed element or string. | ||
*/ | ||
export function deamplifiy( element ) { | ||
if ( 'string' === typeof element ) { | ||
return element; | ||
} | ||
const htmlElement = elementMapping[ element.type ]; | ||
if ( htmlElement ) { | ||
return wp.element.createElement( elementMapping[ element.type ], element.props, wp.element.Children.map( element.props.children, deamplifiy ) ); | ||
} else { | ||
return wp.element.cloneElement( element, element.props, wp.element.Children.map( element.props.children, deamplifiy ) ); | ||
} | ||
} |
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