Reputation: 368
I would like to use the rich text editor trix in rails6. How can I add a button to trix which adds html content?
Upvotes: 4
Views: 1818
Reputation: 399
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
Upvotes: 1
Reputation: 36
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?
Upvotes: 2