Skip to content

Commit

Permalink
add title to iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Sep 16, 2024
1 parent 0efcee4 commit 2254b9d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"Headers": "readonly",
"requestAnimationFrame": "readonly",
"React": "readonly",
"Block": "readonly"
"Block": "readonly",
"DOMParser": "readonly"
},
"extends": ["plugin:@wordpress/eslint-plugin/recommended"],
"ignorePatterns": ["*.json"]
Expand Down
37 changes: 29 additions & 8 deletions src/js/gutenberg-plugins/rewrite-tone-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,24 @@ const InjectIframeStyles = ( { children } ) => {
return;
}

iframeDocument.body.classList.add( 'block-editor-iframe__body', 'editor-styles-wrapper', 'post-type-post', 'admin-color-fresh', 'wp-embed-responsive' );
iframeDocument.body.querySelector( '.is-root-container' ).classList.add( 'is-desktop-preview', 'is-layout-constrained', 'wp-block-post-content-is-layout-constrained', 'has-global-padding', 'alignfull', 'wp-block-post-content', 'block-editor-block-list__layout' );
iframeDocument.body.classList.add(
'block-editor-iframe__body',
'editor-styles-wrapper',
'post-type-post',
'admin-color-fresh',
'wp-embed-responsive'
);
iframeDocument.body
.querySelector( '.is-root-container' )
.classList.add(
'is-desktop-preview',
'is-layout-constrained',
'wp-block-post-content-is-layout-constrained',
'has-global-padding',
'alignfull',
'wp-block-post-content',
'block-editor-block-list__layout'
);

clearInterval( intervalId );
}, 100 );
Expand All @@ -108,6 +124,7 @@ const InjectIframeStyles = ( { children } ) => {
<iframe
ref={ iframeRef }
style={ { width: '100%', height: '100%', border: 'none' } }
title={ __( 'Rewrite tone previewer', 'classifai' ) }
></iframe>
</div>
</>
Expand Down Expand Up @@ -312,17 +329,17 @@ const RewriteTonePlugin = () => {
/**
* Returns HTML string without the outermost tags.
*
* @param {String} htmlContent HTML as string.
* @returns {String} HTML string without outermost tags stripped.
* @param {string} htmlContent HTML as string.
* @return {string} HTML string without outermost tags stripped.
*/
function removeOutermostTag( htmlContent ) {
// Parse the input HTML string into a DOM structure
const parser = new DOMParser();
const doc = parser.parseFromString( htmlContent, 'text/html' );

// Get the first element within the body (this is the outermost element)
const outermostElement = doc.body.firstElementChild;

// Return the innerHTML of the outermost element, which removes the outermost tag
return outermostElement ? outermostElement.innerHTML : htmlContent;
}
Expand Down Expand Up @@ -356,15 +373,19 @@ const RewriteTonePlugin = () => {

let createdBlock = wp.blocks.rawHandler( { HTML: content } );

if ( Array.isArray( createdBlock ) && 1 === createdBlock.length && 'core/html' === createdBlock[0].name ) {
if (
Array.isArray( createdBlock ) &&
1 === createdBlock.length &&
'core/html' === createdBlock[ 0 ].name
) {
createdBlock = createBlock( currentBlock.name, {
content: removeOutermostTag( content ),
} );

return {
clientId,
blocks: [ createdBlock ],
}
};
}

return {
Expand Down

0 comments on commit 2254b9d

Please sign in to comment.