tiptap 中文文档

tiptap TextStyle 文本样式

tiptap TextStyle 标记呈现为 span 标签,您能够添加样式相关的属性,例如font-familyfont-sizecolor,默认情况下,扩展不添加任何样式属性,但其他扩展以它作为基础,例如FontFamily或Color扩展。

Install 安装

npm install @tiptap/extension-text-style

Commands 命令

removeEmptyTextStyle 移除样式。

editor.commands.removeEmptyTextStyle()

源代码

TextStyle 源代码

Subscript 例子

  • Vue 例子

  • React 例子

<template>
  <div v-if="editor">
    <editor-content :editor="editor" />
  </div>
</template>
<script>
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import TextStyle from '@tiptap/extension-text-style'
import { Editor, EditorContent } from '@tiptap/vue-3'

export default {
  components: {
    EditorContent,
  },
  data() {
    return {
      editor: null,
    }
  },
  mounted() {
    this.editor = new Editor({
      extensions: [
        Document,
        Paragraph,
        Text,
        TextStyle,
      ],
      content: `
        <p><span>This has a &lt;span&gt; tag without a style attribute, so it’s thrown away.</span></p>
        <p><span style="">But this one is wrapped in a &lt;span&gt; tag with an inline style attribute, so it’s kept - even if it’s empty for now.</span></p>
      `,
    })
  },
  beforeUnmount() {
    this.editor.destroy()
  },
}
</script>
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import TextStyle from '@tiptap/extension-text-style'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'

export default () => {
  const editor = useEditor({
    extensions: [Document, Paragraph, Text, TextStyle],
    content: `
        <p><span>This has a &lt;span&gt; tag without a style attribute, so it’s thrown away.</span></p>
        <p><span style="">But this one is wrapped in a &lt;span&gt; tag with an inline style attribute, so it’s kept - even if it’s empty for now.</span></p>
      `,
  })
  if (!editor) {
    return null
  }
  return <EditorContent editor={editor} />
}
Catalog
快速入门 Guide 向导 API 列表 tiptap 方法 tiptap 属性 titap 配置 commands 命令 nodes 节点 marks 标记 Bold 粗体 Code 标签 Highlight 高亮标记 Italic 斜体 Link 超链接 Strike 删除符 Subscript 下标 TextStyle 文本样式 Underline 下划线 Superscript 上标 extensions 扩展