slab / parchment

Generalized state model for rich-text editors to interface with browser DOM
BSD 3-Clause "New" or "Revised" License
628 stars 143 forks source link

Remove Byte Order Mark (BOM) characters from Blot #124

Closed asebold closed 1 year ago

asebold commented 1 year ago

Any time I create an embed blot, and it's inserted into a quill editor, the contents of the blot are wrapped in a span with BOM characters on both ends of it ().

These are invisible characters that cause all kinds of problems for my app, but I can't figure out where they're coming from.

What is the purpose of including these characters in blots, and is it possible to get rid of them?

Code generated in browser: Screenshot from 2023-02-20 20-48-51

Code I used to create this blot:

let EmbedBlot = Quill.import('blots/embed');

class TagSelectBlot extends EmbedBlot {
    static create(){
        let tags = ['tag1','tag2']
        let node = super.create()
        node.setAttribute('data-tags',tags.join(','))
        node.classList.add('dropdown-menu')
        node.setAttribute('contenteditable', false);
        node.innerHTML = `<li class="dropdown-content"><a class="dropdown-item">${
            tags[0]
        }</a></li><li class="dropdown-content"><a class="dropdown-item">${tags[1]}</a></li>`        
        return node
    }

    static value(node){
        let tags = node.getAttribute('data-tags')
        return tags.split(',')
    }
}

TagSelectBlot.blotName = 'tag-select';
TagSelectBlot.tagName = 'ul';
TagSelectBlot.className = 'pf-editor-tag-select'
luin commented 1 year ago

Hey @asebold 👋

They are needed to hold the cursor. What particular issues did you encounter? Let's see if there are solutions for that.

asebold commented 1 year ago

My app searches the content created by the editor and takes actions based on certain embeds. The invisible characters have made searching difficult, but I've been able to work around it so far.

If they are necessary for holding the cursor, I can continue to work around them. Mainly, I wanted to get a better understanding of why they are there.

luin commented 1 year ago

Yeah they are necessary for holding the cursor. Closing. Feel free to reopen if there are any concerns or suggestions.