rinku 2.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +2 -0
- data/README.markdown +9 -0
- data/Rakefile +6 -44
- data/ext/rinku/autolink.c +33 -14
- data/lib/rinku.rb +1 -1
- data/rinku.gemspec +5 -4
- data/test/autolink_test.rb +40 -4
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2982203836f1449fe5344a32f7ab1782f3cb4cc7
|
4
|
+
data.tar.gz: 8461bfe12528f128cba4e81e9fb8f64e9903e6e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3587f9e83406d7829cdbec671980536803f3b9e0ed87e6daf8e21389dad8d2cc521d49527b602e3ccaa7e40f3c41ef365ba4bbb42a0b69d6ed7c412bbdd914f3
|
7
|
+
data.tar.gz: 68aa755836af8269edc44bcd4ae8134abe6a3bd7836140218f4bd618069f22ad16ff78c6814610f2525ca5f64cfac8657e2021c0ee238e1ba5d319e6efeb728c
|
data/COPYING
CHANGED
data/README.markdown
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
Rinku does linking
|
2
2
|
==================
|
3
3
|
|
4
|
+
[![Build Status](https://travis-ci.org/vmg/rinku.svg?branch=master)](https://travis-ci.org/vmg/rinku)
|
5
|
+
[![Dependency Status](https://www.versioneye.com/ruby/rinku/badge.svg)](https://www.versioneye.com/ruby/rinku)
|
6
|
+
|
4
7
|
Rinku is a Ruby library that does autolinking.
|
5
8
|
It parses text and turns anything that remotely resembles a link into an HTML link,
|
6
9
|
just like the Ruby on Rails `auto_link` method -- but it's about 20 times faster,
|
@@ -91,6 +94,12 @@ choose to use Rinku instead.
|
|
91
94
|
|
92
95
|
~~~~ruby
|
93
96
|
require 'rails_rinku'
|
97
|
+
include ActionView::Helpers::TextHelper
|
98
|
+
post_body = "Welcome to my new blog at http://www.myblog.com/."
|
99
|
+
auto_link(post_body, :html => { :target => '_blank' }) do |text|
|
100
|
+
truncate(text, :length => 15)
|
101
|
+
end
|
102
|
+
# => "Welcome to my new blog at <a href=\"http://www.myblog.com/\" target=\"_blank\">http://www.m...</a>."
|
94
103
|
~~~~
|
95
104
|
|
96
105
|
The `rails_rinku` package monkeypatches Rails with an `auto_link` method that
|
data/Rakefile
CHANGED
@@ -1,50 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
3
|
require 'rake/extensiontask'
|
4
|
-
require 'digest/md5'
|
5
|
-
|
6
|
-
task :default => :test
|
7
|
-
|
8
|
-
# ==========================================================
|
9
|
-
# Ruby Extension
|
10
|
-
# ==========================================================
|
11
|
-
|
12
|
-
Rake::ExtensionTask.new('rinku')
|
13
|
-
|
14
|
-
# ==========================================================
|
15
|
-
# Testing
|
16
|
-
# ==========================================================
|
17
|
-
|
18
4
|
require 'rake/testtask'
|
19
|
-
Rake::TestTask.new('test') do |t|
|
20
|
-
t.test_files = FileList['test/*_test.rb']
|
21
|
-
t.ruby_opts += ['-rubygems'] if defined? Gem
|
22
|
-
end
|
23
|
-
task 'test' => [:compile]
|
24
5
|
|
25
|
-
|
6
|
+
task default: :test
|
26
7
|
|
27
|
-
|
28
|
-
$spec = eval(File.read('rinku.gemspec'))
|
8
|
+
Rake::ExtensionTask.new('rinku') # defines compile task
|
29
9
|
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
desc 'Build packages'
|
35
|
-
task :package => package('.gem')
|
36
|
-
|
37
|
-
desc 'Build and install as local gem'
|
38
|
-
task :install => package('.gem') do
|
39
|
-
sh "gem install #{package('.gem')}"
|
40
|
-
end
|
41
|
-
|
42
|
-
desc 'Update the gemspec'
|
43
|
-
task :update_gem => file('rinku.gemspec')
|
44
|
-
|
45
|
-
directory 'pkg/'
|
46
|
-
|
47
|
-
file package('.gem') => %w[pkg/ rinku.gemspec] + $spec.files do |f|
|
48
|
-
sh "gem build rinku.gemspec"
|
49
|
-
mv File.basename(f.name), f.name
|
10
|
+
Rake::TestTask.new(test: :compile) do |t|
|
11
|
+
t.test_files = FileList['test/*_test.rb']
|
50
12
|
end
|
data/ext/rinku/autolink.c
CHANGED
@@ -99,14 +99,10 @@ autolink_delim(const uint8_t *data, struct autolink_pos *link)
|
|
99
99
|
}
|
100
100
|
|
101
101
|
if (copen != 0) {
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
/* Try to close the final punctuation sign in this same line;
|
107
|
-
* if we managed to close it outside of the URL, that means that it's
|
108
|
-
* not part of the URL. If it closes inside the URL, that means it
|
109
|
-
* is part of the URL.
|
102
|
+
/* Try to close the final punctuation sign in this link; if
|
103
|
+
* there's more closing than opening punctuation symbols in the
|
104
|
+
* URL, we conservatively remove one closing punctuation from
|
105
|
+
* the end of the URL.
|
110
106
|
*
|
111
107
|
* Examples:
|
112
108
|
*
|
@@ -117,12 +113,16 @@ autolink_delim(const uint8_t *data, struct autolink_pos *link)
|
|
117
113
|
* => http://www.pokemon.com/Pikachu_(Electric)
|
118
114
|
*
|
119
115
|
* foo http://www.pokemon.com/Pikachu_(Electric)) bar
|
120
|
-
* => http://www.pokemon.com/Pikachu_(Electric)
|
116
|
+
* => http://www.pokemon.com/Pikachu_(Electric)
|
121
117
|
*
|
122
118
|
* (foo http://www.pokemon.com/Pikachu_(Electric)) bar
|
123
|
-
* =>
|
119
|
+
* => http://www.pokemon.com/Pikachu_(Electric)
|
124
120
|
*/
|
125
121
|
|
122
|
+
size_t closing = 0;
|
123
|
+
size_t opening = 0;
|
124
|
+
size_t i = link->start;
|
125
|
+
|
126
126
|
while (i < link->end) {
|
127
127
|
if (data[i] == copen)
|
128
128
|
opening++;
|
@@ -132,13 +132,32 @@ autolink_delim(const uint8_t *data, struct autolink_pos *link)
|
|
132
132
|
i++;
|
133
133
|
}
|
134
134
|
|
135
|
-
if (closing
|
135
|
+
if (closing > opening)
|
136
136
|
link->end--;
|
137
137
|
}
|
138
138
|
|
139
139
|
return true;
|
140
140
|
}
|
141
141
|
|
142
|
+
static bool
|
143
|
+
autolink_delim_iter(const uint8_t *data, struct autolink_pos *link)
|
144
|
+
{
|
145
|
+
size_t prev_link_end;
|
146
|
+
int iterations = 0;
|
147
|
+
|
148
|
+
while(link->end != 0) {
|
149
|
+
prev_link_end = link->end;
|
150
|
+
if (!autolink_delim(data, link))
|
151
|
+
return false;
|
152
|
+
if (prev_link_end == link->end || iterations > 5) {
|
153
|
+
break;
|
154
|
+
}
|
155
|
+
iterations++;
|
156
|
+
}
|
157
|
+
|
158
|
+
return true;
|
159
|
+
}
|
160
|
+
|
142
161
|
static bool
|
143
162
|
check_domain(const uint8_t *data, size_t size,
|
144
163
|
struct autolink_pos *link, bool allow_short)
|
@@ -198,7 +217,7 @@ autolink__www(
|
|
198
217
|
return false;
|
199
218
|
|
200
219
|
link->end = utf8proc_find_space(data, link->end, size);
|
201
|
-
return
|
220
|
+
return autolink_delim_iter(data, link);
|
202
221
|
}
|
203
222
|
|
204
223
|
bool
|
@@ -244,7 +263,7 @@ autolink__email(
|
|
244
263
|
break;
|
245
264
|
}
|
246
265
|
|
247
|
-
if ((link->end - pos) < 2 || nb != 1 || np == 0)
|
266
|
+
if ((link->end - pos) < 2 || nb != 1 || np == 0 || (np == 1 && data[link->end - 1] == '.'))
|
248
267
|
return false;
|
249
268
|
|
250
269
|
return autolink_delim(data, link);
|
@@ -278,5 +297,5 @@ autolink__url(
|
|
278
297
|
if (!autolink_issafe(data + link->start, size - link->start))
|
279
298
|
return false;
|
280
299
|
|
281
|
-
return
|
300
|
+
return autolink_delim_iter(data, link);
|
282
301
|
}
|
data/lib/rinku.rb
CHANGED
data/rinku.gemspec
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
1
|
Gem::Specification.new do |s|
|
4
2
|
s.name = 'rinku'
|
5
|
-
s.version = '2.0.
|
3
|
+
s.version = '2.0.2'
|
6
4
|
s.summary = "Mostly autolinking"
|
7
5
|
s.description = <<-EOF
|
8
6
|
A fast and very smart autolinking library that
|
@@ -11,6 +9,7 @@ Gem::Specification.new do |s|
|
|
11
9
|
s.email = 'vicent@github.com'
|
12
10
|
s.homepage = 'https://github.com/vmg/rinku'
|
13
11
|
s.authors = ["Vicent Marti"]
|
12
|
+
s.license = 'ISC'
|
14
13
|
# = MANIFEST =
|
15
14
|
s.files = %w[
|
16
15
|
COPYING
|
@@ -39,5 +38,7 @@ Gem::Specification.new do |s|
|
|
39
38
|
|
40
39
|
s.add_development_dependency "rake"
|
41
40
|
s.add_development_dependency "rake-compiler"
|
42
|
-
s.add_development_dependency "minitest"
|
41
|
+
s.add_development_dependency "minitest", ">= 5.0"
|
42
|
+
|
43
|
+
s.required_ruby_version = '>= 2.0.0'
|
43
44
|
end
|
data/test/autolink_test.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift "#{rootdir}/lib"
|
1
|
+
require 'bundler/setup'
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
4
3
|
|
5
4
|
require 'minitest/autorun'
|
6
5
|
require 'cgi'
|
@@ -10,7 +9,7 @@ require 'rinku'
|
|
10
9
|
class RinkuAutoLinkTest < Minitest::Test
|
11
10
|
def generate_result(link_text, href = nil)
|
12
11
|
href ||= link_text
|
13
|
-
href = "http://" + href unless href =~ %r{\A\w
|
12
|
+
href = "http://" + href unless href =~ %r{\A(\w+://|mailto:)}
|
14
13
|
%{<a href="#{CGI.escapeHTML href}">#{CGI.escapeHTML link_text}</a>}
|
15
14
|
end
|
16
15
|
|
@@ -363,6 +362,13 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
|
|
363
362
|
assert_linked "email#{NBSP}<a href=\"mailto:#{email_raw}\">#{email_raw}</a>", "email#{NBSP}#{email_raw}"
|
364
363
|
end
|
365
364
|
|
365
|
+
def test_identifies_unicode_spaces
|
366
|
+
assert_linked(
|
367
|
+
%{This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>\u202F\u2028\u2001},
|
368
|
+
"This is just a test. http://www.pokemon.com\u202F\u2028\u2001"
|
369
|
+
)
|
370
|
+
end
|
371
|
+
|
366
372
|
def test_www_is_case_insensitive
|
367
373
|
url = "www.reddit.com"
|
368
374
|
assert_linked generate_result(url), url
|
@@ -376,4 +382,34 @@ This is just a test. <a href="http://www.pokemon.com">http://www.pokemon.com</a>
|
|
376
382
|
url = "WwW.reddit.CoM"
|
377
383
|
assert_linked generate_result(url), url
|
378
384
|
end
|
385
|
+
|
386
|
+
def test_non_emails_ending_in_periods
|
387
|
+
assert_linked "abc/def@ghi.", "abc/def@ghi."
|
388
|
+
assert_linked "abc/def@ghi. ", "abc/def@ghi. "
|
389
|
+
assert_linked "abc/def@ghi. x", "abc/def@ghi. x"
|
390
|
+
assert_linked "abc/def@ghi.< x", "abc/def@ghi.< x"
|
391
|
+
assert_linked "abc/<a href=\"mailto:def@ghi.x\">def@ghi.x</a>", "abc/def@ghi.x"
|
392
|
+
assert_linked "abc/<a href=\"mailto:def@ghi.x\">def@ghi.x</a>. a", "abc/def@ghi.x. a"
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_urls_with_entities_and_parens
|
396
|
+
assert_linked "<<a href=\"http://www.google.com\">http://www.google.com</a>>", "<http://www.google.com>"
|
397
|
+
|
398
|
+
assert_linked "<<a href=\"http://www.google.com\">http://www.google.com</a>>)", "<http://www.google.com>)"
|
399
|
+
|
400
|
+
# this produces invalid output, but limits how much work we will do
|
401
|
+
assert_linked "<<a href=\"http://www.google.com>\">http://www.google.com></a>)<)<)<)<)<)<)", "<http://www.google.com>)<)<)<)<)<)<)"
|
402
|
+
|
403
|
+
url = "http://pokemon.com/bulbasaur"
|
404
|
+
assert_linked "URL is #{generate_result(url)}.", "URL is #{url}."
|
405
|
+
assert_linked "(URL is #{generate_result(url)}.)", "(URL is #{url}.)"
|
406
|
+
|
407
|
+
url = "www.pokemon.com/bulbasaur"
|
408
|
+
assert_linked "URL is #{generate_result(url)}.", "URL is #{url}."
|
409
|
+
assert_linked "(URL is #{generate_result(url)}.)", "(URL is #{url}.)"
|
410
|
+
|
411
|
+
url = "abc@xyz.com"
|
412
|
+
assert_linked "URL is #{generate_result(url, "mailto:#{url}")}.", "URL is #{url}."
|
413
|
+
assert_linked "(URL is #{generate_result(url, "mailto:#{url}")}.)", "(URL is #{url}.)"
|
414
|
+
end
|
379
415
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rinku
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vicent Marti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '5.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '5.0'
|
55
55
|
description: |2
|
56
56
|
A fast and very smart autolinking library that
|
57
57
|
acts as a drop-in replacement for Rails `auto_link`
|
@@ -80,7 +80,8 @@ files:
|
|
80
80
|
- rinku.gemspec
|
81
81
|
- test/autolink_test.rb
|
82
82
|
homepage: https://github.com/vmg/rinku
|
83
|
-
licenses:
|
83
|
+
licenses:
|
84
|
+
- ISC
|
84
85
|
metadata: {}
|
85
86
|
post_install_message:
|
86
87
|
rdoc_options: []
|
@@ -90,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
91
|
requirements:
|
91
92
|
- - ">="
|
92
93
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
94
|
+
version: 2.0.0
|
94
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
96
|
requirements:
|
96
97
|
- - ">="
|
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
99
|
version: '0'
|
99
100
|
requirements: []
|
100
101
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.5.1
|
102
103
|
signing_key:
|
103
104
|
specification_version: 4
|
104
105
|
summary: Mostly autolinking
|