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

Remove (non-special) comment nodes when pasting content #15557

Merged
merged 4 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions packages/blocks/src/api/raw-handling/comment-remover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* WordPress dependencies
*/
import { remove } from '@wordpress/dom';

/**
* Browser dependencies
*/
const { COMMENT_NODE } = window.Node;

/**
* Looks for comments, and removes them.
*
* @param {Node} node The node to be processed.
* @return {void}
*/
export default function( node ) {
if ( node.nodeType === COMMENT_NODE ) {
remove( node );
}
}
4 changes: 3 additions & 1 deletion packages/blocks/src/api/raw-handling/paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getBlockContent } from '../serializer';
import { getBlockAttributes, parseWithGrammar } from '../parser';
import normaliseBlocks from './normalise-blocks';
import specialCommentConverter from './special-comment-converter';
import commentRemover from './comment-remover';
import isInlineContent from './is-inline-content';
import phrasingContentReducer from './phrasing-content-reducer';
import headRemover from './head-remover';
Expand Down Expand Up @@ -44,7 +45,7 @@ const { console } = window;
* @return {string} HTML only containing phrasing content.
*/
function filterInlineHTML( HTML ) {
HTML = deepFilterHTML( HTML, [ googleDocsUIDRemover, phrasingContentReducer ] );
HTML = deepFilterHTML( HTML, [ googleDocsUIDRemover, phrasingContentReducer, commentRemover ] );
HTML = removeInvalidHTML( HTML, getPhrasingContentSchema(), { inline: true } );

// Allows us to ask for this information when we get a report.
Expand Down Expand Up @@ -204,6 +205,7 @@ export function pasteHandler( { HTML = '', plainText = '', mode = 'AUTO', tagNam
imageCorrector,
phrasingContentReducer,
specialCommentConverter,
commentRemover,
figureContentReducer,
blockquoteNormaliser,
];
Expand Down