Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 1x 20x 20x 20x 20x 20x 20x 15x 5x 16x 16x 20x 20x 15x 1x | /* global $ */ /** * Find first paragraph that has text content, i.e. paragraphs that are not empty. * Keep in sync with MoveLeadParagraphTransform::identifyLeadParagraph(). * * @private * @param {jQuery} $body Where to search for paragraphs * @return {Node|null} The lead paragraph */ module.exports = function identifyLeadParagraph( $body ) { // Keep in sync with MoveLeadParagraphTransform::isNotEmptyNode() function isNotEmptyNode( node ) { // Ignore VE whitespace characters return !/^[\s↵➞]*$/.test( node.textContent ); } // Keep in sync with MoveLeadParagraphTransform::isNonLeadParagraph() function isNonLeadParagraph( node ) { node = node.cloneNode( true ); const $node = $( node ); // The paragraph itself can be an invisible template (T293834) Iif ( $node.hasClass( 've-ce-focusableNode-invisible' ) ) { return true; } // Ignore non-content nodes, TemplateStyles and coordinates $node.find( '.ve-ce-branchNode-inlineSlug, .ve-ce-focusableNode-invisible, style, span#coordinates' ).remove(); if ( isNotEmptyNode( node ) ) { return false; } return true; } const $paragraphs = $body.children( 'p' ); for ( let i = 0; i < $paragraphs.length; i++ ) { const p = $paragraphs[ i ]; if ( !isNonLeadParagraph( p ) ) { return p; } } return null; }; |