0.0
No commit activity in last 3 years
No release in over 3 years
Returns text transformed into HTML using simple formatting rules.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0

Runtime

 Project Readme

simple_format

  • Translate emoji name or unicode to HTML images.
  • Auto Link url and email.
  • Clean HTML elements and attributes.

Gem Version Dependency Status Code Climate

Installation

Add simple_format to your Gemfile.

gem 'simple_format'

Usage

require 'simple_format'
c = SimpleFormat::Converter.new
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\nmail@domain.com\n\nTest Emoji tag <a href=':cat:'>🍀</a>:ruby-china:." # 测试文本

c.rich_with(string) # 富文本转换(Emoji, nl2br, 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:mail@domain.com\">mail@domain.com</a><br><br>Test Emoji tag <a href=\"&lt;img%20class=%22emoji%22%20src=%22//l.ruby-china.org/assets/emojis/cat.png%22%20width=%2264%22%20height=%2264%22%20/&gt;\"><img class=\"emoji\" src=\"//l.ruby-china.org/assets/emojis/four_leaf_clover.png\"></a>:ruby-china:."

c.auto_link('www.ruby-china.org') # 自动链接
=> "<a href='//www.ruby-china.org' target='_blank'>www.ruby-china.org</a>"

c.emoji_with('🍀') # 表情符
=> "<img class=\"emoji\" src=\"//l.ruby-china.org/assets/emojis/four_leaf_clover.png\" />"

c.text_with(string) # 清除 HTML
=> "This is a :ruby: alert('Formater');.\n\n Test Auto Link www.ruby-china.com\n\nmail@domain.com\n\nTest Emoji tag 🍀:ruby-china:."