redcarpet 1.16.0 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redcarpet might be problematic. Click here for more details.

data/Rakefile CHANGED
@@ -115,9 +115,9 @@ desc 'Gather required Upskirt sources into extension directory'
115
115
  task :gather => 'upskirt/src/markdown.h' do |t|
116
116
  files =
117
117
  FileList[
118
- 'upskirt/src/{markdown,buffer,array}.h',
118
+ 'upskirt/src/{markdown,buffer,array,autolink}.h',
119
119
  'upskirt/src/{markdown,buffer,array,autolink}.c',
120
- 'upskirt/html/{html,html_smartypants,html_autolink}.c',
120
+ 'upskirt/html/{html,html_smartypants}.c',
121
121
  'upskirt/html/html.h',
122
122
  ]
123
123
  cp files, 'ext/redcarpet/',
@@ -14,7 +14,6 @@
14
14
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
15
  */
16
16
 
17
- #include "markdown.h"
18
17
  #include "buffer.h"
19
18
 
20
19
  #include <string.h>
data/ext/redcarpet/html.h CHANGED
@@ -34,12 +34,6 @@ typedef enum {
34
34
  HTML_USE_XHTML = (1 << 11),
35
35
  } render_mode;
36
36
 
37
- typedef enum {
38
- AUTOLINK_URLS = (1 << 0),
39
- AUTOLINK_EMAILS = (1 << 1),
40
- AUTOLINK_ALL = AUTOLINK_URLS|AUTOLINK_EMAILS
41
- } autolink_mode;
42
-
43
37
  void
44
38
  upshtml_escape(struct buf *ob, const char *src, size_t size);
45
39
 
@@ -55,9 +49,5 @@ upshtml_free_renderer(struct mkd_renderer *renderer);
55
49
  extern void
56
50
  upshtml_smartypants(struct buf *ob, struct buf *text);
57
51
 
58
- extern void
59
- upshtml_autolink(struct buf *ob, struct buf *text, unsigned int autolink_flags);
60
-
61
-
62
52
  #endif
63
53
 
@@ -20,6 +20,7 @@
20
20
  #define UPSKIRT_MARKDOWN_H
21
21
 
22
22
  #include "buffer.h"
23
+ #include "autolink.h"
23
24
 
24
25
  #define UPSKIRT_VERSION "1.15.2"
25
26
  #define UPSKIRT_VER_MAJOR 1
@@ -105,15 +106,6 @@ struct mkd_renderer {
105
106
  int
106
107
  is_safe_link(const char *link, size_t link_len);
107
108
 
108
- size_t
109
- ups_autolink__www(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size);
110
-
111
- size_t
112
- ups_autolink__email(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size);
113
-
114
- size_t
115
- ups_autolink__url(size_t *rewind_p, struct buf *link, char *data, size_t offset, size_t size);
116
-
117
109
  /**********************
118
110
  * EXPORTED FUNCTIONS *
119
111
  **********************/
@@ -1,6 +1,14 @@
1
+ #define RSTRING_NOT_MODIFIED
2
+
1
3
  #include <stdio.h>
2
4
  #include "ruby.h"
3
5
 
6
+ #ifdef HAVE_RUBY_ENCODING_H
7
+ #include <ruby/encoding.h>
8
+ #else
9
+ #define rb_enc_copy(dst, src)
10
+ #endif
11
+
4
12
  #include "markdown.h"
5
13
  #include "html.h"
6
14
 
@@ -79,31 +87,6 @@ static void rb_redcarpet__get_flags(VALUE ruby_obj,
79
87
  *render_flags_p = render_flags;
80
88
  }
81
89
 
82
- static VALUE rb_redcarpet_autolink(VALUE self, VALUE text)
83
- {
84
- VALUE result;
85
- struct buf input_buf, *output_buf;
86
-
87
- memset(&input_buf, 0x0, sizeof(struct buf));
88
- input_buf.data = RSTRING_PTR(text);
89
- input_buf.size = RSTRING_LEN(text);
90
-
91
- output_buf = bufnew(128);
92
-
93
- upshtml_autolink(output_buf, &input_buf, AUTOLINK_ALL);
94
- result = rb_str_new(output_buf->data, output_buf->size);
95
-
96
- bufrelease(output_buf);
97
-
98
- /* force the input encoding */
99
- if (rb_respond_to(text, rb_intern("encoding"))) {
100
- VALUE encoding = rb_funcall(text, rb_intern("encoding"), 0);
101
- rb_funcall(result, rb_intern("force_encoding"), 1, encoding);
102
- }
103
-
104
- return result;
105
- }
106
-
107
90
  static VALUE rb_redcarpet__render(VALUE self, RendererType render_type)
108
91
  {
109
92
  VALUE text = rb_funcall(self, rb_intern("text"), 0);
@@ -152,11 +135,8 @@ static VALUE rb_redcarpet__render(VALUE self, RendererType render_type)
152
135
  upshtml_free_renderer(&renderer);
153
136
 
154
137
  /* force the input encoding */
155
- if (rb_respond_to(text, rb_intern("encoding"))) {
156
- VALUE encoding = rb_funcall(text, rb_intern("encoding"), 0);
157
- rb_funcall(result, rb_intern("force_encoding"), 1, encoding);
158
- }
159
-
138
+ rb_enc_copy(result, text);
139
+
160
140
  return result;
161
141
  }
162
142
 
@@ -177,7 +157,5 @@ void Init_redcarpet()
177
157
  rb_cRedcarpet = rb_define_class("Redcarpet", rb_cObject);
178
158
  rb_define_method(rb_cRedcarpet, "to_html", rb_redcarpet_to_html, -1);
179
159
  rb_define_method(rb_cRedcarpet, "toc_content", rb_redcarpet_toc, -1);
180
-
181
- rb_define_singleton_method(rb_cRedcarpet, "auto_link", rb_redcarpet_autolink, 1);
182
160
  }
183
161
 
data/lib/redcarpet.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.16.0'
29
+ VERSION = '1.17.0'
30
30
 
31
31
  # Original Markdown formatted text.
32
32
  attr_reader :text
data/redcarpet.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'redcarpet'
3
- s.version = '1.16.0'
3
+ s.version = '1.17.0'
4
4
  s.summary = "Ruby bindings for libupskirt"
5
5
  s.description = 'A fast and safe Markdown to (X)HTML parser'
6
- s.date = '2011-06-08'
6
+ s.date = '2011-06-09'
7
7
  s.email = 'vicent@github.com'
8
8
  s.homepage = 'http://github.com/tanoku/redcarpet'
9
9
  s.authors = ["Natacha Porté", "Vicent Martí"]
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  ext/redcarpet/extconf.rb
22
22
  ext/redcarpet/html.c
23
23
  ext/redcarpet/html.h
24
- ext/redcarpet/html_autolink.c
25
24
  ext/redcarpet/html_smartypants.c
26
25
  ext/redcarpet/markdown.c
27
26
  ext/redcarpet/markdown.h
@@ -29,7 +28,6 @@ Gem::Specification.new do |s|
29
28
  lib/markdown.rb
30
29
  lib/redcarpet.rb
31
30
  redcarpet.gemspec
32
- test/autolink_test.rb
33
31
  test/benchmark.rb
34
32
  test/benchmark.txt
35
33
  test/markdown_test.rb
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redcarpet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 87
4
+ hash: 83
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 16
8
+ - 17
9
9
  - 0
10
- version: 1.16.0
10
+ version: 1.17.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Natacha Port\xC3\xA9"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-06-08 00:00:00 +02:00
19
+ date: 2011-06-09 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
@@ -41,7 +41,6 @@ files:
41
41
  - ext/redcarpet/extconf.rb
42
42
  - ext/redcarpet/html.c
43
43
  - ext/redcarpet/html.h
44
- - ext/redcarpet/html_autolink.c
45
44
  - ext/redcarpet/html_smartypants.c
46
45
  - ext/redcarpet/markdown.c
47
46
  - ext/redcarpet/markdown.h
@@ -49,7 +48,6 @@ files:
49
48
  - lib/markdown.rb
50
49
  - lib/redcarpet.rb
51
50
  - redcarpet.gemspec
52
- - test/autolink_test.rb
53
51
  - test/benchmark.rb
54
52
  - test/benchmark.txt
55
53
  - test/markdown_test.rb
@@ -1,174 +0,0 @@
1
- /*
2
- * Copyright (c) 2011, Vicent Marti
3
- *
4
- * Permission to use, copy, modify, and distribute this software for any
5
- * purpose with or without fee is hereby granted, provided that the above
6
- * copyright notice and this permission notice appear in all copies.
7
- *
8
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
- */
16
-
17
- #include "markdown.h"
18
- #include "buffer.h"
19
- #include "html.h"
20
-
21
- #include <string.h>
22
- #include <stdlib.h>
23
- #include <stdio.h>
24
- #include <ctype.h>
25
-
26
- static inline int
27
- is_closing_a(const char *tag, size_t size)
28
- {
29
- size_t i;
30
-
31
- if (tag[0] != '<' || size < STRLEN("</a>") || tag[1] != '/')
32
- return 0;
33
-
34
- i = 2;
35
-
36
- while (i < size && isspace(tag[i]))
37
- i++;
38
-
39
- if (i == size || tag[i] != 'a')
40
- return 0;
41
-
42
- i++;
43
-
44
- while (i < size && isspace(tag[i]))
45
- i++;
46
-
47
- if (i == size || tag[i] != '>')
48
- return 0;
49
-
50
- return i;
51
- }
52
-
53
- static size_t
54
- skip_tags(struct buf *ob, const char *text, size_t size)
55
- {
56
- size_t i = 0;
57
-
58
- while (i < size && text[i] != '>')
59
- i++;
60
-
61
- if (size > 3 && text[1] == 'a' && isspace(text[2])) {
62
- while (i < size) {
63
- size_t tag_len = is_closing_a(text + i, size - i);
64
- if (tag_len) {
65
- i += tag_len;
66
- break;
67
- }
68
- i++;
69
- }
70
- }
71
-
72
- bufput(ob, text, i + 1);
73
- return i + 1;
74
- }
75
-
76
- void
77
- upshtml_autolink(struct buf *ob, struct buf *text, unsigned int flags)
78
- {
79
- size_t i, end;
80
- struct buf *link = bufnew(16);
81
- const char *active_chars;
82
-
83
- if (!text || text->size == 0)
84
- return;
85
-
86
- switch (flags) {
87
- case AUTOLINK_EMAILS:
88
- active_chars = "<@";
89
- break;
90
-
91
- case AUTOLINK_URLS:
92
- active_chars = "<w:";
93
-
94
- case AUTOLINK_ALL:
95
- active_chars = "<@w:";
96
- break;
97
-
98
- default:
99
- return;
100
- }
101
-
102
- bufgrow(ob, text->size);
103
-
104
- i = end = 0;
105
-
106
- while (i < text->size) {
107
- size_t rewind;
108
-
109
- while (end < text->size && strchr(active_chars, text->data[end]) == NULL)
110
- end++;
111
-
112
- bufput(ob, text->data + i, end - i);
113
-
114
- if (end >= text->size)
115
- break;
116
-
117
- i = end;
118
- link->size = 0;
119
-
120
- switch (text->data[i]) {
121
- case '@':
122
- end = ups_autolink__email(&rewind, link, text->data + i, i, text->size - i);
123
- if (end > 0) {
124
- ob->size -= rewind;
125
- BUFPUTSL(ob, "<a href=\"mailto:");
126
- bufput(ob, link->data, link->size);
127
- BUFPUTSL(ob, "\">");
128
- upshtml_escape(ob, link->data, link->size);
129
- BUFPUTSL(ob, "</a>");
130
- }
131
- break;
132
-
133
- case 'w':
134
- end = ups_autolink__www(&rewind, link, text->data + i, i, text->size - i);
135
- if (end > 0) {
136
- BUFPUTSL(ob, "<a href=\"http://");
137
- bufput(ob, link->data, link->size);
138
- BUFPUTSL(ob, "\">");
139
- upshtml_escape(ob, link->data, link->size);
140
- BUFPUTSL(ob, "</a>");
141
- }
142
- break;
143
-
144
- case ':':
145
- end = ups_autolink__url(&rewind, link, text->data + i, i, text->size - i);
146
- if (end > 0) {
147
- ob->size -= rewind;
148
- BUFPUTSL(ob, "<a href=\"");
149
- bufput(ob, link->data, link->size);
150
- BUFPUTSL(ob, "\">");
151
- upshtml_escape(ob, link->data, link->size);
152
- BUFPUTSL(ob, "</a>");
153
- }
154
- break;
155
-
156
- case '<':
157
- end = skip_tags(ob, text->data + i, text->size - i);
158
- break;
159
-
160
- default:
161
- end = 0;
162
- break;
163
- }
164
-
165
- if (!end)
166
- end = i + 1;
167
- else {
168
- i += end;
169
- end = i;
170
- }
171
- }
172
- }
173
-
174
-
@@ -1,121 +0,0 @@
1
- # encoding: utf-8
2
- rootdir = File.dirname(File.dirname(__FILE__))
3
- $LOAD_PATH.unshift "#{rootdir}/lib"
4
-
5
- require 'test/unit'
6
- require 'cgi'
7
- require 'redcarpet'
8
-
9
- class RedcarpetAutolinkTest < Test::Unit::TestCase
10
- def assert_linked(expected, url)
11
- assert_equal expected, Redcarpet.auto_link(url)
12
- end
13
-
14
- def test_autolink_works
15
- url = "http://example.com/"
16
- assert_linked "<a href=\"#{url}\">#{url}</a>", url
17
- end
18
-
19
- def test_not_autolink_www
20
- assert_linked "Awww... man", "Awww... man"
21
- end
22
-
23
- def test_does_not_terminate_on_dash
24
- url = "http://example.com/Notification_Center-GitHub-20101108-140050.jpg"
25
- assert_linked "<a href=\"#{url}\">#{url}</a>", url
26
- end
27
-
28
- def test_does_not_include_trailing_gt
29
- url = "http://example.com"
30
- assert_linked "&lt;<a href=\"#{url}\">#{url}</a>&gt;", "&lt;#{url}&gt;"
31
- end
32
-
33
- def test_links_with_anchors
34
- url = "https://github.com/github/hubot/blob/master/scripts/cream.js#L20-20"
35
- assert_linked "<a href=\"#{url}\">#{url}</a>", url
36
- end
37
-
38
- def test_links_like_rails
39
- urls = %w(http://www.rubyonrails.com
40
- http://www.rubyonrails.com:80
41
- http://www.rubyonrails.com/~minam
42
- https://www.rubyonrails.com/~minam
43
- http://www.rubyonrails.com/~minam/url%20with%20spaces
44
- http://www.rubyonrails.com/foo.cgi?something=here
45
- http://www.rubyonrails.com/foo.cgi?something=here&and=here
46
- http://www.rubyonrails.com/contact;new
47
- http://www.rubyonrails.com/contact;new%20with%20spaces
48
- http://www.rubyonrails.com/contact;new?with=query&string=params
49
- http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
50
- http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
51
- http://www.mail-archive.com/rails@lists.rubyonrails.org/
52
- http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
53
- http://en.wikipedia.org/wiki/Sprite_(computer_graphics)
54
- http://en.wikipedia.org/wiki/Texas_hold'em
55
- https://www.google.com/doku.php?id=gps:resource:scs:start
56
- )
57
-
58
- urls.each do |url|
59
- assert_linked %(<a href="#{url}">#{CGI.escapeHTML(url)}</a>), url
60
- end
61
- end
62
-
63
- def test_links_like_autolink_rails
64
- email_raw = 'david@loudthinking.com'
65
- email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
66
- email2_raw = '+david@loudthinking.com'
67
- email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
68
- link_raw = 'http://www.rubyonrails.com'
69
- link_result = %{<a href="#{link_raw}">#{link_raw}</a>}
70
- link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
71
- link2_raw = 'www.rubyonrails.com'
72
- link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
73
- link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
74
- link3_result = %{<a href="#{link3_raw}">#{link3_raw}</a>}
75
- link4_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
76
- link4_result = %{<a href="#{link4_raw}">#{CGI.escapeHTML(link4_raw)}</a>}
77
- link5_raw = 'http://foo.example.com:3000/controller/action'
78
- link5_result = %{<a href="#{link5_raw}">#{link5_raw}</a>}
79
- link6_raw = 'http://foo.example.com:3000/controller/action+pack'
80
- link6_result = %{<a href="#{link6_raw}">#{link6_raw}</a>}
81
- link7_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
82
- link7_result = %{<a href="#{link7_raw}">#{CGI.escapeHTML(link7_raw)}</a>}
83
- link8_raw = 'http://foo.example.com:3000/controller/action.html'
84
- link8_result = %{<a href="#{link8_raw}">#{link8_raw}</a>}
85
- link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
86
- link9_result = %{<a href="#{link9_raw}">#{link9_raw}</a>}
87
- link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
88
- link10_result = %{<a href="#{link10_raw}">#{link10_raw}</a>}
89
-
90
- assert_linked %(Go to #{link_result} and say hello to #{email_result}), "Go to #{link_raw} and say hello to #{email_raw}"
91
- assert_linked %(<p>Link #{link_result}</p>), "<p>Link #{link_raw}</p>"
92
- assert_linked %(<p>#{link_result} Link</p>), "<p>#{link_raw} Link</p>"
93
- assert_linked %(Go to #{link_result}.), %(Go to #{link_raw}.)
94
- assert_linked %(<p>Go to #{link_result}, then say hello to #{email_result}.</p>), %(<p>Go to #{link_raw}, then say hello to #{email_raw}.</p>)
95
- assert_linked %(<p>Link #{link2_result}</p>), "<p>Link #{link2_raw}</p>"
96
- assert_linked %(<p>#{link2_result} Link</p>), "<p>#{link2_raw} Link</p>"
97
- assert_linked %(Go to #{link2_result}.), %(Go to #{link2_raw}.)
98
- # assert_linked %(<p>Say hello to #{email_result}, then go to #{link2_result},</p>), %(<p>Say hello to #{email_raw}, then go to #{link2_raw},</p>)
99
- assert_linked %(<p>Link #{link3_result}</p>), "<p>Link #{link3_raw}</p>"
100
- assert_linked %(<p>#{link3_result} Link</p>), "<p>#{link3_raw} Link</p>"
101
- assert_linked %(Go to #{link3_result}.), %(Go to #{link3_raw}.)
102
- assert_linked %(<p>Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.</p>), %(<p>Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.</p>)
103
- assert_linked %(<p>Link #{link4_result}</p>), "<p>Link #{link4_raw}</p>"
104
- assert_linked %(<p>#{link4_result} Link</p>), "<p>#{link4_raw} Link</p>"
105
- assert_linked %(<p>#{link5_result} Link</p>), "<p>#{link5_raw} Link</p>"
106
- assert_linked %(<p>#{link6_result} Link</p>), "<p>#{link6_raw} Link</p>"
107
- assert_linked %(<p>#{link7_result} Link</p>), "<p>#{link7_raw} Link</p>"
108
- assert_linked %(<p>Link #{link8_result}</p>), "<p>Link #{link8_raw}</p>"
109
- assert_linked %(<p>#{link8_result} Link</p>), "<p>#{link8_raw} Link</p>"
110
- assert_linked %(Go to #{link8_result}.), %(Go to #{link8_raw}.)
111
- assert_linked %(<p>Go to #{link8_result}. seriously, #{link8_result}? i think I'll say hello to #{email_result}. instead.</p>), %(<p>Go to #{link8_raw}. seriously, #{link8_raw}? i think I'll say hello to #{email_raw}. instead.</p>)
112
- assert_linked %(<p>Link #{link9_result}</p>), "<p>Link #{link9_raw}</p>"
113
- assert_linked %(<p>#{link9_result} Link</p>), "<p>#{link9_raw} Link</p>"
114
- assert_linked %(Go to #{link9_result}.), %(Go to #{link9_raw}.)
115
- assert_linked %(<p>Go to #{link9_result}. seriously, #{link9_result}? i think I'll say hello to #{email_result}. instead.</p>), %(<p>Go to #{link9_raw}. seriously, #{link9_raw}? i think I'll say hello to #{email_raw}. instead.</p>)
116
- assert_linked %(<p>#{link10_result} Link</p>), "<p>#{link10_raw} Link</p>"
117
- assert_linked email2_result, email2_raw
118
- assert_linked "#{link_result} #{link_result} #{link_result}", "#{link_raw} #{link_raw} #{link_raw}"
119
- assert_linked '<a href="http://www.rubyonrails.com">Ruby On Rails</a>', '<a href="http://www.rubyonrails.com">Ruby On Rails</a>'
120
- end
121
- end