【问题标题】:Truncate - unexpected result with sanitize(RedCloth.new(object))截断 - 清理后的意外结果(RedCloth.new(object))
【发布时间】:2012-09-10 03:12:26
【问题描述】:

我想使用 RedCloth 输出一些文本。我试图弄清楚这是如何工作的,但我无法得到我想要的结果。

使用的代码:

truncate(sanitize(RedCloth.new("*some* interesting text")).to_html, length: 6)

结果:

*一些*

预期结果:

一些我...

【问题讨论】:

    标签: ruby-on-rails ruby truncate sanitize redcloth


    【解决方案1】:

    我才意识到问题所在。我没有注意我的代码。我需要用 sanitize 反向截断 :) Wops!

    sanitize(truncate(RedCloth.new("*some* interesting text").to_html, length: 6, separator: " "))
    

    这给了我我需要的结果。您还必须使用分隔符:“”以使其看起来干净。

    【讨论】:

    • 如果解决了,您能否将自己的答案标记为“已接受”?在浏览与 ruby​​ 相关的问题以寻找未解决的案例时,它会有所帮助:)
    猜你喜欢
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多