react-quill icon indicating copy to clipboard operation
react-quill copied to clipboard

How do I insert <div> in the editor

Open sarunx93 opened this issue 1 year ago • 8 comments

Hi there. I'm having problems inserting

in quill editor when click a button in toolbar. It seems like my html tag has been distorted (e.g. styles got removed, div appeared as p, etc.)

I also used this.quill.clipboard.dangerouslyPasteHTML to deal with my html code. Below is the code snippet. Any helps will be highly appreciated. Thanks.

import React, { useState } from 'react'
//stop server side rendering when using react quill with next js
import dynamic from 'next/dynamic'
const ReactQuill = dynamic(() => import('react-quill'), { ssr: false })
import CustomToolbar from '../../quill/CustomToolbar'



function htmlInsert(){
    const cursorPosition = this.quill.getSelection().index
    console.log(cursorPosition)
    const html = `<div style="padding:100px; border: 2px solid black;">
                        <h1 style="display:block; color: red; width:100px;">this is new text</h1>
                    </div>`
    this.quill.clipboard.dangerouslyPasteHTML(cursorPosition, html)
}



const QuillEditor = ()=>{
    const [value, setValue] = useState('')

    const modules = {
        toolbar:{
            container:'#toolbar',
            handlers:{
                insertStar: insertStar,
                htmlInsert: htmlInsert,
            }
        },
    }

    return (
        <>
            <div className='container'>
                <div className='ql-editor' style={{backgroundColor:'white', color:'black'}}>
                    <CustomToolbar value={value} clickFunc={insertStar}/>
                    <ReactQuill
                        theme='snow'
                        value={value}
                        onChange={setValue}
                        modules={modules}
                        placeholder='type something'
                    />
                </div>
                <br/>
            </div>

        </>
    )
}
export default QuillEditor

sarunx93 avatar May 30 '23 10:05 sarunx93

Same problem here 🤔

MarcosRuginski avatar Jun 20 '23 00:06 MarcosRuginski

Same problem +

alfeilex avatar Aug 26 '23 17:08 alfeilex

same here, found no solution

muhammad-imraan avatar Jan 04 '24 14:01 muhammad-imraan

same

Jhessiny avatar Jan 30 '24 13:01 Jhessiny

Same Issue

sagar5580 avatar May 15 '24 06:05 sagar5580

Im in 2 hours in this question right now, still nothing

tiredpyrx avatar Jun 14 '24 21:06 tiredpyrx

same

finalize avatar Aug 01 '24 01:08 finalize