tiptap 中文文档

tiptap Strike 删除符

tiptap Strike 扩展会渲染成删除符,内联样式 text-decoration: line-through 有同样的效果。

Install 安装

npm install @tiptap/extension-strike

Settings 配置

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

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

Commands 命令

setStrike 标记文本为删除符。

editor.commands.setStrike()

toggleStrike 切换删除符。

editor.commands.toggleStrike()

unsetStrike 移除删除符。

editor.commands.unsetStrike()

快捷键

CommandWindows/LinuxmacOS
toggleBold()Control Shift XCmd Shift X

源代码

strike 源代码

在线例子

vue 在线例子

Strike 例子

  • Vue 例子

  • React 例子

<template>
  <div v-if="editor">
    <button @click="editor.chain().focus().toggleStrike().run()" :class="{ 'is-active': editor.isActive('strike') }">
      toggleStrike
    </button>
    <button @click="editor.chain().focus().setStrike().run()" :disabled="editor.isActive('strike')">
      setStrike
    </button>
    <button @click="editor.chain().focus().unsetStrike().run()" :disabled="!editor.isActive('strike')">
      unsetStrike
    </button>
    <editor-content :editor="editor" />
  </div>
</template>
<script>
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Strike from '@tiptap/extension-strike'
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,
        Strike,
      ],
      content: `
          <p>This isn’t striked through.</s></p>
          <p><s>But that’s striked through.</s></p>
          <p><del>And this.</del></p>
          <p><strike>This too.</strike></p>
          <p style="text-decoration: line-through">This as well.</p>
        `,
    })
  },
  beforeUnmount() {
    this.editor.destroy()
  },
}
</script>
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Strike from '@tiptap/extension-strike'
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, Strike],
    content: `
          <p>This isn’t striked through.</s></p>
          <p><s>But that’s striked through.</s></p>
          <p><del>And this.</del></p>
          <p><strike>This too.</strike></p>
          <p style="text-decoration: line-through">This as well.</p>
        `,
  })

  if (!editor) {
    return null
  }

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