Search code examples
javascriptjqueryruby-on-railsrubysummernote

How to derive plain text from summernote text editor


I am using summernote text editor in a rails app. When I type in plain text in the editor, I get html tags and other characters alongside the text i typed in the editor. I would like to know how i can derive just plain text in the output. I tried this solution i found online but I get an error saying 'var is a reserved word'

var plainText = $($("#summernote").summernote("code")).text()

This is the summernote code in my coffee file

$ ->
$('[data-provider="summernote"]').each ->
  $(this).summernote
    height: 300

Solution

  • I finally found a simple solution to this problem and it is without JavaScript. After typing or pasting text into the editor, you have to sanitize the output. So for example, in your show page, you do

          <%= sanitize @job.description %>
    

    Then you derive your plain text without any hassle. `