Linux 软件免费装
Banner图

JuZ Rich Text Extender

开发者 juzed
更新时间 2026年10月21日 00:42
PHP版本: 7.4 及以上
WordPress版本: 7.1
版权: GPL-2.0+
版权网址: 版权信息

标签

toolbar gutenberg rich text inline formats

下载

1.0.0 1.1.0 1.1.1

详情介绍:

JuZ Rich Text Extender allows developers to register custom inline format buttons in the Gutenberg (block editor) toolbar. Each button applies a specific HTML inline tag with an optional CSS class to the selected text. The plugin includes a built-in nesting validation system: buttons are automatically disabled when their use would produce invalid HTML nesting (e.g. <a> inside <a>). When a format is already active, its button remains enabled so it can always be toggled off. Key features: Live demo: See it in action on playground.juzed.dev, or try it in the editor with WordPress Playground, nothing to install. For developers: Formats and inline tag rules are both exposed via WordPress filters, making the plugin fully extensible without modifying core files.

安装:

  1. Upload the juz-rich-text-extender folder to the /wp-content/plugins/ directory.
  2. Activate the plugin through the Plugins menu in WordPress.
  3. Use the juz_rich_text_extender/formats filter to register your custom inline formats.

升级注意事项:

1.1.1 Demo links only, no code change. 1.1.0 Compatibility update for WordPress 7.1. 1.0.0 Initial release — no upgrade steps required.

常见问题:

How do I register a custom format?

Use the juz_rich_text_extender/formats filter to add your formats. Each format must be an associative array with the following keys:

  • name - unique identifier (used as the format type slug)
  • title - label shown in the toolbar tooltip
  • tagName - HTML inline tag to apply. Optional, defaults to span. See the caution note below.
  • className - CSS class applied to the tag
  • icon - a Dashicon slug or SVG string
Example: add_filter( 'juz_rich_text_extender/formats', function( $formats ) { $formats[] = [ 'name' => 'highlight', 'title' => __( 'Highlight', 'your-text-domain' ), 'className' => 'my-highlight', 'icon' => 'editor-textcolor', ]; return $formats; } ); CAUTION: tagName is optional and defaults to span, which is strongly recommended. Using any other tag may produce invalid HTML nesting or conflict with Gutenberg's internal formats (e.g. core/link for <a> tags). If you do specify a custom tag, the nesting validation system will still protect against invalid HTML where possible, but you may encounter editor limitations. See "How do I apply a custom class to a link?" for more details.

How do I customise the inline tag nesting rules?

Use the juz_rich_text_extender/inline_tags filter. Each tag entry has three keys: canSelfNest (bool), canNestIn (array of tag names), and canContain (array of tag names). Example: add_filter( 'juz_rich_text_extender/inline_tags', function( $tags ) { // Allow <kbd> as a custom inline tag $tags['kbd'] = [ 'canSelfNest' => false, 'canNestIn' => [ 'p', 'li', 'span', 'strong', 'em' ], 'canContain' => [], ]; return $tags; } );

Why is a button greyed out in the toolbar?

The nesting validation system detected that applying this format at the current cursor position would produce invalid HTML. For example, clicking <a> while already inside an <a> tag is forbidden by the HTML specification, so the button is disabled. This validation only applies to formats using a non-span tagName.

Can I override nesting rules for an existing tag?

Yes. Use the juz_rich_text_extender/inline_tags filter and modify the entry for the tag you want to change before returning the array.

How do I apply a custom class to a link?

Gutenberg manages <a> tags internally via its own core/link format, which makes it unreliable to apply a custom <a>-based format on top of an existing link. The recommended approach is to leave tagName unset (defaults to span) and target it in CSS using the :has() selector: add_filter( 'juz_rich_text_extender/formats', function( $formats ) { $formats[] = [ 'name' => 'button', 'title' => __( 'Button', 'your-text-domain' ), 'className' => 'btn', 'icon' => 'button', ]; return $formats; } ); Then in your CSS: a:has(> .btn) { display: inline-block; padding: 0.5em 1em; background: #0073aa; color: #fff; border-radius: 4px; text-decoration: none; } This approach produces valid HTML (<a href="..."><span class="btn">text</span></a>), survives the HTML ↔ visual editor round-trip without issues, and is supported by all modern browsers.

更新日志:

1.1.1 1.1.0 1.0.0