Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/block-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ attributes: {
attribute: 'src',
},
author: {
type: 'string',
source: 'html',
selector: '.book-author',
},
Expand Down
17 changes: 15 additions & 2 deletions docs/block-api/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ _Example_: Extract the `src` attribute from an image found in the block's markup
```js
{
url: {
type: 'string',
source: 'attribute',
selector: 'img',
attribute: 'src',
Expand All @@ -34,6 +35,7 @@ Use `text` to extract the inner text from markup.
```js
{
content: {
type: 'string',
source: 'text',
selector: 'figcaption',
}
Expand All @@ -48,6 +50,7 @@ Use `html` to extract the inner HTML from markup.
```js
{
content: {
type: 'string',
source: 'html',
selector: 'figcaption',
}
Expand All @@ -60,6 +63,7 @@ Use the `multiline` property to extract the inner HTML of matching tag names for
```js
{
content: {
type: 'string',
source: 'html',
multiline: 'p',
selector: 'blockquote',
Expand All @@ -77,11 +81,20 @@ _Example_: Extract `src` and `alt` from each image element in the block's markup
```js
{
images: {
type: 'array',
source: 'query'
selector: 'img',
query: {
url: { source: 'attribute', attribute: 'src' },
alt: { source: 'attribute', attribute: 'alt' },
url: {
type: 'string',
source: 'attribute',
attribute: 'src',
},
alt: {
type: 'string',
source: 'attribute',
attribute: 'alt',
},
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions docs/block-api/deprecated-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
{
attributes: {
title: {
type: 'string',
source: 'html',
selector: 'p',
},
Expand Down Expand Up @@ -244,6 +245,7 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
{
attributes: {
title: {
type: 'string',
source: 'html',
selector: 'p',
},
Expand Down
2 changes: 2 additions & 0 deletions docs/blocks/block-controls-toolbars-and-inspector.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ registerBlockType( 'gutenberg-boilerplate-es5/hello-world-step-04', {

attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
},
Expand Down Expand Up @@ -111,6 +112,7 @@ registerBlockType( 'gutenberg-boilerplate-esnext/hello-world-step-04', {

attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
},
Expand Down
2 changes: 2 additions & 0 deletions docs/blocks/introducing-attributes-and-editable-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ registerBlockType( 'gutenberg-boilerplate-es5/hello-world-step-03', {

attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
}
Expand Down Expand Up @@ -72,6 +73,7 @@ registerBlockType( 'gutenberg-boilerplate-esnext/hello-world-step-03', {

attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/audio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const settings = {
attribute: 'src',
},
caption: {
type: 'string',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some docs with samples very similar to this.
https://github.com/WordPress/gutenberg/blob/master/docs/block-api/attributes.md#text

I think it may be worth it to add type: 'string', in these docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 9a6276b

source: 'html',
selector: 'figcaption',
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const blockAttributes = {
attribute: 'title',
},
text: {
type: 'string',
source: 'html',
selector: 'a',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/cover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const validAlignments = [ 'left', 'center', 'right', 'wide', 'full' ];

const blockAttributes = {
title: {
type: 'string',
source: 'html',
selector: 'p',
},
Expand Down Expand Up @@ -463,6 +464,7 @@ export const settings = {
attributes: {
...blockAttributes,
title: {
type: 'string',
source: 'html',
selector: 'h2',
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/embed/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const embedAttributes = {
type: 'string',
},
caption: {
type: 'string',
source: 'html',
selector: 'figcaption',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const settings = {
type: 'string',
},
fileName: {
type: 'string',
source: 'html',
selector: 'a:not([download])',
},
Expand All @@ -61,6 +62,7 @@ export const settings = {
default: true,
},
downloadButtonText: {
type: 'string',
source: 'html',
selector: 'a[download]',
default: _x( 'Download', 'button label' ),
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/gallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const blockAttributes = {
attribute: 'data-id',
},
caption: {
type: 'string',
source: 'html',
selector: 'figcaption',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ const supports = {

const schema = {
content: {
type: 'string',
source: 'html',
selector: 'h1,h2,h3,h4,h5,h6',
default: '',
},
level: {
type: 'number',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const blockAttributes = {
default: '',
},
caption: {
type: 'string',
source: 'html',
selector: 'figcaption',
},
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ const schema = {
default: false,
},
values: {
type: 'string',
source: 'html',
selector: 'ol,ul',
multiline: 'li',
default: '',
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/paragraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const supports = {

const schema = {
content: {
type: 'string',
source: 'html',
selector: 'p',
default: '',
Expand Down Expand Up @@ -197,6 +198,7 @@ export const settings = {
content: {
type: 'string',
source: 'html',
default: '',
},
},
save( { attributes } ) {
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/preformatted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export const settings = {

attributes: {
content: {
type: 'string',
source: 'html',
selector: 'pre',
default: '',
},
},

Expand Down
4 changes: 4 additions & 0 deletions packages/block-library/src/pullquote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ import {

const blockAttributes = {
value: {
type: 'string',
source: 'html',
selector: 'blockquote',
multiline: 'p',
},
citation: {
type: 'string',
source: 'html',
selector: 'cite',
default: '',
},
mainColor: {
type: 'string',
Expand Down Expand Up @@ -133,6 +136,7 @@ export const settings = {
attributes: {
...blockAttributes,
citation: {
type: 'string',
source: 'html',
selector: 'footer',
},
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ import { G, Path, SVG } from '@wordpress/components';

const blockAttributes = {
value: {
type: 'string',
source: 'html',
selector: 'blockquote',
multiline: 'p',
default: '',
},
citation: {
type: 'string',
source: 'html',
selector: 'cite',
default: '',
},
align: {
type: 'string',
Expand Down Expand Up @@ -292,8 +296,10 @@ export const settings = {
attributes: {
...blockAttributes,
citation: {
type: 'string',
source: 'html',
selector: 'footer',
default: '',
},
style: {
type: 'number',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/subhead/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const settings = {

attributes: {
content: {
type: 'string',
source: 'html',
selector: 'p',
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function getTableSectionAttributeSchema( section ) {
selector: 'td,th',
query: {
content: {
type: 'string',
source: 'html',
},
tag: {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/text-columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const settings = {
selector: 'p',
query: {
children: {
type: 'string',
source: 'html',
},
},
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/verse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export const settings = {

attributes: {
content: {
type: 'string',
source: 'html',
selector: 'pre',
default: '',
},
textAlign: {
type: 'string',
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/video/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const settings = {
attribute: 'autoplay',
},
caption: {
type: 'string',
source: 'html',
selector: 'figcaption',
},
Expand Down
4 changes: 0 additions & 4 deletions packages/blocks/src/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ export function createBlock( name, blockAttributes = {}, innerBlocks = [] ) {
result[ key ] = schema.default;
}

if ( schema.source === 'html' && typeof result[ key ] !== 'string' ) {
result[ key ] = '';
}

if ( [ 'node', 'children' ].indexOf( schema.source ) !== -1 ) {
// Ensure value passed is always an array, which we're expecting in
// the RichText component to handle the deprecated value.
Expand Down