How can I use strip_tags in regular Ruby code (non-rails)?(如何在常规 Ruby 代码(非 Rails)中使用 strip_tags?)
问题描述
我需要将 HTML 转换为纯文本.ActionView 的 SanitizeHelper 中有一个很好的功能,但我无法理解如何引用它并在简单的 test.rb 文件中使用它.
I need to turn HTML into plain text. There's a nice function that does that in ActionView's SanitizeHelper, but I have trouble understanding how I can reference it and use it in a simple test.rb file.
http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html
我希望能够调用 strip_tags("<b>lol</b>") =>哈哈"
推荐答案
这个问题很老了,但我最近也遇到了同样的问题.我找到了一个简单的解决方案:gem sanitize.它很轻,工作正常,并且如果您需要它们还有其他选项.
The question is quite old, but I had the same problem recently. I found a simple solution: gem sanitize. It's light, works fine and has additional options if you need them.
Sanitize.clean("<b>lol</b>") #=> "lol"
这篇关于如何在常规 Ruby 代码(非 Rails)中使用 strip_tags?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在常规 Ruby 代码(非 Rails)中使用 strip_tags?
基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
