From 08616cb3829531523331bb42476850f934b20708 Mon Sep 17 00:00:00 2001 From: Marcus Kazmierczak Date: Fri, 26 Mar 2021 19:28:36 -0700 Subject: [PATCH] Rich Text Docs: Add section for disabling specific format types (#29383) * 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 --- docs/reference-guides/richtext.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/reference-guides/richtext.md b/docs/reference-guides/richtext.md index e5c3edbc4ea7f6..a955eb1f2d8e0d 100644 --- a/docs/reference-guides/richtext.md +++ b/docs/reference-guides/richtext.md @@ -122,3 +122,16 @@ If the HTML tags from text formatting such as `` or `` 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/). +