Add simple_format
to your Gemfile.
gem 'simple_format'
require 'simple_format'
string = "This is a <span src='error'>:ruby:</span> <script type='text/javascript'>alert('Formater');</script>.\n\n Test Auto Link www.ruby-china.com\n\n[email protected]\n\nTest Emoji tag <a href=':cat:'>🍀</a>:ruby-china:."
SimpleFormat.h(string) # Emoji, Auto Link, Sanitize.clean
This is a <span src=\"error\">:ruby:</span> alert('Formater');.<br><br> Test Auto Link <a href=\"http://www.ruby-china.com\" target=\"_blank\">www.ruby-china.com</a><br><br><a href=\"mailto:[email protected]\">[email protected]</a><br><br>Test Emoji tag <a href=\"<img%20class=%22emoji%22%20src=%22//l.ruby-china.com/assets/emojis/cat.png%22%20width=%2264%22%20height=%2264%22%20/>\"><img class=\"emoji\" src=\"//l.ruby-china.com/assets/emojis/four_leaf_clover.png\" width=\"64\" height=\"64\"></a>:ruby-china:.
SimpleFormat.auto_link(string)
This is a <span src='error'>:ruby:</span> <script type='text/javascript'>alert('Formater');</script>.<br /><br /> Test Auto Link <a href='http://www.ruby-china.com' target='_blank'>www.ruby-china.com</a><br /><br /><a href='mailto:[email protected]'>[email protected]</a><br /><br />Test Emoji tag <a href=':cat:'>🍀</a>:ruby-china:.
SimpleFormat.replace_emoji_with_images(string, 24) # Default img size is 64
This is a <span src='error'>:ruby:</span> <script type='text/javascript'>alert('Formater');</script>.\n\n Test Auto Link www.ruby-china.com\n\[email protected]\n\nTest Emoji tag <a href='<img class=\"emoji\" src=\"//l.ruby-china.com/assets/emojis/cat.png\" width=\"24\" height=\"24\" />'><img class=\"emoji\" src=\"//l.ruby-china.com/assets/emojis/four_leaf_clover.png\" width=\"24\" height=\"24\" /></a>:ruby-china:.
SimpleFormat.clean(string, {elements: [], attributes: { all: [] }})
=> "This is a :ruby: alert('Formater');.\n\n Test Auto Link www.ruby-china.com\n\n[email protected]\n\nTest Emoji tag 🍀:ruby-china:."