basecamp / trix

A rich text editor for everyday writing
https://trix-editor.org/
MIT License
18.86k stars 1.11k forks source link

Insert image to trix-editor through javascript #1055

Open adiubaidah opened 1 year ago

adiubaidah commented 1 year ago

Does anyone know how to insert attachment in trix editor with javascript ?,

  1. I have the image through the url, and that url is working properly
  2. and when i use const attachment = new Trix.Attachment({content : url}) and insertAttachment, it only display the url not the image
stanj98 commented 6 months ago

Hey, have you found a solution to this?

andrii-baran-nfgp commented 5 months ago

Have you tried?

new Trix.Attachment({content : url, contentType:"image"})
sejutaimpian commented 2 months ago
function addImageUrl(url, caption) {
    const attachment = new Trix.Attachment({ filename: caption, url: url, contentType: "image/png" })
    element.editor.insertAttachment(attachment)
}

this worked for me.