Skip to content

Commit

Permalink
Rich Text Docs: Add section for disabling specific format types (#29383)
Browse files Browse the repository at this point in the history
* Add section for disabling specific format types

Adds a new question/answer to rich text documentation for disabling a
specific format type either by using allowedFormts or unregister a
format.

Related: #12680

* Update allowedFormats as prop to component

* Add pointer to example above
  • Loading branch information
mkaz authored Mar 27, 2021
1 parent 139ecce commit 08616cb
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/reference-guides/richtext.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,16 @@ If the HTML tags from text formatting such as `<strong>` or `<em>` are being esc
Before moving forward, consider if using the RichText component makes sense at all. Would it be better to use a basic `input` or `textarea` element? If you don't think any formatting should be possible, these HTML tags may make more sense.

If you'd still like to use RichText, you can eliminate all of the formatting options by specifying the `withoutInteractiveFormatting` property.

If you want to limit the formats allowed, you can specify using `allowedFormats` property in your code, see the example above or [the component documentation](https://github.com/WordPress/gutenberg/blob/HEAD/packages/block-editor/src/components/rich-text/README.md#allowedformats-array) for details.

### Disable Specific Format Types in Editor

The RichText component uses formats to display inline elements, for example images within the paragraph block. If you just want to disable a format from the editor, you can use the `unregisterFormatType` function. For example to disable inline images, use:

```
wp.richText.unregisterFormatType( 'core/image' );
```

To apply, you would need to enqueue the above script in your plugin or theme. See the JavaScript tutorial for [how to load JavaScript in WordPress](https://developer.wordpress.org/block-editor/tutorials/javascript/loading-javascript/).

0 comments on commit 08616cb

Please sign in to comment.