TextStyle 扩展

版本下载

该标记呈现一个 <span> HTML 标签,并允许您添加一系列与样式相关的属性,例如字体系列、字体大小或颜色。该扩展默认不添加任何样式属性,但其他扩展将其作为基础,例如 FontFamily 或 Color。

应用字体大小

TextStyle 提供 <span> 标记,而 FontSize 等扩展会添加具体的样式属性。安装 text-style 包,并将这两个扩展与包含文档 schema 的编辑器(例如 StarterKit 提供的 schema)一起使用:

npm install @tiptap/extension-text-style @tiptap/starter-kit
import { Editor } from '@tiptap/core'
import { TextStyle, FontSize } from '@tiptap/extension-text-style'
import StarterKit from '@tiptap/starter-kit'

const editor = new Editor({
  extensions: [StarterKit, TextStyle, FontSize],
})

editor.chain().focus().setFontSize('18px').run()

该命令会将选中的文本渲染为带有行内 font-size: 18px 样式的 span。

安装

npm install @tiptap/extension-text-style

命令

removeEmptyTextStyle()

移除没有内联样式的 <span> 标签。

editor.command.removeEmptyTextStyle()

源代码

packages/extension-text-style/