百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rinku

> 编程语言
开源

自动链接。Ruby。是的,大致就是这样。

599 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

自动链接。Ruby。是的,大致就是这样。

Rinku does linking

Rinku is a Ruby library that does autolinking. It parses text and turns anything that remotely resembles a link into an HTML link, just like the Ruby on Rails auto_link method -- but it's about 20 times faster, because it's written in C, and it's about 20 times smarter when linking, because it does actual parsing instead of RegEx replacements.

Rinku is a Ruby Gem

Rinku is available as a Ruby gem:

$ [sudo] gem install rinku

The Rinku source is available at GitHub:

$ git clone git://github.com/vmg/rinku.git

Rinku is a standalone library

It exports a single method called Rinku.auto_link.

ruby
require 'rinku'

Rinku.auto_link(text, mode=:all, link_attr=nil, skip_tags=nil)
Rinku.auto_link(text, mode=:all, link_attr=nil, skip_tags=nil) { |link_text| ... }

Parses a block of text looking for "safe" urls or email addresses, and turns them into HTML links with the given attributes.

NOTE: The block of text may or may not be HTML; if the text is HTML, Rinku will skip the relevant tags to prevent double-linking and linking inside pre blocks by default.

NOTE: If the input text is HTML, it's expected to be already escaped. Rinku will perform no escaping.

NOTE: Currently the follow protocols are considered safe and are the only ones that will be autolinked.

http:// https:// ftp:// mailto://

Email addresses are also autolinked by default. URLs without a protocol specifier but starting with 'www.' will also be autolinked, defaulting to the 'http://' protocol.

  • text is a string in plain text or HTML markup. If the string is formatted in HTML, Rinku is smart enough to skip the links that are already enclosed in `` tags.`

  • mode is a symbol, either :all, :urls or :email_addresses, which specifies which kind of links will be auto-linked.

  • link_attr is a string containing the link attributes for each link that will be generated. These attributes are not sanitized and will be include as-is in each generated link, e.g.

    ruby
     auto_link('http://www.pokemon.com', :all, 'target="_blank"')
     # => 'http://www.pokemon.com'

    This string can be autogenerated from a hash using the Rails tag_options helper.

  • skip_tags is a list of strings with the names of HTML tags that will be skipped when autolinking. If nil, this defaults to the value of the global Rinku.skip_tags, which is initially ["a", "pre", "code", "kbd", "script"].

  • &block is an optional block argument. If a block is passed, it will be yielded for each found link in the text, and its return value will be used instead of the name of the link. E.g.

    ruby
    auto_link('Check it out at http://www.pokemon.com') do |url|
      "THE POKEMAN WEBSITEZ"
    end
    # => 'Check it out at THE POKEMAN WEBSITEZ'

Rinku is a drop-in replacement for Rails 3.1 auto_link

Auto-linking functionality has been removed from Rails 3.1, and is instead offered as a standalone gem, rails_autolink. You can choose to use Rinku instead.

ruby
require 'rails_rinku'
include ActionView::Helpers::TextHelper
post_body = "Welcome to my new blog at http://www.myblog.com/."
auto_link(post_body, :html => { :target => '_blank' }) do |text|
  truncate(text, :length => 15)
end
# => "Welcome to my new blog at http://www.m...."

The rails_rinku package monkeypatches Rails with an auto_link method that mimics 100% the original one, parameter per parameter. It's just faster.

Developing

$ gem install rake-compiler

$ rake

Rinku is written by me

I am Vicent Marti, and I wrote Rinku. While Rinku is busy doing autolinks, you should be busy following me on twitter. @vmg. Do it.

Rinku has an awesome license

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言