开发者

Get length of rendered HTML on Rails server

How could I get the length on the server side of of a HTML string after it was rendered.

E.g. A&amp;B<a href="http://www.abc.org">C</a> has a length of 4 after it was rendered.

On the client side this would be pretty easy using for example jQuery. Just pack it in a d开发者_运维百科iv and call $("div").text().length.

But what can I use on the server side using Ruby/Rails?

Update

I guess Mike is right that there is no direct solution for that. But is there a library that let me easily convert special entities like &amp; to the normal presentation (&)?

Update of Update ;-)

I think http://htmlentities.rubyforge.org/ will do the trick.


I have a feeling this isn't built in as Rails strictly returns the HTML for the browser to parse and render. Rails has no idea how the HTML will be rendered to the user.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜