Ruby/html trick: wrap long strings with invisible wordwrap characters
end
This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.
Accessible, manageable, virtualized application stacks ready to download or deploy to the cloud!
Reach me at yan at pritzker.ws
end
Hi Yan,
I stumbled upon this post while looking for a good way to do word wrapping.
Your method looks good, except it could break words inside tags. You might want to check this one out instead: it makes sure not to break words inside and in pre blocks.
I’d thought about tokenizing and making sure to wrap only words between tags, but in the end it was too much overhead for such a simple task, and I guess the above is good enough (actually, it’s perfect if are correctly escaped when not used to surround tags).
I hope this helps. :)
Thanks for the heads up, I also realized there was a bug in my code that would swallow spaces in the string. I fixed the regex not to do that. The link you showed, I found that after I wrote my post. In my case, I actually didn’t care as much about breaking tags because I had only pure strings without tags to deal with. Probably the other implementation is more complete but also, I would guess, slightly slower. Thanks for the link though!
I agree, it’s definitely slower, but well worth it if you have to deal with text containing tags.
© skwpspace. Powered by WordPress using a DePo Clean Theme modified by Yan Pritzker.
3 Comments