rinku 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +36 -25
- data/Rakefile +15 -0
- data/ext/rinku/autolink.c +5 -6
- data/ext/rinku/buffer.c +27 -26
- data/ext/rinku/buffer.h +2 -5
- data/ext/rinku/rinku.c +58 -50
- data/lib/rails_rinku.rb +6 -1
- data/lib/rinku.rb +1 -0
- data/rinku.gemspec +1 -1
- data/test/autolink_test.rb +20 -0
- metadata +39 -23
data/README.markdown
CHANGED
|
@@ -23,53 +23,64 @@ Rinku is a standalone library
|
|
|
23
23
|
|
|
24
24
|
It exports a single method called `Rinku.auto_link`.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
~~~~~ruby
|
|
27
27
|
require 'rinku'
|
|
28
28
|
|
|
29
|
-
auto_link(text, mode=:all, link_attr=nil)
|
|
30
|
-
auto_link(text, mode=:all, link_attr=nil) { |link_text| ... }
|
|
31
|
-
|
|
29
|
+
Rinku.auto_link(text, mode=:all, link_attr=nil, skip_tags=nil)
|
|
30
|
+
Rinku.auto_link(text, mode=:all, link_attr=nil, skip_tags=nil) { |link_text| ... }
|
|
31
|
+
~~~~~~
|
|
32
32
|
|
|
33
33
|
Parses a block of text looking for "safe" urls or email addresses,
|
|
34
34
|
and turns them into HTML links with the given attributes.
|
|
35
35
|
|
|
36
|
+
NOTE: The block of text may or may not be HTML; if the text is HTML,
|
|
37
|
+
Rinku will skip the relevant tags to prevent double-linking and linking
|
|
38
|
+
inside `pre` blocks by default.
|
|
39
|
+
|
|
40
|
+
NOTE: If the input text is HTML, it's expected to be already escaped.
|
|
41
|
+
Rinku will perform no escaping.
|
|
42
|
+
|
|
36
43
|
NOTE: Currently the follow protocols are considered safe and are the
|
|
37
44
|
only ones that will be autolinked.
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
http:// https:// ftp:// mailto://
|
|
40
47
|
|
|
41
48
|
Email addresses are also autolinked by default. URLs without a protocol
|
|
42
|
-
specifier but starting with
|
|
43
|
-
the
|
|
49
|
+
specifier but starting with 'www.' will also be autolinked, defaulting to
|
|
50
|
+
the 'http://' protocol.
|
|
44
51
|
|
|
45
|
-
-
|
|
52
|
+
- `text` is a string in plain text or HTML markup. If the string is formatted in
|
|
46
53
|
HTML, Rinku is smart enough to skip the links that are already enclosed in `<a>`
|
|
47
|
-
tags
|
|
54
|
+
tags.`
|
|
48
55
|
|
|
49
|
-
-
|
|
50
|
-
kind of links will be auto-linked.
|
|
56
|
+
- `mode` is a symbol, either `:all`, `:urls` or `:email_addresses`,
|
|
57
|
+
which specifies which kind of links will be auto-linked.
|
|
51
58
|
|
|
52
|
-
-
|
|
59
|
+
- `link_attr` is a string containing the link attributes for each link that
|
|
53
60
|
will be generated. These attributes are not sanitized and will be include as-is
|
|
54
61
|
in each generated link, e.g.
|
|
55
62
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
~~~~~ruby
|
|
64
|
+
auto_link('http://www.pokemon.com', :all, 'target="_blank"')
|
|
65
|
+
# => '<a href="http://www.pokemon.com" target="_blank">http://www.pokemon.com</a>'
|
|
66
|
+
~~~~~
|
|
60
67
|
|
|
61
|
-
|
|
68
|
+
This string can be autogenerated from a hash using the Rails `tag_options` helper.
|
|
62
69
|
|
|
63
|
-
-
|
|
70
|
+
- `skip_tags` is a list of strings with the names of HTML tags that will be skipped
|
|
71
|
+
when autolinking. If `nil`, this defaults to the value of the global `Rinku.skip_tags`,
|
|
72
|
+
which is initially `["a", "pre", "code", "kbd", "script"]`.
|
|
73
|
+
|
|
74
|
+
- `&block` is an optional block argument. If a block is passed, it will
|
|
64
75
|
be yielded for each found link in the text, and its return value will be used instead
|
|
65
76
|
of the name of the link. E.g.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
77
|
+
|
|
78
|
+
~~~~~ruby
|
|
79
|
+
auto_link('Check it out at http://www.pokemon.com') do |url|
|
|
80
|
+
"THE POKEMAN WEBSITEZ"
|
|
81
|
+
end
|
|
82
|
+
# => 'Check it out at <a href="http://www.pokemon.com">THE POKEMAN WEBSITEZ</a>'
|
|
83
|
+
~~~~~~
|
|
73
84
|
|
|
74
85
|
Rinku is a drop-in replacement for Rails 3.1 `auto_link`
|
|
75
86
|
----------------------------------------------------
|
data/Rakefile
CHANGED
|
@@ -50,3 +50,18 @@ file package('.gem') => %w[pkg/ rinku.gemspec] + $spec.files do |f|
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
# GEMSPEC HELPERS ==========================================================
|
|
53
|
+
task :gather => 'sundown/src/autolink.h' do |t|
|
|
54
|
+
files =
|
|
55
|
+
FileList[
|
|
56
|
+
'sundown/src/{buffer,autolink}.h',
|
|
57
|
+
'sundown/src/{buffer,autolink}.c',
|
|
58
|
+
]
|
|
59
|
+
cp files, 'ext/rinku/',
|
|
60
|
+
:preserve => true,
|
|
61
|
+
:verbose => true
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
file 'sundown/src/autolink.h' do |t|
|
|
66
|
+
abort "The Sundown submodule is required."
|
|
67
|
+
end
|
data/ext/rinku/autolink.c
CHANGED
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
int
|
|
25
25
|
sd_autolink_issafe(const uint8_t *link, size_t link_len)
|
|
26
26
|
{
|
|
27
|
-
static const size_t valid_uris_count =
|
|
27
|
+
static const size_t valid_uris_count = 5;
|
|
28
28
|
static const char *valid_uris[] = {
|
|
29
|
-
"http://", "https://", "ftp://", "mailto
|
|
29
|
+
"/", "http://", "https://", "ftp://", "mailto:"
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
size_t i;
|
|
@@ -140,10 +140,9 @@ check_domain(uint8_t *data, size_t size)
|
|
|
140
140
|
else if (!isalnum(data[i]) && data[i] != '-') break;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return i;
|
|
143
|
+
/* a valid domain needs to have at least a dot.
|
|
144
|
+
* that's as far as we get */
|
|
145
|
+
return np ? i : 0;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
size_t
|
data/ext/rinku/buffer.c
CHANGED
|
@@ -113,9 +113,35 @@ bufprintf(struct buf *buf, const char *fmt, ...)
|
|
|
113
113
|
if (!buf || !buf->unit)
|
|
114
114
|
return;
|
|
115
115
|
|
|
116
|
+
int n;
|
|
117
|
+
|
|
118
|
+
if (buf == 0 || (buf->size >= buf->asize && bufgrow(buf, buf->size + 1)) < 0)
|
|
119
|
+
return;
|
|
120
|
+
|
|
116
121
|
va_start(ap, fmt);
|
|
117
|
-
|
|
122
|
+
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
|
|
118
123
|
va_end(ap);
|
|
124
|
+
|
|
125
|
+
if (n < 0) {
|
|
126
|
+
#ifdef _MSC_VER
|
|
127
|
+
n = _vscprintf(fmt, ap);
|
|
128
|
+
#else
|
|
129
|
+
return;
|
|
130
|
+
#endif
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if ((size_t)n >= buf->asize - buf->size) {
|
|
134
|
+
if (bufgrow(buf, buf->size + n + 1) < 0)
|
|
135
|
+
return;
|
|
136
|
+
va_start(ap, fmt);
|
|
137
|
+
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
|
|
138
|
+
va_end(ap);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (n < 0)
|
|
142
|
+
return;
|
|
143
|
+
|
|
144
|
+
buf->size += n;
|
|
119
145
|
}
|
|
120
146
|
|
|
121
147
|
/* bufput: appends raw data to a buffer */
|
|
@@ -198,31 +224,6 @@ bufslurp(struct buf *buf, size_t len)
|
|
|
198
224
|
void
|
|
199
225
|
vbufprintf(struct buf *buf, const char *fmt, va_list ap)
|
|
200
226
|
{
|
|
201
|
-
int n;
|
|
202
227
|
|
|
203
|
-
if (buf == 0 || (buf->size >= buf->asize && bufgrow(buf, buf->size + 1)) < 0)
|
|
204
|
-
return;
|
|
205
|
-
|
|
206
|
-
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
|
|
207
|
-
|
|
208
|
-
if (n < 0) {
|
|
209
|
-
#ifdef _MSC_VER
|
|
210
|
-
n = _vscprintf(fmt, ap);
|
|
211
|
-
#else
|
|
212
|
-
return;
|
|
213
|
-
#endif
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if ((size_t)n >= buf->asize - buf->size) {
|
|
217
|
-
if (bufgrow(buf, buf->size + n + 1) < 0)
|
|
218
|
-
return;
|
|
219
|
-
|
|
220
|
-
n = _buf_vsnprintf((char *)buf->data + buf->size, buf->asize - buf->size, fmt, ap);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (n < 0)
|
|
224
|
-
return;
|
|
225
|
-
|
|
226
|
-
buf->size += n;
|
|
227
228
|
}
|
|
228
229
|
|
data/ext/rinku/buffer.h
CHANGED
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
#ifndef
|
|
19
|
-
#define
|
|
18
|
+
#ifndef BUFFER_H__
|
|
19
|
+
#define BUFFER_H__
|
|
20
20
|
|
|
21
21
|
#include <stddef.h>
|
|
22
22
|
#include <stdarg.h>
|
|
@@ -85,7 +85,4 @@ void bufslurp(struct buf *, size_t);
|
|
|
85
85
|
/* bufprintf: formatted printing to a buffer */
|
|
86
86
|
void bufprintf(struct buf *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
|
|
87
87
|
|
|
88
|
-
/* vbufprintf: stdarg variant of formatted printing into a buffer */
|
|
89
|
-
void vbufprintf(struct buf *, const char * , va_list);
|
|
90
|
-
|
|
91
88
|
#endif
|
data/ext/rinku/rinku.c
CHANGED
|
@@ -116,20 +116,21 @@ autolink__skip_tag(
|
|
|
116
116
|
struct buf *ob,
|
|
117
117
|
const uint8_t *text,
|
|
118
118
|
size_t size,
|
|
119
|
-
const char **skip_tags
|
|
120
|
-
size_t skip_tags_count)
|
|
119
|
+
const char **skip_tags)
|
|
121
120
|
{
|
|
122
|
-
size_t
|
|
121
|
+
size_t i = 0;
|
|
123
122
|
|
|
124
123
|
while (i < size && text[i] != '>')
|
|
125
124
|
i++;
|
|
126
125
|
|
|
127
|
-
|
|
128
|
-
if (html_is_tag(text, size, skip_tags
|
|
126
|
+
while (*skip_tags != NULL) {
|
|
127
|
+
if (html_is_tag(text, size, *skip_tags) == HTML_TAG_OPEN)
|
|
129
128
|
break;
|
|
129
|
+
|
|
130
|
+
skip_tags++;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
|
-
if (
|
|
133
|
+
if (*skip_tags != NULL) {
|
|
133
134
|
for (;;) {
|
|
134
135
|
while (i < size && text[i] != '<')
|
|
135
136
|
i++;
|
|
@@ -137,7 +138,7 @@ autolink__skip_tag(
|
|
|
137
138
|
if (i == size)
|
|
138
139
|
break;
|
|
139
140
|
|
|
140
|
-
if (html_is_tag(text + i, size - i, skip_tags
|
|
141
|
+
if (html_is_tag(text + i, size - i, *skip_tags) == HTML_TAG_CLOSE)
|
|
141
142
|
break;
|
|
142
143
|
|
|
143
144
|
i++;
|
|
@@ -159,7 +160,6 @@ rinku_autolink(
|
|
|
159
160
|
unsigned int flags,
|
|
160
161
|
const char *link_attr,
|
|
161
162
|
const char **skip_tags,
|
|
162
|
-
size_t skip_tags_count,
|
|
163
163
|
void (*link_text_cb)(struct buf *ob, const struct buf *link, void *payload),
|
|
164
164
|
void *payload)
|
|
165
165
|
{
|
|
@@ -212,8 +212,7 @@ rinku_autolink(
|
|
|
212
212
|
|
|
213
213
|
if (action == AUTOLINK_ACTION_SKIP_TAG) {
|
|
214
214
|
end += autolink__skip_tag(ob,
|
|
215
|
-
text + end, size - end,
|
|
216
|
-
skip_tags, skip_tags_count);
|
|
215
|
+
text + end, size - end, skip_tags);
|
|
217
216
|
|
|
218
217
|
continue;
|
|
219
218
|
}
|
|
@@ -266,6 +265,26 @@ autolink_callback(struct buf *link_text, const struct buf *link, void *block)
|
|
|
266
265
|
bufput(link_text, RSTRING_PTR(rb_link_text), RSTRING_LEN(rb_link_text));
|
|
267
266
|
}
|
|
268
267
|
|
|
268
|
+
const char **rinku_load_tags(VALUE rb_skip)
|
|
269
|
+
{
|
|
270
|
+
const char **skip_tags;
|
|
271
|
+
size_t i, count;
|
|
272
|
+
|
|
273
|
+
Check_Type(rb_skip, T_ARRAY);
|
|
274
|
+
|
|
275
|
+
count = RARRAY_LEN(rb_skip);
|
|
276
|
+
skip_tags = xmalloc(sizeof(void *) * (count + 1));
|
|
277
|
+
|
|
278
|
+
for (i = 0; i < count; ++i) {
|
|
279
|
+
VALUE tag = rb_ary_entry(rb_skip, i);
|
|
280
|
+
Check_Type(tag, T_STRING);
|
|
281
|
+
skip_tags[i] = StringValueCStr(tag);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
skip_tags[count] = NULL;
|
|
285
|
+
return skip_tags;
|
|
286
|
+
}
|
|
287
|
+
|
|
269
288
|
/*
|
|
270
289
|
* Document-method: auto_link
|
|
271
290
|
*
|
|
@@ -286,52 +305,55 @@ autolink_callback(struct buf *link_text, const struct buf *link, void *block)
|
|
|
286
305
|
* NOTE: Currently the follow protocols are considered safe and are the
|
|
287
306
|
* only ones that will be autolinked.
|
|
288
307
|
*
|
|
289
|
-
*
|
|
308
|
+
* http:// https:// ftp:// mailto://
|
|
290
309
|
*
|
|
291
310
|
* Email addresses are also autolinked by default. URLs without a protocol
|
|
292
311
|
* specifier but starting with 'www.' will also be autolinked, defaulting to
|
|
293
312
|
* the 'http://' protocol.
|
|
294
313
|
*
|
|
295
|
-
*
|
|
296
|
-
* HTML, Rinku is smart enough to skip the links that are already enclosed in
|
|
297
|
-
* tags
|
|
314
|
+
* - `text` is a string in plain text or HTML markup. If the string is formatted in
|
|
315
|
+
* HTML, Rinku is smart enough to skip the links that are already enclosed in `<a>`
|
|
316
|
+
* tags.`
|
|
298
317
|
*
|
|
299
|
-
*
|
|
300
|
-
* which specifies which kind of links will be auto-linked.
|
|
301
|
-
* will autolink e
|
|
318
|
+
* - `mode` is a symbol, either `:all`, `:urls` or `:email_addresses`,
|
|
319
|
+
* which specifies which kind of links will be auto-linked.
|
|
302
320
|
*
|
|
303
|
-
*
|
|
321
|
+
* - `link_attr` is a string containing the link attributes for each link that
|
|
304
322
|
* will be generated. These attributes are not sanitized and will be include as-is
|
|
305
323
|
* in each generated link, e.g.
|
|
306
324
|
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
325
|
+
* ~~~~~ruby
|
|
326
|
+
* auto_link('http://www.pokemon.com', :all, 'target="_blank"')
|
|
327
|
+
* # => '<a href="http://www.pokemon.com" target="_blank">http://www.pokemon.com</a>'
|
|
328
|
+
* ~~~~~
|
|
309
329
|
*
|
|
310
|
-
*
|
|
330
|
+
* This string can be autogenerated from a hash using the Rails `tag_options` helper.
|
|
311
331
|
*
|
|
312
|
-
*
|
|
313
|
-
* when autolinking. If nil
|
|
332
|
+
* - `skip_tags` is a list of strings with the names of HTML tags that will be skipped
|
|
333
|
+
* when autolinking. If `nil`, this defaults to the value of the global `Rinku.skip_tags`,
|
|
334
|
+
* which is initially `["a", "pre", "code", "kbd", "script"]`.
|
|
314
335
|
*
|
|
315
|
-
*
|
|
336
|
+
* - `&block` is an optional block argument. If a block is passed, it will
|
|
316
337
|
* be yielded for each found link in the text, and its return value will be used instead
|
|
317
338
|
* of the name of the link. E.g.
|
|
318
339
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
340
|
+
* ~~~~~ruby
|
|
341
|
+
* auto_link('Check it out at http://www.pokemon.com') do |url|
|
|
342
|
+
* "THE POKEMAN WEBSITEZ"
|
|
343
|
+
* end
|
|
344
|
+
* # => 'Check it out at <a href="http://www.pokemon.com">THE POKEMAN WEBSITEZ</a>'
|
|
345
|
+
* ~~~~~~
|
|
323
346
|
*/
|
|
324
347
|
static VALUE
|
|
325
348
|
rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
|
|
326
349
|
{
|
|
327
|
-
static const char *SKIP_TAGS[] = {"a", "pre", "code", "kbd", "script"};
|
|
350
|
+
static const char *SKIP_TAGS[] = {"a", "pre", "code", "kbd", "script", NULL};
|
|
328
351
|
|
|
329
352
|
VALUE result, rb_text, rb_mode, rb_html, rb_skip, rb_block;
|
|
330
353
|
struct buf *output_buf;
|
|
331
354
|
int link_mode, count;
|
|
332
355
|
const char *link_attr = NULL;
|
|
333
356
|
const char **skip_tags = NULL;
|
|
334
|
-
size_t skip_tags_count;
|
|
335
357
|
ID mode_sym;
|
|
336
358
|
|
|
337
359
|
rb_scan_args(argc, argv, "13&", &rb_text, &rb_mode, &rb_html, &rb_skip, &rb_block);
|
|
@@ -350,25 +372,13 @@ rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
|
|
|
350
372
|
link_attr = RSTRING_PTR(rb_html);
|
|
351
373
|
}
|
|
352
374
|
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
Check_Type(rb_skip, T_ARRAY);
|
|
357
|
-
|
|
358
|
-
skip_tags_count = RARRAY_LEN(rb_skip);
|
|
359
|
-
skip_tags = malloc(sizeof(void *) * skip_tags_count);
|
|
360
|
-
if (!skip_tags)
|
|
361
|
-
rb_raise(rb_eNoMemError, "Out of memory");
|
|
362
|
-
|
|
363
|
-
for (i = 0; i < skip_tags_count; ++i) {
|
|
364
|
-
VALUE tag = rb_ary_entry(rb_skip, i);
|
|
365
|
-
Check_Type(tag, T_STRING);
|
|
375
|
+
if (NIL_P(rb_skip))
|
|
376
|
+
rb_skip = rb_iv_get(self, "@skip_tags");
|
|
366
377
|
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
} else {
|
|
378
|
+
if (NIL_P(rb_skip)) {
|
|
370
379
|
skip_tags = SKIP_TAGS;
|
|
371
|
-
|
|
380
|
+
} else {
|
|
381
|
+
skip_tags = rinku_load_tags(rb_skip);
|
|
372
382
|
}
|
|
373
383
|
|
|
374
384
|
output_buf = bufnew(32);
|
|
@@ -390,7 +400,6 @@ rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
|
|
|
390
400
|
link_mode,
|
|
391
401
|
link_attr,
|
|
392
402
|
skip_tags,
|
|
393
|
-
skip_tags_count,
|
|
394
403
|
RTEST(rb_block) ? &autolink_callback : NULL,
|
|
395
404
|
(void*)rb_block);
|
|
396
405
|
|
|
@@ -402,7 +411,7 @@ rb_rinku_autolink(int argc, VALUE *argv, VALUE self)
|
|
|
402
411
|
}
|
|
403
412
|
|
|
404
413
|
if (skip_tags != SKIP_TAGS)
|
|
405
|
-
|
|
414
|
+
xfree(skip_tags);
|
|
406
415
|
|
|
407
416
|
bufrelease(output_buf);
|
|
408
417
|
return result;
|
|
@@ -414,4 +423,3 @@ void Init_rinku()
|
|
|
414
423
|
rb_define_method(rb_mRinku, "auto_link", rb_rinku_autolink, -1);
|
|
415
424
|
}
|
|
416
425
|
|
|
417
|
-
|
data/lib/rails_rinku.rb
CHANGED
|
@@ -8,11 +8,16 @@ module RailsRinku
|
|
|
8
8
|
unless args.empty?
|
|
9
9
|
options[:link] = args[0] || :all
|
|
10
10
|
options[:html] = args[1] || {}
|
|
11
|
+
options[:skip] = args[2]
|
|
11
12
|
end
|
|
12
13
|
options.reverse_merge!(:link => :all, :html => {})
|
|
13
14
|
text = text.html_safe unless text.html_safe?
|
|
14
15
|
|
|
15
|
-
Rinku.auto_link
|
|
16
|
+
Rinku.auto_link text,
|
|
17
|
+
options[:link],
|
|
18
|
+
tag_options(options[:html]),
|
|
19
|
+
options[:skip],
|
|
20
|
+
&block
|
|
16
21
|
end
|
|
17
22
|
end
|
|
18
23
|
|
data/lib/rinku.rb
CHANGED
data/rinku.gemspec
CHANGED
data/test/autolink_test.rb
CHANGED
|
@@ -15,6 +15,26 @@ class RedcarpetAutolinkTest < Test::Unit::TestCase
|
|
|
15
15
|
assert_equal expected, Rinku.auto_link(url)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def test_global_skip_tags
|
|
19
|
+
assert_equal Rinku.skip_tags, nil
|
|
20
|
+
Rinku.skip_tags = ['pre']
|
|
21
|
+
assert_equal Rinku.skip_tags, ['pre']
|
|
22
|
+
|
|
23
|
+
Rinku.skip_tags = ['pa']
|
|
24
|
+
url = 'This is just a <pa>http://www.pokemon.com</pa> test'
|
|
25
|
+
assert_equal Rinku.auto_link(url), url
|
|
26
|
+
|
|
27
|
+
Rinku.skip_tags = nil
|
|
28
|
+
assert_not_equal Rinku.auto_link(url), url
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_auto_link_with_single_trailing_punctuation_and_space
|
|
32
|
+
url = "http://www.youtube.com"
|
|
33
|
+
url_result = generate_result(url)
|
|
34
|
+
assert_equal url_result, Rinku.auto_link(url)
|
|
35
|
+
assert_equal "link: #{url_result}. foo?", Rinku.auto_link("link: #{url}. foo?")
|
|
36
|
+
end
|
|
37
|
+
|
|
18
38
|
def test_does_not_segfault
|
|
19
39
|
assert_linked "< this is just a test", "< this is just a test"
|
|
20
40
|
end
|
metadata
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rinku
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 3
|
|
5
5
|
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 1
|
|
8
|
+
- 5
|
|
9
|
+
- 0
|
|
10
|
+
version: 1.5.0
|
|
6
11
|
platform: ruby
|
|
7
|
-
authors:
|
|
8
|
-
- Vicent
|
|
12
|
+
authors:
|
|
13
|
+
- "Vicent Mart\xC3\xAD"
|
|
9
14
|
autorequire:
|
|
10
15
|
bindir: bin
|
|
11
16
|
cert_chain: []
|
|
12
|
-
|
|
17
|
+
|
|
18
|
+
date: 2011-12-04 00:00:00 Z
|
|
13
19
|
dependencies: []
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
|
|
21
|
+
description: " A fast and very smart autolinking library that\n acts as a drop-in replacement for Rails `auto_link`\n"
|
|
16
22
|
email: vicent@github.com
|
|
17
23
|
executables: []
|
|
18
|
-
|
|
24
|
+
|
|
25
|
+
extensions:
|
|
19
26
|
- ext/rinku/extconf.rb
|
|
20
|
-
extra_rdoc_files:
|
|
27
|
+
extra_rdoc_files:
|
|
21
28
|
- COPYING
|
|
22
|
-
files:
|
|
29
|
+
files:
|
|
23
30
|
- COPYING
|
|
24
31
|
- README.markdown
|
|
25
32
|
- Rakefile
|
|
@@ -35,27 +42,36 @@ files:
|
|
|
35
42
|
- test/autolink_test.rb
|
|
36
43
|
homepage: http://github.com/tanoku/rinku
|
|
37
44
|
licenses: []
|
|
45
|
+
|
|
38
46
|
post_install_message:
|
|
39
47
|
rdoc_options: []
|
|
40
|
-
|
|
48
|
+
|
|
49
|
+
require_paths:
|
|
41
50
|
- lib
|
|
42
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
52
|
none: false
|
|
44
|
-
requirements:
|
|
45
|
-
- -
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
hash: 3
|
|
57
|
+
segments:
|
|
58
|
+
- 0
|
|
59
|
+
version: "0"
|
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
61
|
none: false
|
|
50
|
-
requirements:
|
|
51
|
-
- -
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
hash: 3
|
|
66
|
+
segments:
|
|
67
|
+
- 0
|
|
68
|
+
version: "0"
|
|
54
69
|
requirements: []
|
|
70
|
+
|
|
55
71
|
rubyforge_project:
|
|
56
72
|
rubygems_version: 1.8.6
|
|
57
73
|
signing_key:
|
|
58
74
|
specification_version: 3
|
|
59
75
|
summary: Mostly autolinking
|
|
60
|
-
test_files:
|
|
76
|
+
test_files:
|
|
61
77
|
- test/autolink_test.rb
|