首页 > 代码库 > rails 字符串 转化为 html
rails 字符串 转化为 html
simple_format http://apidock.com/rails/v4.0.2/ActionView/Helpers/TextHelper/simple_format http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html my_text = "Here is some basic text...\n...with a line break." simple_format(my_text) # => "<p>Here is some basic text...\n<br />...with a line break.</p>" simple_format(my_text, {}, wrapper_tag: "div") # => "<div>Here is some basic text...\n<br />...with a line break.</div>" more_text = "We want to put a paragraph...\n\n...right there." simple_format(more_text) # => "<p>We want to put a paragraph...</p>\n\n<p>...right there.</p>" simple_format("Look ma! A class!", class: ‘description‘) # => "<p class=‘description‘>Look ma! A class!</p>" simple_format("<blink>Unblinkable.</blink>") # => "<p>Unblinkable.</p>" simple_format("<blink>Blinkable!</blink> It‘s true.", {}, sanitize: false) # => "<p><blink>Blinkable!</span> It‘s true.</p>" 一个\n被认为是换行其之后是<br/> 两个\n被认为是分段其之前是</p>之后<p> If you want to escape all content, you should invoke the h method before calling the text helper. simple_format h(‘<a href="http://example.com/">Example</a>‘) # => "<p><a href=http://www.mamicode.com/"http://example.com/\">Example</a></p>"
rails 字符串 转化为 html
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。