How to partially escapeHTML in Ruby (dont escape HTML tags)

105 Views Asked by At

I ned to write a string that could escape both these strings.

str = "We couldn't help"
str = "We couldn't help."

I achieved that using

CGI.escapeHTML(CGI.unescapeHTML(str))

Now however I have a new requirement of accomodating HTML tags as well.

str = "We couldn&#39;t help. Check <a href = https://www.google.com>link</a> for help"

How can I escape the string except the HTML tags ? So that I can escape all these 3 kinds of strings.

0

There are 0 best solutions below