2

I would like to use the rich text editor trix in rails6. How can I add a button to trix which adds html content?

Chris
  • 318
  • 1
  • 15

2 Answers2

2

To allow ActionText showing raw HTML, try this.

<%= raw your_action_text_object.to_plain_text %>

btw, I don't know why you want to add a button, could you explain in detail?

Ash
  • 36
  • 3
  • 2
    I'm interested too in a button that permits to paste html inside the trix input. For example to add a link (as foo) copied from other pages html. – Donapieppo Feb 10 '21 at 08:09
1

Assuming that you want to do it using javascript, when clicking on a button, you'll need to fetch the rich_text element and then apply the raw html, as follows:

const element = document.getElementById('your-id-here')
element.editor.loadHTML('<div>HTML<br>HERE</div>')

font: https://github.com/basecamp/trix/issues/344#issuecomment-261939749

Bruno Gerotto
  • 369
  • 2
  • 11