redcarpet 2.0.0b3 → 2.0.0b4

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.

@@ -1,4 +1,4 @@
1
- #ifndef __REDCARPET_H__
1
+ #ifndef __REDCARPET_H__
2
2
  #define __REDCARPET_H__
3
3
 
4
4
  #define RSTRING_NOT_MODIFIED
@@ -6,9 +6,10 @@
6
6
  #include <stdio.h>
7
7
 
8
8
  #ifdef HAVE_RUBY_ENCODING_H
9
- #include <ruby/encoding.h>
9
+ # include <ruby/encoding.h>
10
+ # define redcarpet_str_new(data, size) rb_enc_str_new(data, size, rb_utf8_encoding())
10
11
  #else
11
- #define rb_enc_copy(dst, src)
12
+ # define redcarpet_str_new(data, size) rb_str_new(data, size)
12
13
  #endif
13
14
 
14
15
  #include "markdown.h"
@@ -0,0 +1,81 @@
1
+ #include "stack.h"
2
+ #include <string.h>
3
+
4
+ int
5
+ stack_grow(struct stack *st, size_t new_size)
6
+ {
7
+ void **new_st;
8
+
9
+ if (st->asize >= new_size)
10
+ return 0;
11
+
12
+ new_st = realloc(st->item, new_size * sizeof(void *));
13
+ if (new_st == NULL)
14
+ return -1;
15
+
16
+ memset(new_st + st->asize, 0x0,
17
+ (new_size - st->asize) * sizeof(void *));
18
+
19
+ st->item = new_st;
20
+ st->asize = new_size;
21
+
22
+ if (st->size > new_size)
23
+ st->size = new_size;
24
+
25
+ return 0;
26
+ }
27
+
28
+ void
29
+ stack_free(struct stack *st)
30
+ {
31
+ if (!st)
32
+ return;
33
+
34
+ free(st->item);
35
+
36
+ st->item = NULL;
37
+ st->size = 0;
38
+ st->asize = 0;
39
+ }
40
+
41
+ int
42
+ stack_init(struct stack *st, size_t initial_size)
43
+ {
44
+ st->item = NULL;
45
+ st->size = 0;
46
+ st->asize = 0;
47
+
48
+ if (!initial_size)
49
+ initial_size = 8;
50
+
51
+ return stack_grow(st, initial_size);
52
+ }
53
+
54
+ void *
55
+ stack_pop(struct stack *st)
56
+ {
57
+ if (!st->size)
58
+ return NULL;
59
+
60
+ return st->item[st->size--];
61
+ }
62
+
63
+ int
64
+ stack_push(struct stack *st, void *item)
65
+ {
66
+ if (stack_grow(st, st->size * 2) < 0)
67
+ return -1;
68
+
69
+ st->item[st->size++] = item;
70
+ return 0;
71
+ }
72
+
73
+ void *
74
+ stack_top(struct stack *st)
75
+ {
76
+ if (!st->size)
77
+ return NULL;
78
+
79
+ return st->item[st->size - 1];
80
+ }
81
+
@@ -0,0 +1,21 @@
1
+ #ifndef __CR_STACK_H__
2
+ #define __CR_STACK_H__
3
+
4
+ #include <stdlib.h>
5
+
6
+ struct stack {
7
+ void **item;
8
+ size_t size;
9
+ size_t asize;
10
+ };
11
+
12
+ void stack_free(struct stack *);
13
+ int stack_grow(struct stack *, size_t);
14
+ int stack_init(struct stack *, size_t);
15
+
16
+ int stack_push(struct stack *, void *);
17
+
18
+ void *stack_pop(struct stack *);
19
+ void *stack_top(struct stack *);
20
+
21
+ #endif
data/lib/redcarpet.rb CHANGED
@@ -1,29 +1,10 @@
1
1
  require 'redcarpet.so'
2
2
 
3
3
  module Redcarpet
4
- VERSION = '2.0.0b3'
4
+ VERSION = '2.0.0b4'
5
5
 
6
6
  class Markdown
7
- # Available Markdown extensions
8
- attr_accessor :no_intra_emphasis
9
- attr_accessor :tables
10
- attr_accessor :fenced_code_blocks
11
- attr_accessor :autolink
12
- attr_accessor :strikethrough
13
- attr_accessor :lax_html_blocks
14
- attr_accessor :space_after_headers
15
- attr_accessor :superscript
16
-
17
- attr_accessor :renderer
18
-
19
- def initialize(renderer, extensions={})
20
- if renderer.instance_of? Class
21
- renderer = renderer.new
22
- end
23
-
24
- @renderer = renderer
25
- extensions.each_pair { |k, v| send("#{k}=", v) }
26
- end
7
+ attr_reader :renderer
27
8
  end
28
9
 
29
10
  module Render
@@ -41,7 +22,7 @@ module Redcarpet
41
22
  end
42
23
 
43
24
  # SmartyPants Mixin module
44
- #
25
+ #
45
26
  # Implements SmartyPants.postprocess, which
46
27
  # performs smartypants replacements on the HTML file,
47
28
  # once it has been fully rendered.
@@ -61,7 +42,7 @@ module Redcarpet
61
42
  # end
62
43
  #
63
44
  # # Standalone
64
- # Redcarpet::Render::SmartyPants.postprocess("you're")
45
+ # Redcarpet::Render::SmartyPants.render("you're")
65
46
  #
66
47
  module SmartyPants
67
48
  extend self
data/redcarpet.gemspec CHANGED
@@ -1,9 +1,10 @@
1
+ # encoding: utf-8
1
2
  Gem::Specification.new do |s|
2
3
  s.name = 'redcarpet'
3
- s.version = '2.0.0b3'
4
+ s.version = '2.0.0b4'
4
5
  s.summary = "Markdown that smells nice"
5
6
  s.description = 'A fast, safe and extensible Markdown to (X)HTML parser'
6
- s.date = '2011-08-09'
7
+ s.date = '2011-09-08'
7
8
  s.email = 'vicent@github.com'
8
9
  s.homepage = 'http://github.com/tanoku/redcarpet'
9
10
  s.authors = ["Natacha Porté", "Vicent Martí"]
@@ -13,8 +14,6 @@ Gem::Specification.new do |s|
13
14
  README.markdown
14
15
  Rakefile
15
16
  bin/redcarpet
16
- ext/redcarpet/array.c
17
- ext/redcarpet/array.h
18
17
  ext/redcarpet/autolink.c
19
18
  ext/redcarpet/autolink.h
20
19
  ext/redcarpet/buffer.c
@@ -22,12 +21,15 @@ Gem::Specification.new do |s|
22
21
  ext/redcarpet/extconf.rb
23
22
  ext/redcarpet/html.c
24
23
  ext/redcarpet/html.h
24
+ ext/redcarpet/html_blocks.h
25
25
  ext/redcarpet/html_smartypants.c
26
26
  ext/redcarpet/markdown.c
27
27
  ext/redcarpet/markdown.h
28
28
  ext/redcarpet/rc_markdown.c
29
29
  ext/redcarpet/rc_render.c
30
30
  ext/redcarpet/redcarpet.h
31
+ ext/redcarpet/stack.c
32
+ ext/redcarpet/stack.h
31
33
  lib/redcarpet.rb
32
34
  lib/redcarpet/render_man.rb
33
35
  redcarpet.gemspec
@@ -2,6 +2,10 @@
2
2
  rootdir = File.dirname(File.dirname(__FILE__))
3
3
  $LOAD_PATH.unshift "#{rootdir}/lib"
4
4
 
5
+ if defined? Encoding
6
+ Encoding.default_internal = 'UTF-8'
7
+ end
8
+
5
9
  require 'test/unit'
6
10
  require 'redcarpet'
7
11
  require 'redcarpet/render_man'
@@ -9,7 +13,7 @@ require 'nokogiri'
9
13
 
10
14
  def html_equal(html_a, html_b)
11
15
  assert_equal Nokogiri::HTML::DocumentFragment.parse(html_a).to_html,
12
- Nokogiri::HTML::DocumentFragment.parse(html_b).to_html
16
+ Nokogiri::HTML::DocumentFragment.parse(html_b).to_html
13
17
  end
14
18
 
15
19
  class SmartyPantsTest < Test::Unit::TestCase
@@ -19,38 +23,32 @@ class SmartyPantsTest < Test::Unit::TestCase
19
23
 
20
24
  def test_that_smart_converts_single_quotes_in_words_that_end_in_re
21
25
  markdown = @pants.render("<p>They're not for sale.</p>")
22
- html_equal "<p>They&rsquo;re not for sale.</p>", markdown
26
+ assert_equal "<p>They&rsquo;re not for sale.</p>", markdown
23
27
  end
24
28
 
25
29
  def test_that_smart_converts_single_quotes_in_words_that_end_in_ll
26
30
  markdown = @pants.render("<p>Well that'll be the day</p>")
27
- html_equal "<p>Well that&rsquo;ll be the day</p>", markdown
31
+ assert_equal "<p>Well that&rsquo;ll be the day</p>", markdown
28
32
  end
29
33
 
30
34
  def test_that_smart_converts_double_quotes_to_curly_quotes
31
35
  rd = @pants.render(%(<p>"Quoted text"</p>))
32
- html_equal %(<p>&ldquo;Quoted text&rdquo;</p>), rd
36
+ assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>), rd
33
37
  end
34
38
 
35
39
  def test_that_smart_gives_ve_suffix_a_rsquo
36
40
  rd = @pants.render("<p>I've been meaning to tell you ..</p>")
37
- html_equal "<p>I&rsquo;ve been meaning to tell you ..</p>\n", rd
41
+ assert_equal "<p>I&rsquo;ve been meaning to tell you ..</p>", rd
38
42
  end
39
43
 
40
44
  def test_that_smart_gives_m_suffix_a_rsquo
41
45
  rd = @pants.render("<p>I'm not kidding</p>")
42
- html_equal "<p>I&rsquo;m not kidding</p>\n", rd
46
+ assert_equal "<p>I&rsquo;m not kidding</p>", rd
43
47
  end
44
48
 
45
49
  def test_that_smart_gives_d_suffix_a_rsquo
46
50
  rd = @pants.render("<p>what'd you say?</p>")
47
- html_equal "<p>what&rsquo;d you say?</p>\n", rd
48
- end
49
- end
50
-
51
- class SmartyHTMLTests < SmartyPantsTest
52
- def setup
53
- @pants = Redcarpet::Markdown.new Redcarpet::Render::SmartyHTML
51
+ assert_equal "<p>what&rsquo;d you say?</p>", rd
54
52
  end
55
53
  end
56
54
 
@@ -59,34 +57,38 @@ class HTMLRenderTest < Test::Unit::TestCase
59
57
  @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
60
58
  @rndr = {
61
59
  :no_html => Redcarpet::Render::HTML.new(:filter_html => true),
62
- :no_image => Redcarpet::Render::HTML.new(:no_image => true),
60
+ :no_images => Redcarpet::Render::HTML.new(:no_images => true),
63
61
  :no_links => Redcarpet::Render::HTML.new(:no_links => true),
64
62
  :safe_links => Redcarpet::Render::HTML.new(:safe_links_only => true),
65
63
  }
66
64
  end
67
65
 
66
+ def render_with(rndr, text)
67
+ Redcarpet::Markdown.new(rndr).render(text)
68
+ end
69
+
68
70
  def test_that_filter_html_works
69
- markdown = @markdown.render_with(@rndr[:no_html], 'Through <em>NO</em> <script>DOUBLE NO</script>')
71
+ markdown = render_with(@rndr[:no_html], 'Through <em>NO</em> <script>DOUBLE NO</script>')
70
72
  html_equal "<p>Through NO DOUBLE NO</p>", markdown
71
73
  end
72
74
 
73
75
  def test_filter_html_doesnt_break_two_space_hard_break
74
- markdown = @markdown.render_with(@rndr[:no_html], "Lorem, \nipsum\n")
76
+ markdown = render_with(@rndr[:no_html], "Lorem, \nipsum\n")
75
77
  html_equal "<p>Lorem,<br/>\nipsum</p>\n", markdown
76
78
  end
77
79
 
78
80
  def test_that_no_image_flag_works
79
- rd = @markdown.render_with(@rndr[:no_image], %(![dust mite](http://dust.mite/image.png) <img src="image.png" />))
81
+ rd = render_with(@rndr[:no_images], %(![dust mite](http://dust.mite/image.png) <img src="image.png" />))
80
82
  assert rd !~ /<img/
81
83
  end
82
84
 
83
85
  def test_that_no_links_flag_works
84
- rd = @markdown.render_with(@rndr[:no_links], %([This link](http://example.net/) <a href="links.html">links</a>))
86
+ rd = render_with(@rndr[:no_links], %([This link](http://example.net/) <a href="links.html">links</a>))
85
87
  assert rd !~ /<a /
86
88
  end
87
89
 
88
90
  def test_that_safelink_flag_works
89
- rd = @markdown.render_with(@rndr[:safe_links], "[IRC](irc://chat.freenode.org/#freenode)")
91
+ rd = render_with(@rndr[:safe_links], "[IRC](irc://chat.freenode.org/#freenode)")
90
92
  html_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>\n", rd
91
93
  end
92
94
 
@@ -98,6 +100,10 @@ class MarkdownTest < Test::Unit::TestCase
98
100
  @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
99
101
  end
100
102
 
103
+ def render_with(flags, text)
104
+ Redcarpet::Markdown.new(Redcarpet::Render::HTML, flags).render(text)
105
+ end
106
+
101
107
  def test_that_simple_one_liner_goes_to_html
102
108
  assert_respond_to @markdown, :render
103
109
  html_equal "<p>Hello World.</p>", @markdown.render("Hello World.")
@@ -109,8 +115,7 @@ class MarkdownTest < Test::Unit::TestCase
109
115
  end
110
116
 
111
117
  def test_that_inline_markdown_starts_and_ends_correctly
112
- @markdown.no_intra_emphasis = true
113
- markdown = @markdown.render('_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>')
118
+ markdown = render_with({:no_intra_emphasis => true}, '_start _ foo_bar bar_baz _ end_ *italic* **bold** <a>_blah_</a>')
114
119
 
115
120
  html_equal "<p><em>start _ foo_bar bar_baz _ end</em> <em>italic</em> <strong>bold</strong> <a><em>blah</em></a></p>", markdown
116
121
 
@@ -147,8 +152,7 @@ class MarkdownTest < Test::Unit::TestCase
147
152
  end
148
153
 
149
154
  def test_para_before_block_html_should_not_wrap_in_p_tag
150
- @markdown.lax_html_blocks = true
151
- markdown = @markdown.render(
155
+ markdown = render_with({:lax_html_blocks => true},
152
156
  "Things to watch out for\n" +
153
157
  "<ul>\n<li>Blah</li>\n</ul>\n")
154
158
 
@@ -165,17 +169,15 @@ class MarkdownTest < Test::Unit::TestCase
165
169
  end
166
170
 
167
171
  def test_that_intra_emphasis_works
168
- rd = @markdown.render("foo_bar_baz")
172
+ rd = render_with({}, "foo_bar_baz")
169
173
  html_equal "<p>foo<em>bar</em>baz</p>\n", rd
170
174
 
171
- @markdown.no_intra_emphasis = true
172
- rd = @markdown.render("foo_bar_baz")
175
+ rd = render_with({:no_intra_emphasis => true},"foo_bar_baz")
173
176
  html_equal "<p>foo_bar_baz</p>\n", rd
174
177
  end
175
178
 
176
179
  def test_that_autolink_flag_works
177
- @markdown.autolink = true
178
- rd = @markdown.render("http://github.com/rtomayko/rdiscount")
180
+ rd = render_with({:autolink => true}, "http://github.com/rtomayko/rdiscount")
179
181
  html_equal "<p><a href=\"http://github.com/rtomayko/rdiscount\">http://github.com/rtomayko/rdiscount</a></p>\n", rd
180
182
  end
181
183
 
@@ -199,8 +201,7 @@ class MarkdownTest < Test::Unit::TestCase
199
201
  end
200
202
 
201
203
  def test_whitespace_after_urls
202
- @markdown.autolink = true
203
- rd = @markdown.render("Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)")
204
+ rd = render_with({:autolink => true}, "Japan: http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm (yes, japan)")
204
205
  exp = %{<p>Japan: <a href="http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm">http://www.abc.net.au/news/events/japan-quake-2011/beforeafter.htm</a> (yes, japan)</p>}
205
206
  html_equal exp, rd
206
207
  end
@@ -235,19 +236,17 @@ class MarkdownTest < Test::Unit::TestCase
235
236
  hello|sailor
236
237
  EOS
237
238
 
238
- assert @markdown.render(text) !~ /<table/
239
+ assert render_with({}, text) !~ /<table/
239
240
 
240
- @markdown.tables = true
241
- assert @markdown.render(text) =~ /<table/
241
+ assert render_with({:tables => true}, text) =~ /<table/
242
242
  end
243
243
 
244
244
  def test_strikethrough_flag_works
245
245
  text = "this is ~some~ striked ~~text~~"
246
246
 
247
- assert @markdown.render(text) !~ /<del/
247
+ assert render_with({}, text) !~ /<del/
248
248
 
249
- @markdown.strikethrough = true
250
- assert @markdown.render(text) =~ /<del/
249
+ assert render_with({:strikethrough => true}, text) =~ /<del/
251
250
  end
252
251
 
253
252
  def test_that_fenced_flag_works
@@ -260,10 +259,9 @@ This is some awesome code
260
259
  ~~~
261
260
  fenced
262
261
 
263
- assert @markdown.render(text) !~ /<code/
262
+ assert render_with({}, text) !~ /<code/
264
263
 
265
- @markdown.fenced_code_blocks = true
266
- assert @markdown.render(text) =~ /<code/
264
+ assert render_with({:fenced_code_blocks => true}, text) =~ /<code/
267
265
  end
268
266
 
269
267
  def test_that_headers_are_linkable
@@ -272,16 +270,14 @@ fenced
272
270
  end
273
271
 
274
272
  def test_autolinking_with_ent_chars
275
- @markdown.autolink = true
276
- markdown = @markdown.render(<<text)
273
+ markdown = render_with({:autolink => true}, <<text)
277
274
  This a stupid link: https://github.com/rtomayko/tilt/issues?milestone=1&state=open
278
275
  text
279
276
  html_equal "<p>This a stupid link: <a href=\"https://github.com/rtomayko/tilt/issues?milestone=1&state=open\">https://github.com/rtomayko/tilt/issues?milestone=1&amp;state=open</a></p>\n", markdown
280
277
  end
281
278
 
282
279
  def test_spaced_headers
283
- @markdown.space_after_headers = true
284
- rd = @markdown.render("#123 a header yes\n")
280
+ rd = render_with({:space_after_headers => true}, "#123 a header yes\n")
285
281
  assert rd !~ /<h1>/
286
282
  end
287
283
  end
metadata CHANGED
@@ -1,43 +1,52 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: redcarpet
3
- version: !ruby/object:Gem::Version
4
- version: 2.0.0b3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
5
  prerelease: 5
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ - b
11
+ - 4
12
+ version: 2.0.0b4
6
13
  platform: ruby
7
- authors:
8
- - Natacha Porté
9
- - Vicent Martí
14
+ authors:
15
+ - "Natacha Port\xC3\xA9"
16
+ - "Vicent Mart\xC3\xAD"
10
17
  autorequire:
11
18
  bindir: bin
12
19
  cert_chain: []
13
- date: 2011-08-09 00:00:00.000000000Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
20
+
21
+ date: 2011-09-08 00:00:00 Z
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
16
24
  name: rake-compiler
17
- requirement: &70234078705880 !ruby/object:Gem::Requirement
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
18
27
  none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ hash: 3
32
+ segments:
33
+ - 0
34
+ version: "0"
23
35
  type: :development
24
- prerelease: false
25
- version_requirements: *70234078705880
36
+ version_requirements: *id001
26
37
  description: A fast, safe and extensible Markdown to (X)HTML parser
27
38
  email: vicent@github.com
28
- executables:
39
+ executables:
29
40
  - redcarpet
30
- extensions:
41
+ extensions:
31
42
  - ext/redcarpet/extconf.rb
32
- extra_rdoc_files:
43
+ extra_rdoc_files:
33
44
  - COPYING
34
- files:
45
+ files:
35
46
  - COPYING
36
47
  - README.markdown
37
48
  - Rakefile
38
49
  - bin/redcarpet
39
- - ext/redcarpet/array.c
40
- - ext/redcarpet/array.h
41
50
  - ext/redcarpet/autolink.c
42
51
  - ext/redcarpet/autolink.h
43
52
  - ext/redcarpet/buffer.c
@@ -45,39 +54,53 @@ files:
45
54
  - ext/redcarpet/extconf.rb
46
55
  - ext/redcarpet/html.c
47
56
  - ext/redcarpet/html.h
57
+ - ext/redcarpet/html_blocks.h
48
58
  - ext/redcarpet/html_smartypants.c
49
59
  - ext/redcarpet/markdown.c
50
60
  - ext/redcarpet/markdown.h
51
61
  - ext/redcarpet/rc_markdown.c
52
62
  - ext/redcarpet/rc_render.c
53
63
  - ext/redcarpet/redcarpet.h
64
+ - ext/redcarpet/stack.c
65
+ - ext/redcarpet/stack.h
54
66
  - lib/redcarpet.rb
55
67
  - lib/redcarpet/render_man.rb
56
68
  - redcarpet.gemspec
57
69
  - test/redcarpet_test.rb
58
70
  homepage: http://github.com/tanoku/redcarpet
59
71
  licenses: []
72
+
60
73
  post_install_message:
61
74
  rdoc_options: []
62
- require_paths:
75
+
76
+ require_paths:
63
77
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
65
79
  none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
86
+ version: "0"
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
88
  none: false
72
- requirements:
73
- - - ! '>'
74
- - !ruby/object:Gem::Version
89
+ requirements:
90
+ - - ">"
91
+ - !ruby/object:Gem::Version
92
+ hash: 25
93
+ segments:
94
+ - 1
95
+ - 3
96
+ - 1
75
97
  version: 1.3.1
76
98
  requirements: []
99
+
77
100
  rubyforge_project:
78
101
  rubygems_version: 1.8.6
79
102
  signing_key:
80
103
  specification_version: 3
81
104
  summary: Markdown that smells nice
82
- test_files:
105
+ test_files:
83
106
  - test/redcarpet_test.rb