The Rails Actionview::helpers::texthepler module provides a number of practical methods that are useful for forum class applications, such as Auto_link, which automatically detects URLs in incoming strings. and automatically converts it to HTML hyperlink format, which is good for displaying the content of a post.
But in the development of JavaEye3.0, but found that auto_link have bugs, once the post URL followed by Chinese words, auto_link will be the URL after all the Chinese as a part of the URL format, until you hit a space, for example:
Reference
Http://www.javaeye.com website is very good
will be formatted as:
Reference
<a href= "http://www.javaeye.com site is very good" >http://www.javaeye.com site is very good </a>
It looks like you've got the source code in rails to find the answer.
Open NetBeans, hit the shortcut key Ctrl+o, in the pop-up window input: Texthelper, enter, NetBeans has helped me open the TEXT_HELPER.RB source code, through the Navigator window, very convenient to locate the Auto_link method, To take a closer look, the main fact is that this regular expression is at work:
Ruby Code
Auto_link_re =%r{
(# leading text
<\w+.*?>| # leading HTML tag, or
[^=!: '/]| # leading punctuation, or
^ # beginning of line
)
(
(?: HT tps?:/ /)| # protocol Spec, or
(?: www\.) # www.*
)
(
[-\w]+ # subdomain or domain
(?: \. [-\w]+) * # remaining subdomains or domain
(?:: \d+)? # Port
(?:/ (?:(?: [~\w\+%-]| (?: [,.;:][^\s$]) +)?) * # Path
(?: \? [\w\+%&=.; -]+)? # query string
(?: \ #[\w\-]*)? # trailing anchor
)
([[:p unct:]]|\s|<|$) # trailing text
}x unless const_d Efined? (: Auto_link_re)