Skip to content

Commit

Permalink
Merge pull request #4014 from WordPress/update/supports-html
Browse files Browse the repository at this point in the history
Block API: Refactor supportHTML as supports property
  • Loading branch information
aduth authored Dec 15, 2017
2 parents 7cb404d + 2a3e4a0 commit bbf06e2
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 21 deletions.
4 changes: 3 additions & 1 deletion blocks/library/categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ registerBlockType( 'core/categories', {
},
},

supportHTML: false,
supports: {
html: false,
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
Expand Down
4 changes: 3 additions & 1 deletion blocks/library/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ registerBlockType( 'core/code', {
},
},

supportHTML: false,
supports: {
html: false,
},

transforms: {
from: [
Expand Down
3 changes: 1 addition & 2 deletions blocks/library/html/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ registerBlockType( 'core/html', {

keywords: [ __( 'embed' ) ],

supportHTML: false,

supports: {
customClassName: false,
className: false,
html: false,
},

attributes: {
Expand Down
4 changes: 3 additions & 1 deletion blocks/library/latest-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ registerBlockType( 'core/latest-posts', {

keywords: [ __( 'recent posts' ) ],

supportHTML: false,
supports: {
html: false,
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
Expand Down
3 changes: 1 addition & 2 deletions blocks/library/more/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ registerBlockType( 'core/more', {

useOnce: true,

supportHTML: false,

supports: {
customClassName: false,
className: false,
html: false,
},

attributes: {
Expand Down
3 changes: 1 addition & 2 deletions blocks/library/shortcode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ registerBlockType( 'core/shortcode', {
],
},

supportHTML: false,

supports: {
customClassName: false,
className: false,
html: false,
},

edit: withInstanceId(
Expand Down
9 changes: 2 additions & 7 deletions docs/block-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,11 @@ customClassName: false,
className: false,
```

#### supportHTML (optional)

* **Type:** `Bool`
* **Default:** `true`

Whether a block can be edited in HTML mode.
- `html` (default `true`): By default, Gutenberg will allow a block's markup to be edited individually. To disable this behavior, set `html` to `false`.

```js
// Remove support for an HTML mode.
supportHTML: false,
html: false,
```

## Edit and Save
Expand Down
4 changes: 2 additions & 2 deletions editor/components/block-settings-menu/block-mode-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { noop } from 'lodash';
*/
import { __ } from '@wordpress/i18n';
import { IconButton } from '@wordpress/components';
import { getBlockType } from '@wordpress/blocks';
import { getBlockType, hasBlockSupport } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -18,7 +18,7 @@ import { getBlockMode, getBlock } from '../../selectors';
import { toggleBlockMode } from '../../actions';

export function BlockModeToggle( { blockType, mode, onToggleMode, small = false } ) {
if ( ! blockType || blockType.supportHTML === false ) {
if ( ! hasBlockSupport( blockType, 'html', true ) ) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { BlockModeToggle } from '../block-mode-toggle';
describe( 'BlockModeToggle', () => {
it( 'should not render the HTML mode button if the block doesn\'t support it', () => {
const wrapper = shallow(
<BlockModeToggle blockType={ { supportHTML: false } } />
<BlockModeToggle blockType={ { supports: { html: false } } } />
);

expect( wrapper.equals( null ) ).toBe( true );
Expand All @@ -20,7 +20,7 @@ describe( 'BlockModeToggle', () => {
it( 'should render the HTML mode button', () => {
const wrapper = shallow(
<BlockModeToggle
blockType={ { supportHTML: true } }
blockType={ { supports: { html: true } } }
mode="visual"
/>
);
Expand All @@ -32,7 +32,7 @@ describe( 'BlockModeToggle', () => {
it( 'should render the Visual mode button', () => {
const wrapper = shallow(
<BlockModeToggle
blockType={ { supportHTML: true } }
blockType={ { supports: { html: true } } }
mode="html"
/>
);
Expand Down

0 comments on commit bbf06e2

Please sign in to comment.