ueberdosis / tiptap

The headless rich text editor framework for web artisans.
https://tiptap.dev
MIT License
27.56k stars 2.29k forks source link

Older wrapping using span removes while call the plugin again to add another span wrapping for same text #4199

Open shilpa9608 opened 1 year ago

shilpa9608 commented 1 year ago

Which packages did you experience the bug in?

custom extension

What Tiptap version are you using?

2.0.0-beta.113

What’s the bug you are facing?

The older wrapping using span removes to add new wrapping . How to avoid this ??


import {
    Mark,
    markInputRule,
    markPasteRule,
    mergeAttributes,
  } from '@tiptap/core'

  export interface InsertionDiffOptions {
    HTMLAttributes: Record<string, any>,
  }

  declare module '@tiptap/core' {
    interface Commands<ReturnType> {
        contentInsertion: {

        setInsertion: (options: {
            commentid: string;

        }) => ReturnType,

        toggleInsertion: () => ReturnType,

        unsetInsetion: () => ReturnType,
      }
    }
  }

  export const InsertionDiff = Mark.create<InsertionDiffOptions>({
    name: 'contentInsertion',

    addOptions() {
      return {
        HTMLAttributes: {},
      }
    },
    addAttributes(){
        return{
            commentid:{
                default:''
            }
        }
    },

    parseHTML() {
      return [
        {
          tag: 'span',
        },

      ]
    },

    renderHTML({ HTMLAttributes }) {
      const styleAttr = {class: "highlighter"}
      return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes,styleAttr), 0]
    },

    addCommands() {
      return {
        setInsertion: (options) => ({ commands }) => {
          return commands.setMark(this.name,options)
        },
        toggleInsertion: () => ({ commands }) => {
          return commands.toggleMark(this.name)
        },
        unsetInsetion: () => ({ commands }) => {
          return commands.unsetMark(this.name)
        },
      }
    },

  })

### What browser are you using?

Chrome

### Code example

_No response_

### What did you expect to happen?

We need to keep all span wrapping for the given text.

### Anything to add? (optional)

_No response_

### Did you update your dependencies?

- [X] Yes, I’ve updated my dependencies to use the latest version of all packages.

### Are you sponsoring us?

- [X] Yes, I’m a sponsor. 💖
shilpa9608 commented 1 year ago

Hello team..

ashu12chi commented 1 year ago

The parsing of content is controlled by Prosemirror. When the prosemirror see nested span tag, it only considers the outer one, and discard the inner tag. Can you explain your exact use case why you need nested span tag?

The better way is to use the textStyle plugin for rendering span tag similar to color and font-family plugin.

shilpa9608 commented 1 year ago

Screenshot from 2023-07-17 11-48-48 (1)

We need a span wrapping like this. While adding each comment , we need to wrap the text node with new span..