Giter Site home page Giter Site logo

rinku's Introduction

Rinku

Due to the absence of external maintenance, this is now a fully Zendesk owned/maintained gem.

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/zendesk/rinku.git

Rinku is a standalone library

It exports a single method called Rinku.auto_link.

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 <a> 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.

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

    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.

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

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.

require 'rails_rinku'

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

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.

rinku's People

Contributors

vmg avatar shajith avatar saturnflyer avatar erebor avatar ckumar1 avatar razumau avatar dbuchi avatar rtomayko avatar bquorning avatar henare avatar jcheatham avatar brianmario avatar sr avatar vanchi-zendesk avatar grosser avatar

Stargazers

 avatar Felipe Monteiro avatar David Kuhta avatar lopez avatar luigi avatar

Watchers

Piotr Płaneta avatar Morten Primdahl avatar Anatoly Mikhaylov avatar  avatar Antek Piechnik avatar Vijay Mani avatar Juris Galang avatar Marcos Oliveira avatar Daniel Engel avatar Michael Melia avatar Wesley Gorman avatar Sivakumar Krishnamurthy avatar Mariusz Lusiak avatar ian waters avatar  avatar Saroj Yadav avatar JD Manuel avatar Clara Bettina Behrmann avatar John Isaac avatar Rasmus Barfoed avatar Laszlo Papp avatar VEERA V G avatar Eugene Chinveeraphan avatar Aaron Santos avatar Michael Van Winkle avatar Robert Carter avatar Prakriti Mateti avatar Maxime Prades avatar Jason Smale avatar Sarmad Sangi avatar Miguel Molina avatar TianQi avatar Leonardo Rodrigues de Mello avatar James Cloos avatar Đặng Tiến Cường avatar wai chee yau avatar Shawn Lim avatar Dinesh Saravanan Kumaraswamy avatar Suthagaran Kurusamy avatar Anton de Young avatar Eric Weaver avatar Matt Daley avatar Hoang Trinh Vu avatar Szymon Wladyka avatar Dara McHugh avatar Jakub Glodek avatar Anthony Woo avatar Luigi Antonini avatar Stephanie Wei avatar Steve Loyd avatar Amit Singhal avatar Erin Boyle avatar Adam Panzer avatar James Dietrich avatar luigi avatar Jeff Pierce avatar Colton Ericksen avatar Grigori Goldman avatar Michał Partyka avatar Sofia Margariti avatar Nicolò Calcavecchia avatar Max McCal avatar Michael Ferguson avatar Amy Au-Yeung avatar Lo Sheng avatar Colum Twomey avatar Alexander Brown avatar Jammaica Mae Ignacio avatar Marcus Kim avatar Tim Fewkes avatar James Reilly avatar Henry Thompson avatar Cuthbert Guerrero avatar Sidhartha Saurav avatar Umashankar Rajaram avatar Tony Xu avatar Cemre Alpsoy avatar Lukasz Macionczyk avatar Bjornar Sandvik avatar Jakub Nowak avatar Benjamin BOCCARA avatar Pitt Fagan avatar Krzysztof Bober avatar Yi Li avatar Ayala Levine avatar Darlene Pascua avatar Casper Szymiczek-Graley avatar Kevin Beattie avatar Oscar Junker avatar  avatar Jon Brummel avatar Carl Mahoney avatar Adi Glasman avatar Joshua Daniel avatar Adam Hart avatar Royston Tay avatar Troy Witt avatar Ikpons Idelegbagbon avatar Dino Rošić avatar Pawel Gocek avatar

Forkers

nebopolis hparker

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.