我的应用会发送电子邮件。如果有一个很长的字词或一个很长的网址,那么就不会让iphone变焦广告收紧,从而破坏了电子邮件的观看体验。
这是我到目前为止所提出的但是没有用,想法?
辅助
def html_format(string, max_width=12)
text = string.gsub("\n", '<br />').html_safe.strip
(text.length < max_width) ?
text :
text.scan(/.{1,#{max_width}}/).join("<wbr>")
return text
end
查看
<%= html_format(@comment.content) %>
答案 0 :(得分:3)
这是一个method I found online似乎适用于使用<wbr>
分割长字符串:
def split_str(str, len = 10)
fragment = /.{#{len}}/
str.split(/(\s+)/).map! { |word|
(/\s/ === word) ? word : word.gsub(fragment, '\0<wbr />')
}.join
end
答案 1 :(得分:0)
This post显示了如何用正则表达式包装长单词。