github.com/jamescook/rinku-crystal
master / published Jun 21, 2020 / repository
Autolinking
rinku-crystal
Bindings for Rinku, an autolinker
Installation
-
Add the dependency to your
shard.yml:dependencies: rinku-crystal: github: jamescook/rinku-crystal -
Run
shards install -
Compile the Rinku library and copy it to where your platform stores libraries (e.g. /usr/local/lib). The
Makefilein this repo may work for your platform.
Usage
require "rinku"
Rinku.auto_link("www.google.com and some more text")
=> "<a href=\"http://www.google.com\">www.google.com</a> and some more text"
Rinku.auto_link("Email address goes here somebody@the-internet.xyz")
=> "Email address goes here <a href=\"mailto:somebody@the-internet.xyz\">somebody@the-internet.xyz</a>"
# Mode can be one of :all, :email or :urls
Rinku.auto_link("auto link url www.bing.com:8080/42 and do not link email somebody@the-internet.xyz", :urls)
=> "auto link url <a href=\"http://www.bing.com:8080/42\">www.bing.com:8080/42</a> and do not link email somebody@the-internet.xyz"
Benchmark
Run crystal run --release bench.cr to check performance on your platform compared with Autolink. On the author's machine:
Autolink 3.20k (312.85µs) (± 2.09%) 43.2kB/op 51.63× slower
Rinku 165.05k ( 6.06µs) (± 2.58%) 2.08kB/op fastest
The larger the string, the faster Rinku is compared to Autolink.
Contributing
- Fork it (https://github.com/jamescook/rinku-crystal/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- James Cook - creator and maintainer