Ruby,Textile:如何获取没有标签和纺织格式的纯文本
我的文章正文是纺织格式的文本。我使用 sphinx 进行全文搜索,我想在结果中突出显示查询。 Sphinx 给了我这样的东西,
A *simple* _<span class="highlight">example</span>_.
我想删除所有纺织品格式,但保存突出显示标签,就像这样
A simple <span class="highlight">example</span>.
Is it possible with Redcloth gem?
I have articles with bodies that are textile formatted text. I make full text search with sphinx and I want to highlight query in results. Sphinx give me something like this
A *simple* _<span class="highlight">example</span>_.
I want to remove all textile format but save highlight tags, like this
A simple <span class="highlight">example</span>.
Is it possible with Redcloth gem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 RedCloth 处理内容,然后剥离所有标签的结果。因此,类似:
strip_tags 在 ActionView::Helpers::TextHelper 模块中可用。 http://apidock.com/rails/ActionView/Helpers/TextHelper/strip_tags了解更多信息。
You could process the content with RedCloth and then strip the result of all tags. So something like:
strip_tags is available in the ActionView::Helpers::TextHelper module. http://apidock.com/rails/ActionView/Helpers/TextHelper/strip_tags for more info.
尚未使用 Sphinx,但从您的问题来看,Sphinx 在将文本输出为搜索结果。
我目前不知道 RedCloth 中的任何方法,但 Vidibus-Textile Gem (基于 RedCloth)添加了一个
to_text
方法,这可能对您的情况有用。Ofc 您需要确保在 Sphinx 添加
span
标记之前调用它。Have yet to work with Sphinx, but judging from your question, it appears that
<span class="highlight">..</span>
is added by Sphinx upon outputting the text as a search result.I am currently unaware of any method in RedCloth, but the Vidibus-Textile Gem (based on RedCloth) adds a
to_text
method, which could be useful for your case.Ofc you'd need to make sure it's invoked before Sphinx adds the
span
tags.