tiptap 中文文档

tiptap Italic 斜体

tiptap Italic 以斜体呈现文本,如果在编辑器的初始内容中传递 emi 标签或具有设置font-style: italic的内联样式属性的文本,那么它们都以斜体呈现。

Install 安装

npm install @tiptap/extension-italic

Settings 配置

HTMLAttributes 自定义标签对应的HTML属性。

Italic.configure({
  HTMLAttributes: {
    class: 'custom-class',
  },
})

Commands 命令

setItalic 标记文本为斜体。

editor.commands.setItalic()

toggleItalic 切换为斜体。

editor.commands.toggleItalic()

unsetItalic 移除斜体标记。

editor.commands.unsetItalic()

快捷键

CommandWindows/LinuxmacOS
toggleItalic()Control ICmd I

源代码

italic 源代码

在线例子

vue 在线例子

Italic 例子

  • Vue 例子

  • React 例子

<template>
  <div v-if="editor">
    <button @click="editor.chain().focus().toggleItalic().run()" :class="{ 'is-active': editor.isActive('italic') }">
      toggleItalic
    </button>
    <button @click="editor.chain().focus().setItalic().run()" :disabled="editor.isActive('italic')">
      setItalic
    </button>
    <button @click="editor.chain().focus().unsetItalic().run()" :disabled="!editor.isActive('italic')">
      unsetItalic
    </button>
    <editor-content :editor="editor" />
  </div>
</template>
<script>
import Document from '@tiptap/extension-document'
import Italic from '@tiptap/extension-italic'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'

export default {
  components: {
    EditorContent,
  },
  data() {
    return {
      editor: null,
    }
  },
  mounted() {
    this.editor = new Editor({
      extensions: [
        Document,
        Paragraph,
        Text,
        Italic,
      ],
      content: `
        <p>This isn’t italic.</p>
        <p><em>This is italic.</em></p>
        <p><i>And this.</i></p>
        <p style="font-style: italic">This as well.</p>
      `,
    })
  },
  beforeUnmount() {
    this.editor.destroy()
  },
}
</script>
import Document from '@tiptap/extension-document'
import Italic from '@tiptap/extension-italic'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'

export default () => {
  const editor = useEditor({
    extensions: [Document, Paragraph, Text, Italic],
    content: `
        <p>This isn’t italic.</p>
        <p><em>This is italic.</em></p>
        <p><i>And this.</i></p>
        <p style="font-style: italic">This as well.</p>
      `,
  })

  if (!editor) {
    return null
  }

  return (
    <>
      <button
        onClick={() => editor.chain().focus().toggleItalic().run()}
        className={editor.isActive('italic') ? 'is-active' : ''}
      >
        toggleItalic
      </button>
      <button
        onClick={() => editor.chain().focus().setItalic().run()}
        disabled={editor.isActive('italic')}
      >
        setItalic
      </button>
      <button
        onClick={() => editor.chain().focus().unsetItalic().run()}
        disabled={!editor.isActive('italic')}
      >
        unsetItalic
      </button>
      <EditorContent editor={editor} />
    </>
  )
}
Catalog
快速入门 Guide 向导 API 列表 tiptap 方法 tiptap 属性 titap 配置 commands 命令 nodes 节点 marks 标记 Bold 粗体 Code 标签 Highlight 高亮标记 Italic 斜体 Link 超链接 Strike 删除符 Subscript 下标 TextStyle 文本样式 Underline 下划线 Superscript 上标 extensions 扩展