diff --git a/docs/reference-guides/block-api/block-supports.md b/docs/reference-guides/block-api/block-supports.md index 683e4f134d9877..880dd844127105 100644 --- a/docs/reference-guides/block-api/block-supports.md +++ b/docs/reference-guides/block-api/block-supports.md @@ -57,6 +57,15 @@ supports: { } ``` +If this property is set to `true` or `html`, the id attribute of the root element of the saved markup are referenced. If this property is set to `delimiter`, the attribute is saved as a comment delimiter. This value should be used for dynamic blocks that don't save markup. + +```js +// Declare support for anchor links. +supports: { + anchor: 'delimiter' +} +``` + ## align - Type: `boolean` or `array` diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index bf0d3bf71d06f9..0e16a9cb18a240 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -619,7 +619,7 @@ Show minutes required to finish reading the post. ([Source](https://github.com/W - **Name:** core/post-time-to-read - **Experimental:** true - **Category:** theme -- **Supports:** color (background, gradients, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~ +- **Supports:** anchor, color (background, gradients, text), spacing (margin, padding), typography (fontSize, lineHeight), ~~html~~ - **Attributes:** textAlign ## Title diff --git a/lib/block-supports/anchor.php b/lib/block-supports/anchor.php index 8f704a5019b365..7c7842d5cfc3b1 100644 --- a/lib/block-supports/anchor.php +++ b/lib/block-supports/anchor.php @@ -11,8 +11,8 @@ * @param WP_Block_Type $block_type Block Type. */ function gutenberg_register_anchor_support( $block_type ) { - $has_anchor_support = _wp_array_get( $block_type->supports, array( 'anchor' ), true ); - if ( ! $has_anchor_support ) { + $anchor_support = _wp_array_get( $block_type->supports, array( 'anchor' ), true ); + if ( ! $anchor_support ) { return; } @@ -20,7 +20,16 @@ function gutenberg_register_anchor_support( $block_type ) { $block_type->attributes = array(); } - if ( ! array_key_exists( 'anchor', $block_type->attributes ) ) { + if ( true === $anchor_support || 'html' === $anchor_support ) { + $block_type->attributes['anchor'] = array( + 'type' => 'string', + 'source' => 'attribute', + 'attribute' => 'id', + 'selector' => '*', + ); + } + + if ( 'delimiter' === $anchor_support ) { $block_type->attributes['anchor'] = array( 'type' => 'string', ); diff --git a/packages/block-editor/src/hooks/anchor.js b/packages/block-editor/src/hooks/anchor.js index b3fdcd65c541b7..f378a7ab9888a6 100644 --- a/packages/block-editor/src/hooks/anchor.js +++ b/packages/block-editor/src/hooks/anchor.js @@ -21,13 +21,17 @@ import { useBlockEditingMode } from '../components/block-editing-mode'; */ const ANCHOR_REGEX = /[\s#]/g; -const ANCHOR_SCHEMA = { +const ANCHOR_SCHEMA_HTML = { type: 'string', source: 'attribute', attribute: 'id', selector: '*', }; +const ANCHOR_SCHEMA_DELIMITER = { + type: 'string', +}; + /** * Filters registered block settings, extending attributes with anchor using ID * of the first node. @@ -43,10 +47,16 @@ export function addAttribute( settings ) { } if ( hasBlockSupport( settings, 'anchor' ) ) { // Gracefully handle if settings.attributes is undefined. - settings.attributes = { - ...settings.attributes, - anchor: ANCHOR_SCHEMA, - }; + const { anchor } = settings.supports; + if ( [ true, 'html', 'delimiter' ].includes( anchor ) ) { + settings.attributes = { + ...settings.attributes, + anchor: + anchor === 'delimiter' + ? ANCHOR_SCHEMA_DELIMITER + : ANCHOR_SCHEMA_HTML, + }; + } } return settings; diff --git a/packages/block-editor/src/hooks/test/anchor.js b/packages/block-editor/src/hooks/test/anchor.js index a919fad575312e..caccc66b34293a 100644 --- a/packages/block-editor/src/hooks/test/anchor.js +++ b/packages/block-editor/src/hooks/test/anchor.js @@ -29,15 +29,48 @@ describe( 'anchor', () => { expect( settings.attributes ).toBe( undefined ); } ); - it( 'should assign a new anchor attribute', () => { + [ false, 'incorrect' ].forEach( ( value ) => { + it( `should do nothing if value is ${ value }`, () => { + const settings = registerBlockType( { + ...blockSettings, + supports: { + anchor: value, + }, + } ); + + expect( settings.attributes ).toBe( undefined ); + } ); + } ); + + [ true, 'html' ].forEach( ( value ) => { + it( `should assign a new anchor attribute referencing html if value is ${ value }`, () => { + const settings = registerBlockType( { + ...blockSettings, + supports: { + anchor: value, + }, + } ); + + expect( settings.attributes.anchor ).toEqual( { + attribute: 'id', + selector: '*', + source: 'attribute', + type: 'string', + } ); + } ); + } ); + + it( 'should assign a new anchor attribute referencing comment delimiter if value is delimiter', () => { const settings = registerBlockType( { ...blockSettings, supports: { - anchor: true, + anchor: `delimiter`, }, } ); - expect( settings.attributes ).toHaveProperty( 'anchor' ); + expect( settings.attributes.anchor ).toEqual( { + type: 'string', + } ); } ); it( 'should not override attributes defined in settings', () => { diff --git a/packages/block-library/src/archives/block.json b/packages/block-library/src/archives/block.json index edc6895e14b06f..5f857c35ce80a4 100644 --- a/packages/block-library/src/archives/block.json +++ b/packages/block-library/src/archives/block.json @@ -26,7 +26,7 @@ }, "supports": { "align": true, - "anchor": true, + "anchor": "delimiter", "html": false, "spacing": { "margin": true, diff --git a/packages/block-library/src/avatar/block.json b/packages/block-library/src/avatar/block.json index 3fbb6dd9221aec..f014c860c81ac2 100644 --- a/packages/block-library/src/avatar/block.json +++ b/packages/block-library/src/avatar/block.json @@ -25,7 +25,7 @@ }, "usesContext": [ "postType", "postId", "commentId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "align": true, "alignWide": false, diff --git a/packages/block-library/src/calendar/block.json b/packages/block-library/src/calendar/block.json index c772cf58411f06..5537df9d4249e4 100644 --- a/packages/block-library/src/calendar/block.json +++ b/packages/block-library/src/calendar/block.json @@ -17,7 +17,7 @@ }, "supports": { "align": true, - "anchor": true, + "anchor": "delimiter", "color": { "link": true, "__experimentalSkipSerialization": [ "text", "background" ], diff --git a/packages/block-library/src/categories/block.json b/packages/block-library/src/categories/block.json index a90a527e35c451..af014bcd2ef7f5 100644 --- a/packages/block-library/src/categories/block.json +++ b/packages/block-library/src/categories/block.json @@ -30,7 +30,7 @@ }, "supports": { "align": true, - "anchor": true, + "anchor": "delimiter", "html": false, "spacing": { "margin": true, diff --git a/packages/block-library/src/comment-author-avatar/block.json b/packages/block-library/src/comment-author-avatar/block.json index 2b6cefd6db9983..a4de7b8d45e49c 100644 --- a/packages/block-library/src/comment-author-avatar/block.json +++ b/packages/block-library/src/comment-author-avatar/block.json @@ -20,7 +20,7 @@ }, "usesContext": [ "commentId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "inserter": false, "__experimentalBorder": { diff --git a/packages/block-library/src/comment-author-name/block.json b/packages/block-library/src/comment-author-name/block.json index cfa036fa80e2d3..9245c1dc7ab3b1 100644 --- a/packages/block-library/src/comment-author-name/block.json +++ b/packages/block-library/src/comment-author-name/block.json @@ -22,7 +22,7 @@ }, "usesContext": [ "commentId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "spacing": { "margin": true, diff --git a/packages/block-library/src/comment-content/block.json b/packages/block-library/src/comment-content/block.json index 69917ccce6aeaf..72b4a442abde48 100644 --- a/packages/block-library/src/comment-content/block.json +++ b/packages/block-library/src/comment-content/block.json @@ -14,7 +14,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "color": { "gradients": true, "link": true, diff --git a/packages/block-library/src/comment-date/block.json b/packages/block-library/src/comment-date/block.json index ea1e2633381392..abf44e991e598d 100644 --- a/packages/block-library/src/comment-date/block.json +++ b/packages/block-library/src/comment-date/block.json @@ -18,7 +18,7 @@ }, "usesContext": [ "commentId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/comment-edit-link/block.json b/packages/block-library/src/comment-edit-link/block.json index e695ddc3801f77..3eb499eb8fd602 100644 --- a/packages/block-library/src/comment-edit-link/block.json +++ b/packages/block-library/src/comment-edit-link/block.json @@ -18,7 +18,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "link": true, diff --git a/packages/block-library/src/comment-reply-link/block.json b/packages/block-library/src/comment-reply-link/block.json index 7ed60f34f581f9..694ca402f57329 100644 --- a/packages/block-library/src/comment-reply-link/block.json +++ b/packages/block-library/src/comment-reply-link/block.json @@ -14,7 +14,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "color": { "gradients": true, "link": true, diff --git a/packages/block-library/src/comment-template/block.json b/packages/block-library/src/comment-template/block.json index 9d0eb98684f142..af61bd58755b89 100644 --- a/packages/block-library/src/comment-template/block.json +++ b/packages/block-library/src/comment-template/block.json @@ -10,7 +10,7 @@ "usesContext": [ "postId" ], "supports": { "align": true, - "anchor": true, + "anchor": "delimiter", "html": false, "reusable": false, "spacing": { diff --git a/packages/block-library/src/comments-pagination-next/block.json b/packages/block-library/src/comments-pagination-next/block.json index f0cee1a1cdbe68..48c8a0036fd38b 100644 --- a/packages/block-library/src/comments-pagination-next/block.json +++ b/packages/block-library/src/comments-pagination-next/block.json @@ -14,7 +14,7 @@ }, "usesContext": [ "postId", "comments/paginationArrow" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "color": { diff --git a/packages/block-library/src/comments-pagination-numbers/block.json b/packages/block-library/src/comments-pagination-numbers/block.json index 0ab4f965ff1cd6..edb330e88a44a9 100644 --- a/packages/block-library/src/comments-pagination-numbers/block.json +++ b/packages/block-library/src/comments-pagination-numbers/block.json @@ -9,7 +9,7 @@ "textdomain": "default", "usesContext": [ "postId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "color": { diff --git a/packages/block-library/src/comments-pagination-previous/block.json b/packages/block-library/src/comments-pagination-previous/block.json index 211e1a33305a0d..c7e2e464900f52 100644 --- a/packages/block-library/src/comments-pagination-previous/block.json +++ b/packages/block-library/src/comments-pagination-previous/block.json @@ -14,7 +14,7 @@ }, "usesContext": [ "postId", "comments/paginationArrow" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "color": { diff --git a/packages/block-library/src/comments-pagination/block.json b/packages/block-library/src/comments-pagination/block.json index d7c8be4b8eaa25..bc9ba4db07e29a 100644 --- a/packages/block-library/src/comments-pagination/block.json +++ b/packages/block-library/src/comments-pagination/block.json @@ -17,7 +17,7 @@ "comments/paginationArrow": "paginationArrow" }, "supports": { - "anchor": true, + "anchor": "delimiter", "align": true, "reusable": false, "html": false, diff --git a/packages/block-library/src/comments/block.json b/packages/block-library/src/comments/block.json index 19490f6e99eb47..50fd0e73aa93a0 100644 --- a/packages/block-library/src/comments/block.json +++ b/packages/block-library/src/comments/block.json @@ -18,7 +18,7 @@ }, "supports": { "align": [ "wide", "full" ], - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/home-link/block.json b/packages/block-library/src/home-link/block.json index df964ad76bc68d..5fa9ec748efca8 100644 --- a/packages/block-library/src/home-link/block.json +++ b/packages/block-library/src/home-link/block.json @@ -22,7 +22,7 @@ "style" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "typography": { diff --git a/packages/block-library/src/latest-comments/block.json b/packages/block-library/src/latest-comments/block.json index 80fa4f5d2d063a..be7aff622febe4 100644 --- a/packages/block-library/src/latest-comments/block.json +++ b/packages/block-library/src/latest-comments/block.json @@ -29,7 +29,7 @@ }, "supports": { "align": true, - "anchor": true, + "anchor": "delimiter", "html": false, "spacing": { "margin": true, diff --git a/packages/block-library/src/latest-posts/block.json b/packages/block-library/src/latest-posts/block.json index 9b451f5875c733..53bb215fa3c37b 100644 --- a/packages/block-library/src/latest-posts/block.json +++ b/packages/block-library/src/latest-posts/block.json @@ -84,7 +84,7 @@ }, "supports": { "align": true, - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/loginout/block.json b/packages/block-library/src/loginout/block.json index 3ba18dcf17143f..ff8ca41cae855b 100644 --- a/packages/block-library/src/loginout/block.json +++ b/packages/block-library/src/loginout/block.json @@ -18,7 +18,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "className": true, "typography": { "fontSize": true, diff --git a/packages/block-library/src/navigation/block.json b/packages/block-library/src/navigation/block.json index ce2bed0d8837f6..718b0884438770 100644 --- a/packages/block-library/src/navigation/block.json +++ b/packages/block-library/src/navigation/block.json @@ -91,7 +91,7 @@ }, "supports": { "align": [ "wide", "full" ], - "anchor": true, + "anchor": "delimiter", "html": false, "inserter": true, "typography": { diff --git a/packages/block-library/src/page-list/block.json b/packages/block-library/src/page-list/block.json index 0fa309431202a9..3a2495fc36bb6c 100644 --- a/packages/block-library/src/page-list/block.json +++ b/packages/block-library/src/page-list/block.json @@ -33,7 +33,7 @@ "openSubmenusOnClick" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "typography": { diff --git a/packages/block-library/src/post-author-biography/block.json b/packages/block-library/src/post-author-biography/block.json index a2e5f327acfeb7..8a72ff3ca35bc0 100644 --- a/packages/block-library/src/post-author-biography/block.json +++ b/packages/block-library/src/post-author-biography/block.json @@ -13,7 +13,7 @@ }, "usesContext": [ "postType", "postId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "spacing": { "margin": true, "padding": true diff --git a/packages/block-library/src/post-author-name/block.json b/packages/block-library/src/post-author-name/block.json index 2340636e0c63a4..de218666df43b0 100644 --- a/packages/block-library/src/post-author-name/block.json +++ b/packages/block-library/src/post-author-name/block.json @@ -21,7 +21,7 @@ }, "usesContext": [ "postType", "postId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "spacing": { "margin": true, diff --git a/packages/block-library/src/post-author/block.json b/packages/block-library/src/post-author/block.json index 4a8e0433868e53..dccd603df49484 100644 --- a/packages/block-library/src/post-author/block.json +++ b/packages/block-library/src/post-author/block.json @@ -35,7 +35,7 @@ }, "usesContext": [ "postType", "postId", "queryId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "spacing": { "margin": true, diff --git a/packages/block-library/src/post-comments-count/block.json b/packages/block-library/src/post-comments-count/block.json index c56039a1fbee04..ac51100106d627 100644 --- a/packages/block-library/src/post-comments-count/block.json +++ b/packages/block-library/src/post-comments-count/block.json @@ -14,7 +14,7 @@ }, "usesContext": [ "postId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/post-comments-form/block.json b/packages/block-library/src/post-comments-form/block.json index 793d14d74ba7ba..cee362aaec28f6 100644 --- a/packages/block-library/src/post-comments-form/block.json +++ b/packages/block-library/src/post-comments-form/block.json @@ -13,7 +13,7 @@ }, "usesContext": [ "postId", "postType" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/post-comments-link/block.json b/packages/block-library/src/post-comments-link/block.json index b0ff71adca1547..a5fe6a2e8c4af5 100644 --- a/packages/block-library/src/post-comments-link/block.json +++ b/packages/block-library/src/post-comments-link/block.json @@ -14,7 +14,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "link": true, diff --git a/packages/block-library/src/post-content/block.json b/packages/block-library/src/post-content/block.json index 56834a980baed1..ee3bc89d5d646b 100644 --- a/packages/block-library/src/post-content/block.json +++ b/packages/block-library/src/post-content/block.json @@ -8,7 +8,7 @@ "textdomain": "default", "usesContext": [ "postId", "postType", "queryId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "align": [ "wide", "full" ], "html": false, "__experimentalLayout": true, diff --git a/packages/block-library/src/post-date/block.json b/packages/block-library/src/post-date/block.json index 41c45a4a57e26e..868fff57013c33 100644 --- a/packages/block-library/src/post-date/block.json +++ b/packages/block-library/src/post-date/block.json @@ -24,7 +24,7 @@ }, "usesContext": [ "postId", "postType", "queryId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/post-excerpt/block.json b/packages/block-library/src/post-excerpt/block.json index 53a92cb0bda639..87f7531f9d081b 100644 --- a/packages/block-library/src/post-excerpt/block.json +++ b/packages/block-library/src/post-excerpt/block.json @@ -24,7 +24,7 @@ }, "usesContext": [ "postId", "postType", "queryId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/post-featured-image/block.json b/packages/block-library/src/post-featured-image/block.json index c6007785cd82ac..d3bb38b7dba8f3 100644 --- a/packages/block-library/src/post-featured-image/block.json +++ b/packages/block-library/src/post-featured-image/block.json @@ -56,7 +56,7 @@ "usesContext": [ "postId", "postType", "queryId" ], "supports": { "align": [ "left", "right", "center", "wide", "full" ], - "anchor": true, + "anchor": "delimiter", "color": { "__experimentalDuotone": "img, .wp-block-post-featured-image__placeholder, .components-placeholder__illustration, .components-placeholder::before", "text": false, diff --git a/packages/block-library/src/post-navigation-link/block.json b/packages/block-library/src/post-navigation-link/block.json index 2bdfa654798ee6..9badc53502a4b5 100644 --- a/packages/block-library/src/post-navigation-link/block.json +++ b/packages/block-library/src/post-navigation-link/block.json @@ -31,7 +31,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "color": { diff --git a/packages/block-library/src/post-template/block.json b/packages/block-library/src/post-template/block.json index 1a5426253dbf3f..a6be461f8bb629 100644 --- a/packages/block-library/src/post-template/block.json +++ b/packages/block-library/src/post-template/block.json @@ -19,7 +19,7 @@ "reusable": false, "html": false, "align": [ "wide", "full" ], - "anchor": true, + "anchor": "delimiter", "__experimentalLayout": true, "color": { "gradients": true, diff --git a/packages/block-library/src/post-terms/block.json b/packages/block-library/src/post-terms/block.json index 1633c7c01b82ca..01ac77916675c2 100644 --- a/packages/block-library/src/post-terms/block.json +++ b/packages/block-library/src/post-terms/block.json @@ -28,7 +28,7 @@ }, "usesContext": [ "postId", "postType" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/post-time-to-read/block.json b/packages/block-library/src/post-time-to-read/block.json index 2b7d7936094f7c..2a12e9099bd5f8 100644 --- a/packages/block-library/src/post-time-to-read/block.json +++ b/packages/block-library/src/post-time-to-read/block.json @@ -22,6 +22,7 @@ } }, "html": false, + "anchor": "delimiter", "spacing": { "margin": true, "padding": true diff --git a/packages/block-library/src/post-title/block.json b/packages/block-library/src/post-title/block.json index 66377292db68c0..47cb22a1324ee4 100644 --- a/packages/block-library/src/post-title/block.json +++ b/packages/block-library/src/post-title/block.json @@ -31,7 +31,7 @@ }, "supports": { "align": [ "wide", "full" ], - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/query-no-results/block.json b/packages/block-library/src/query-no-results/block.json index 789dcc8e66f605..5b583997540414 100644 --- a/packages/block-library/src/query-no-results/block.json +++ b/packages/block-library/src/query-no-results/block.json @@ -9,7 +9,7 @@ "textdomain": "default", "usesContext": [ "queryId", "query" ], "supports": { - "anchor": true, + "anchor": "delimiter", "align": true, "reusable": false, "html": false, diff --git a/packages/block-library/src/query-pagination-next/block.json b/packages/block-library/src/query-pagination-next/block.json index 7c4f5797efa903..98e23834ddefa0 100644 --- a/packages/block-library/src/query-pagination-next/block.json +++ b/packages/block-library/src/query-pagination-next/block.json @@ -14,7 +14,7 @@ }, "usesContext": [ "queryId", "query", "paginationArrow", "showLabel" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "color": { diff --git a/packages/block-library/src/query-pagination-numbers/block.json b/packages/block-library/src/query-pagination-numbers/block.json index a05faff5f1b52b..63d14ee7feef72 100644 --- a/packages/block-library/src/query-pagination-numbers/block.json +++ b/packages/block-library/src/query-pagination-numbers/block.json @@ -9,7 +9,7 @@ "textdomain": "default", "usesContext": [ "queryId", "query" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "color": { diff --git a/packages/block-library/src/query-pagination-previous/block.json b/packages/block-library/src/query-pagination-previous/block.json index 2efda01e20b6bd..eeca94c5ee54ac 100644 --- a/packages/block-library/src/query-pagination-previous/block.json +++ b/packages/block-library/src/query-pagination-previous/block.json @@ -14,7 +14,7 @@ }, "usesContext": [ "queryId", "query", "paginationArrow", "showLabel" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false, "color": { diff --git a/packages/block-library/src/query-pagination/block.json b/packages/block-library/src/query-pagination/block.json index 7217a3eb4f1a38..bf9f868ba6f69c 100644 --- a/packages/block-library/src/query-pagination/block.json +++ b/packages/block-library/src/query-pagination/block.json @@ -23,7 +23,7 @@ "showLabel": "showLabel" }, "supports": { - "anchor": true, + "anchor": "delimiter", "align": true, "reusable": false, "html": false, diff --git a/packages/block-library/src/query-title/block.json b/packages/block-library/src/query-title/block.json index 029762c321e399..fee1795c49bd0d 100644 --- a/packages/block-library/src/query-title/block.json +++ b/packages/block-library/src/query-title/block.json @@ -27,7 +27,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "align": [ "wide", "full" ], "html": false, "color": { diff --git a/packages/block-library/src/query/block.json b/packages/block-library/src/query/block.json index 50733930b78dc5..5e79f67f38db9e 100644 --- a/packages/block-library/src/query/block.json +++ b/packages/block-library/src/query/block.json @@ -43,7 +43,7 @@ }, "supports": { "align": [ "wide", "full" ], - "anchor": true, + "anchor": "delimiter", "html": false, "__experimentalLayout": true }, diff --git a/packages/block-library/src/read-more/block.json b/packages/block-library/src/read-more/block.json index ed2b23c3b7f0fd..1aeeb53faa3f5e 100644 --- a/packages/block-library/src/read-more/block.json +++ b/packages/block-library/src/read-more/block.json @@ -17,7 +17,7 @@ }, "usesContext": [ "postId" ], "supports": { - "anchor": true, + "anchor": "delimiter", "html": false, "color": { "gradients": true, diff --git a/packages/block-library/src/rss/block.json b/packages/block-library/src/rss/block.json index 2e3fd4b2d385e1..7b501ab3e41296 100644 --- a/packages/block-library/src/rss/block.json +++ b/packages/block-library/src/rss/block.json @@ -43,7 +43,7 @@ }, "supports": { "align": true, - "anchor": true, + "anchor": "delimiter", "html": false }, "editorStyle": "wp-block-rss-editor", diff --git a/packages/block-library/src/search/block.json b/packages/block-library/src/search/block.json index 387295ebb36dea..ba2a86dd5b9c1a 100644 --- a/packages/block-library/src/search/block.json +++ b/packages/block-library/src/search/block.json @@ -46,7 +46,7 @@ }, "supports": { "align": [ "left", "center", "right" ], - "anchor": true, + "anchor": "delimiter", "color": { "gradients": true, "__experimentalSkipSerialization": true, diff --git a/packages/block-library/src/site-logo/block.json b/packages/block-library/src/site-logo/block.json index 8eba39b91c7ad4..894ac93a33f636 100644 --- a/packages/block-library/src/site-logo/block.json +++ b/packages/block-library/src/site-logo/block.json @@ -31,7 +31,7 @@ }, "supports": { "html": false, - "anchor": true, + "anchor": "delimiter", "align": true, "alignWide": false, "color": { diff --git a/packages/block-library/src/site-tagline/block.json b/packages/block-library/src/site-tagline/block.json index a11eab4fbc243b..5331af442362c5 100644 --- a/packages/block-library/src/site-tagline/block.json +++ b/packages/block-library/src/site-tagline/block.json @@ -14,7 +14,7 @@ }, "example": {}, "supports": { - "anchor": true, + "anchor": "delimiter", "align": [ "wide", "full" ], "html": false, "color": { diff --git a/packages/block-library/src/site-title/block.json b/packages/block-library/src/site-title/block.json index b69acda934fda2..d5786ecdb481f3 100644 --- a/packages/block-library/src/site-title/block.json +++ b/packages/block-library/src/site-title/block.json @@ -27,7 +27,7 @@ "viewportWidth": 500 }, "supports": { - "anchor": true, + "anchor": "delimiter", "align": [ "wide", "full" ], "html": false, "color": { diff --git a/packages/block-library/src/social-link/block.json b/packages/block-library/src/social-link/block.json index 140cc123ec484c..b01b0522c794af 100644 --- a/packages/block-library/src/social-link/block.json +++ b/packages/block-library/src/social-link/block.json @@ -30,7 +30,7 @@ "iconBackgroundColorValue" ], "supports": { - "anchor": true, + "anchor": "delimiter", "reusable": false, "html": false }, diff --git a/packages/block-library/src/tag-cloud/block.json b/packages/block-library/src/tag-cloud/block.json index ec1e3335127193..715fd09ee461bf 100644 --- a/packages/block-library/src/tag-cloud/block.json +++ b/packages/block-library/src/tag-cloud/block.json @@ -36,7 +36,7 @@ ], "supports": { "html": false, - "anchor": true, + "anchor": "delimiter", "align": true, "spacing": { "margin": true, diff --git a/packages/block-library/src/template-part/block.json b/packages/block-library/src/template-part/block.json index 282ac2ca22127a..f817cfacca24a1 100644 --- a/packages/block-library/src/template-part/block.json +++ b/packages/block-library/src/template-part/block.json @@ -21,7 +21,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "align": true, "html": false, "reusable": false diff --git a/packages/block-library/src/term-description/block.json b/packages/block-library/src/term-description/block.json index bd96f3405f54f2..a60ec5db658341 100644 --- a/packages/block-library/src/term-description/block.json +++ b/packages/block-library/src/term-description/block.json @@ -12,7 +12,7 @@ } }, "supports": { - "anchor": true, + "anchor": "delimiter", "align": [ "wide", "full" ], "html": false, "color": { diff --git a/packages/server-side-render/src/server-side-render.js b/packages/server-side-render/src/server-side-render.js index 69a2183036dd14..aee2921ecfa89b 100644 --- a/packages/server-side-render/src/server-side-render.js +++ b/packages/server-side-render/src/server-side-render.js @@ -112,9 +112,15 @@ export default function ServerSideRender( props ) { setIsLoading( true ); - let sanitizedAttributes = - attributes && - __experimentalSanitizeBlockAttributes( block, attributes ); + let sanitizedAttributes; + if ( attributes ) { + // Anchor attribute isn't supported on the server side and + // should be excluded from the parameters. + const { anchor, ...restAttributes } = attributes; + sanitizedAttributes = + restAttributes && + __experimentalSanitizeBlockAttributes( block, restAttributes ); + } if ( skipBlockSupportAttributes ) { sanitizedAttributes = diff --git a/schemas/json/block.json b/schemas/json/block.json index 5b92a654fbc4a5..a422bc8411f7a6 100644 --- a/schemas/json/block.json +++ b/schemas/json/block.json @@ -222,9 +222,17 @@ "description": "It contains as set of options to control features used in the editor. See the supports documentation at https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/ for more details.", "properties": { "anchor": { - "type": "boolean", - "description": "Anchors let you link directly to a specific block on a page. This property adds a field to define an id for the block and a button to copy the direct link.", - "default": false + "description": "Anchors let you link directly to a specific block on a page. This property adds a field to define an id for the block and a button to copy the direct link. If this property is set to `true` or `html`, the id attribute of the root element of the saved markup are referenced. If this property is set to `delimiter`, the attribute is saved as a comment delimiter.", + "default": false, + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "string", + "enum": [ "html", "delimiter" ] + } + ] }, "align": { "default": false,