I have the following string as an example
"<p>Hello,</p><p><br></p><p>my name is Same</p><p><br></p><p><br></p><p>Farewell,</p><p>Same</p>"
And I would like to strip all HTML tags from it. I was using the following method which kind of worked
Nokogiri::HTML(CGI.unescapeHTML(@message_preview)).content
But it ultimately produced,
"Hello,my name is SameFarewell,Same"
When I wanted
"Hello, my name is Same Farewell, Same"
Notice the spaces, given a line break, I want there to be a space in its place instead of being the very next character in the string.
I was hoping to try to use gsub or regex but am kind of lost on how to make it happen.
<br>with a space before your remove the HTML tags!? Also to trim multiple spaces to a single one (in case of multiple line breaks).@message_preview.gsub!(/<br>/, ' ')But i just realized I need to account for a whole host of html tags because of the keyboard options. Bold, italic, underline, ol, ul, quotes etc. So I need to find a way to include all that in my gsub and then run the nokogirinokogiridoing this as a Regex is a bad idea