RTF格式

命名空间:核心/富文本.

选择器

获取格式类型

按名称返回格式类型。

用法

从'@wordpress/i18n'导入{__,sprintf};从“@wordpress/rich-text”导入{store as richTextStore};从“@wordpress/data”导入{useSelect};常量示例组件=()=>{const{getFormatType}=useSelect((select)=>选择(richTextStore),[]);const boldFormat=getFormatType('core/bold');return boldFormat?(<ul>{Object.entries(boldFormat)?.map(([key,value])=>(<li>{key}:{value}</li>) ) }</ul>) : (__(“未找到”);};

参数

  • 状态 对象:数据状态。
  • 名称 一串:格式类型名称。

退换商品

  • 目标?:格式类型。

获取裸元素的格式类型

获取可以处理裸元素(不带dataformat-type属性)的格式类型(如果有),并给定该元素的标记名。

用法

从'@wordpress/i18n'导入{__,sprintf};从“@wordpress/rich-text”导入{store as richTextStore};从“@wordpress/data”导入{useSelect};常量示例组件=()=>{const{getFormatTypeForBareElement}=useSelect((select)=>选择(richTextStore),[]);const format=getFormatTypeForBareElement('strong');返回格式&&<p>{sprintf(__('格式名:%s'),format.name)}</p>;};

参数

  • 状态 对象:数据状态。
  • 裸元素标记名 一串:要为其查找格式类型的元素的标记名。

退换商品

  • ?对象:格式类型。

获取类名称的格式类型

获取可以处理给定元素类的元素的格式类型(如果有)。

用法

从'@wordpress/i18n'导入{__,sprintf};从“@wordpress/rich-text”导入{store as richTextStore};从“@wordpress/data”导入{useSelect};常量示例组件=()=>{const{getFormatTypeForClassName}=useSelect((select)=>选择(richTextStore),[]);const format=getFormatTypeForClassName(“具有内联颜色”);返回格式&&<p>{sprintf(__('格式名:%s'),format.name)}</p>;};

参数

  • 状态 对象:数据状态。
  • 元素类名称 一串:要为其查找格式类型的元素的类。

退换商品

  • ?对象:格式类型。

获取格式类型

返回所有可用的格式类型。

用法

从'@wordpress/i18n'导入{__,sprintf};从“@wordpress/rich-text”导入{store as richTextStore};从“@wordpress/data”导入{useSelect};常量示例组件=()=>{const{getFormatTypes}=useSelect((select)=>选择(richTextStore),[]);const-availableFormats=getFormatTypes();是否返回可用格式?(<ul>{availableFormats?.map((格式)=>(<li>{format.name}</li>) ) }</ul>) : (__('无可用格式'));};

参数

  • 状态 对象:数据状态。

退换商品

  • 阵列:格式类型。

行动

没有要记录的内容。