Skip to content

Commit

Permalink
Merge pull request #20734 from Yoast/fix/single-title-marking
Browse files Browse the repository at this point in the history
Fixes incorrect highlighting for H1s with mark-up in the block editor
  • Loading branch information
agnieszkaszuba authored Oct 9, 2023
2 parents dd43a86 + 3f61a96 commit 61cb59a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/js/src/decorator/gutenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function removeAllAnnotationsFromBlock( blockClientId ) {
* @returns {void}
*/
export function reapplyAnnotationsForSelectedBlock() {
const block = select( "core/editor" ).getSelectedBlock();
const block = select( "core/block-editor" ).getSelectedBlock();
const activeMarkerId = select( "yoast-seo/editor" ).getActiveMarker();

if ( ! block || ! activeMarkerId ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,21 @@ describe( "An assessment to check whether there is more than one H1 in the text"

describe( "A test for marking incorrect H1s in the body", function() {
it( "returns markers for incorrect H1s in the body", function() {
const mockPaper = new Paper( "<p>a paragraph</p><h1>heading</h1>" );
const mockPaper = new Paper( "<p>a paragraph</p><h1>this is a <strong>heading</strong></h1>" );
const mockResearcher = new EnglishResearcher( mockPaper );
buildTree( mockPaper, mockResearcher );
h1Assessment.getResult( mockPaper, mockResearcher );

const expected = [
new Mark( {
original: "<h1>heading</h1>",
marked: "<h1><yoastmark class='yoast-text-mark'>heading</yoastmark></h1>",
original: "<h1>this is a heading</h1>",
marked: "<h1><yoastmark class='yoast-text-mark'>this is a heading</yoastmark></h1>",
position: {
startOffset: 22,
endOffset: 29,
clientId: "",
endOffsetBlock: 7,
startOffset: 22,
endOffset: 56,
startOffsetBlock: 0,
endOffsetBlock: 34,
} } ),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SingleH1Assessment extends Assessment {
startOffset: h1.position.startOffset,
endOffset: h1.position.endOffset,
startOffsetBlock: 0,
endOffsetBlock: h1.content.length,
endOffsetBlock: h1.position.endOffset - h1.position.startOffset,
clientId: h1.position.clientId,
},
} );
Expand Down

0 comments on commit 61cb59a

Please sign in to comment.