redcarpet 1.6.0 → 1.7.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.

@@ -1,26 +1,54 @@
1
- Markdown + Ruby + libupskirt
2
- ============================
1
+ Ruby + Upskirt = Markdown that doesn't suck
2
+ ===========================================
3
3
 
4
- > Inspired by Rick Astley wearing a kilt
4
+ Redcarpet is a Ruby wrapper for Upskirt. It is mostly based on Ryan
5
+ Tomayko's RDiscount wrapper, and inspired by Rick Astley wearing a kilt.
5
6
 
6
- Upskirt is an implementation of John Gruber's Markdown markup
7
- language. Upskirt is safe, fast and production ready. Check out
8
- the original version at <http://git.instinctive.eu/cgit/libupskirt/>
7
+ Redcarpet is powered by the Upskirt library, which can be found at
9
8
 
10
- Redcarpet is Upskirt with a touch of Ruby. It is mostly based on Ryan
11
- Tomayko's RDiscount wrapper, and inspired by Rick Astley wearing a kilt.
9
+ https://www.github.com/tanoku/upskirt
10
+
11
+ You might want to find out more about Upskirt to see what makes these Ruby
12
+ bindings so awesome.
13
+
14
+ Credits
15
+ -------
16
+
17
+ * Natacha Porté, lady of Markdown
18
+ * Vicent Martí, wannabe
19
+ * With special thanks to Ryan Tomayko
20
+
21
+ Install
22
+ -------
23
+
24
+ Redcarpet is readily available as a Ruby gem:
12
25
 
13
- Redcarpet is powered by a modified version of Upskirt, which has been
14
- updated to pass the official Markdown test suite and now has support
15
- for many additional features: autolinks, smartypants, safe filters,
16
- and a long etcetera.
26
+ $ [sudo] gem install redcarpet
17
27
 
18
- Redcarpet is a drop-in replacement for BlueCloth, RedCloth and RDiscount.
28
+ The Redcarpet source (including Upskirt as a submodule) is available at GitHub:
19
29
 
20
- * Upskirt is (C)2009 Natacha Porté
21
- * Upskirt has been brought back to life and made standards-compilant in 2011 by Vicent Marti
22
- * Redcarpet is (C)2011 Vicent Marti
23
-
30
+ $ git clone git://github.com/tanoku/redcarpet.git
31
+
32
+ Usage
33
+ -----
34
+
35
+ Redcarpet implements the basic protocol popularized by RedCloth:
36
+
37
+ require 'redcarpet'
38
+ markdown = Redcarpet.new("Hello World!")
39
+ puts markdown.to_html
40
+
41
+ Additional processing options can be turned on when creating the
42
+ Redcarpet object:
43
+
44
+ markdown = Redcarpet.new("Hello World!", :smart, :filter_html)
45
+
46
+ Note that by default, Redcarpet parses standard Markdown (with no extensions)
47
+ and offers a sane subset of parse options which allow you to modify the rendering
48
+ output and to enable MD extensions on a per-case basis.
49
+
50
+ Redcarpet also offers a wrapper class, `RedcarpetCompat` with the same flags
51
+ and behavior as the RDiscount library, which acts as a drop-in replacement.
24
52
 
25
53
  License
26
54
  -------
@@ -36,3 +64,4 @@ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
36
64
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
37
65
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
38
66
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
67
+
data/Rakefile CHANGED
@@ -133,3 +133,23 @@ file 'redcarpet.gemspec' => FileList['Rakefile','lib/redcarpet.rb'] do |f|
133
133
  File.open(f.name, 'w') { |io| io.write(spec) }
134
134
  puts "updated #{f.name}"
135
135
  end
136
+
137
+ desc 'Gather required Upskirt sources into extension directory'
138
+ task :gather => 'upskirt/src/markdown.h' do |t|
139
+ files =
140
+ FileList[
141
+ 'upskirt/src/{markdown,buffer,array}.h',
142
+ 'upskirt/src/{markdown,buffer,array}.c',
143
+ 'upskirt/render/xhtml.c',
144
+ 'upskirt/render/xhtml.h',
145
+ ]
146
+ cp files, 'ext/',
147
+ :preserve => true,
148
+ :verbose => true
149
+ end
150
+
151
+ file 'upskirt/src/markdown.h' do |t|
152
+ abort "The Upskirt submodule is required."
153
+ end
154
+
155
+
@@ -18,12 +18,12 @@
18
18
  */
19
19
 
20
20
  #include "markdown.h"
21
-
22
21
  #include "array.h"
23
22
 
24
23
  #include <assert.h>
25
24
  #include <string.h>
26
25
  #include <strings.h> /* for strncasecmp */
26
+ #include <ctype.h>
27
27
 
28
28
  #define TEXT_UNIT 64 /* unit for the copy of the input buffer */
29
29
  #define WORK_UNIT 64 /* block-level working buffer */
@@ -948,7 +948,6 @@ static size_t
948
948
  is_codefence(char *data, size_t size)
949
949
  {
950
950
  size_t i = 0, n = 0;
951
- char c;
952
951
 
953
952
  /* skipping initial spaces */
954
953
  if (size < 3) return 0;
@@ -1113,8 +1112,6 @@ parse_paragraph(struct buf *ob, struct render *rndr, char *data, size_t size)
1113
1112
  struct buf work = { data, 0, 0, 0, 0 }; /* volatile working buffer */
1114
1113
 
1115
1114
  while (i < size) {
1116
- size_t html_size;
1117
-
1118
1115
  for (end = i + 1; end < size && data[end - 1] != '\n'; end++) /* empty */;
1119
1116
 
1120
1117
  if (is_empty(data + i, size - i) || (level = is_headerline(data + i, size - i)) != 0)
@@ -1747,8 +1744,6 @@ parse_table_header(struct buf *ob, struct render *rndr, char *data, size_t size,
1747
1744
  under_end++;
1748
1745
 
1749
1746
  for (col = 0; col < *columns && i < under_end; ++col) {
1750
- size_t cell_start, cell_end;
1751
-
1752
1747
  if (data[i] == ':') {
1753
1748
  i++; (*column_data)[col] |= MKD_TABLE_ALIGN_L;
1754
1749
  }
@@ -1804,7 +1799,6 @@ parse_table(struct buf *ob, struct render *rndr, char *data, size_t size)
1804
1799
  if (i > 0) {
1805
1800
 
1806
1801
  while (i < size) {
1807
- size_t row_len;
1808
1802
  size_t row_start;
1809
1803
  int pipes = 0;
1810
1804
 
@@ -2032,7 +2026,7 @@ static void expand_tabs(struct buf *ob, const char *line, size_t size)
2032
2026
 
2033
2027
  /* markdown • parses the input buffer and renders it into the output buffer */
2034
2028
  void
2035
- markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndrer, unsigned int extensions) {
2029
+ ups_markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndrer, unsigned int extensions) {
2036
2030
  struct link_ref *lr;
2037
2031
  struct buf *text = bufnew(TEXT_UNIT);
2038
2032
  size_t i, beg, end;
@@ -2049,10 +2043,11 @@ markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndrer, unsi
2049
2043
  for (i = 0; i < 256; i += 1)
2050
2044
  rndr.active_char[i] = 0;
2051
2045
 
2052
- if ((rndr.make.emphasis || rndr.make.double_emphasis || rndr.make.triple_emphasis) &&
2053
- rndr.make.emph_chars) {
2054
- for (i = 0; rndr.make.emph_chars[i]; i += 1)
2055
- rndr.active_char[(unsigned char)rndr.make.emph_chars[i]] = char_emphasis;
2046
+ if (rndr.make.emphasis || rndr.make.double_emphasis || rndr.make.triple_emphasis) {
2047
+ rndr.active_char['*'] = char_emphasis;
2048
+ rndr.active_char['_'] = char_emphasis;
2049
+ if (extensions & MKDEXT_STRIKETHROUGH)
2050
+ rndr.active_char['~'] = char_emphasis;
2056
2051
  }
2057
2052
 
2058
2053
  if (rndr.make.codespan)
@@ -41,6 +41,7 @@ enum mkd_extensions {
41
41
  MKDEXT_TABLES = (1 << 1),
42
42
  MKDEXT_FENCED_CODE = (1 << 2),
43
43
  MKDEXT_AUTOLINK = (1 << 3),
44
+ MKDEXT_STRIKETHROUGH = (1 << 4),
44
45
  };
45
46
 
46
47
  /* mkd_renderer • functions for rendering parsed data */
@@ -78,8 +79,7 @@ struct mkd_renderer {
78
79
  void (*doc_header)(struct buf *ob, void *opaque);
79
80
  void (*doc_footer)(struct buf *ob, void *opaque);
80
81
 
81
- /* renderer data */
82
- const char *emph_chars; /* chars that trigger emphasis rendering */
82
+ /* user data */
83
83
  void *opaque;
84
84
  };
85
85
 
@@ -106,8 +106,8 @@ is_safe_link(const char *link, size_t link_len);
106
106
  **********************/
107
107
 
108
108
  /* markdown • parses the input buffer and renders it into the output buffer */
109
- void
110
- markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndr, unsigned int extensions);
109
+ extern void
110
+ ups_markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndr, unsigned int extensions);
111
111
 
112
112
  #endif
113
113
 
@@ -62,7 +62,7 @@ static void rb_redcarpet__get_flags(VALUE ruby_obj,
62
62
  extensions |= MKDEXT_AUTOLINK;
63
63
 
64
64
  if (rb_funcall(ruby_obj, rb_intern("strikethrough"), 0) == Qtrue)
65
- render_flags |= XHTML_STRIKETHROUGH;
65
+ extensions |= MKDEXT_STRIKETHROUGH;
66
66
 
67
67
  *enabled_extensions_p = extensions;
68
68
  *render_flags_p = render_flags;
@@ -90,22 +90,22 @@ static VALUE rb_redcarpet__render(VALUE self, RendererType render_type)
90
90
 
91
91
  switch (render_type) {
92
92
  case REDCARPET_RENDER_XHTML:
93
- init_xhtml_renderer(&renderer, render_flags);
93
+ ups_xhtml_renderer(&renderer, render_flags);
94
94
  break;
95
95
 
96
96
  case REDCARPET_RENDER_TOC:
97
- init_toc_renderer(&renderer);
97
+ ups_toc_renderer(&renderer);
98
98
  break;
99
99
 
100
100
  default:
101
101
  return Qnil;
102
102
  }
103
103
 
104
- markdown(output_buf, &input_buf, &renderer, enabled_extensions);
104
+ ups_markdown(output_buf, &input_buf, &renderer, enabled_extensions);
105
105
 
106
106
  result = rb_str_new(output_buf->data, output_buf->size);
107
107
  bufrelease(output_buf);
108
- free_renderer(&renderer);
108
+ ups_free_renderer(&renderer);
109
109
 
110
110
  /* force the input encoding */
111
111
  if (rb_respond_to(text, rb_intern("encoding"))) {
@@ -21,6 +21,7 @@
21
21
  #include <strings.h>
22
22
  #include <stdlib.h>
23
23
  #include <stdio.h>
24
+ #include <ctype.h>
24
25
 
25
26
  struct xhtml_renderopt {
26
27
  struct {
@@ -139,15 +140,10 @@ rndr_codespan(struct buf *ob, struct buf *text, void *opaque)
139
140
  static int
140
141
  rndr_double_emphasis(struct buf *ob, struct buf *text, char c, void *opaque)
141
142
  {
142
- struct xhtml_renderopt *options = opaque;
143
-
144
143
  if (!text || !text->size)
145
144
  return 0;
146
145
 
147
146
  if (c == '~') {
148
- if ((options->flags & XHTML_STRIKETHROUGH) == 0)
149
- return 0;
150
-
151
147
  BUFPUTSL(ob, "<span style=\"text-decoration:line-through;\">");
152
148
  bufput(ob, text->data, text->size);
153
149
  BUFPUTSL(ob, "</span>");
@@ -412,7 +408,7 @@ static struct {
412
408
 
413
409
  #define SUBS_COUNT (sizeof(smartypants_subs) / sizeof(smartypants_subs[0]))
414
410
 
415
- static inline
411
+ static inline int
416
412
  word_boundary(char c)
417
413
  {
418
414
  return isspace(c) || ispunct(c);
@@ -628,7 +624,7 @@ toc_finalize(struct buf *ob, void *opaque)
628
624
  }
629
625
 
630
626
  void
631
- init_toc_renderer(struct mkd_renderer *renderer)
627
+ ups_toc_renderer(struct mkd_renderer *renderer)
632
628
  {
633
629
  static const struct mkd_renderer toc_render = {
634
630
  NULL,
@@ -659,7 +655,6 @@ init_toc_renderer(struct mkd_renderer *renderer)
659
655
  NULL,
660
656
  toc_finalize,
661
657
 
662
- "*-~",
663
658
  NULL
664
659
  };
665
660
 
@@ -672,7 +667,7 @@ init_toc_renderer(struct mkd_renderer *renderer)
672
667
  }
673
668
 
674
669
  void
675
- init_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
670
+ ups_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
676
671
  {
677
672
  static const struct mkd_renderer renderer_default = {
678
673
  rndr_blockcode,
@@ -703,7 +698,6 @@ init_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
703
698
  NULL,
704
699
  NULL,
705
700
 
706
- "*_~",
707
701
  NULL
708
702
  };
709
703
 
@@ -727,7 +721,7 @@ init_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
727
721
  }
728
722
 
729
723
  void
730
- free_renderer(struct mkd_renderer *renderer)
724
+ ups_free_renderer(struct mkd_renderer *renderer)
731
725
  {
732
726
  free(renderer->opaque);
733
727
  }
@@ -26,17 +26,16 @@ typedef enum {
26
26
  XHTML_EXPAND_TABS = (1 << 5),
27
27
  XHTML_SAFELINK = (1 << 7),
28
28
  XHTML_TOC = (1 << 8),
29
- XHTML_STRIKETHROUGH = (1 << 10),
30
29
  } render_mode;
31
30
 
32
- void
33
- init_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags);
31
+ extern void
32
+ ups_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags);
34
33
 
35
- void
36
- init_toc_renderer(struct mkd_renderer *renderer);
34
+ extern void
35
+ ups_toc_renderer(struct mkd_renderer *renderer);
37
36
 
38
- void
39
- free_renderer(struct mkd_renderer *renderer);
37
+ extern void
38
+ ups_free_renderer(struct mkd_renderer *renderer);
40
39
 
41
40
  #endif
42
41
 
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.6.0'
29
+ VERSION = '1.7.0'
30
30
 
31
31
  # Original Markdown formatted text.
32
32
  attr_reader :text
@@ -67,9 +67,6 @@ class Redcarpet
67
67
  # Enable PHP-Markdown fenced code extension
68
68
  attr_accessor :fenced_code
69
69
 
70
- # Backwards compatibility
71
- attr_accessor :fold_lines
72
-
73
70
  def initialize(text, *extensions)
74
71
  @text = text
75
72
  extensions.each { |e| send("#{e}=", true) }
@@ -82,10 +79,15 @@ Markdown = Redcarpet unless defined? Markdown
82
79
  # Creates a instance of Redcarpet with all markdown
83
80
  # extensions enabled, same behavior as in RDiscount
84
81
  class RedcarpetCompat < Redcarpet
82
+ # Backwards compatibility
83
+ attr_accessor :fold_lines
84
+ attr_accessor :no_tables
85
+ attr_accessor :fold_lines
86
+
85
87
  def initialize(text, *extensions)
86
88
  super(text, *extensions)
87
- tables = true
88
- strikethrough = true
89
+ self.tables = !self.no_tables
90
+ self.strikethrough = true
89
91
  end
90
92
  end
91
93
 
@@ -1,8 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'redcarpet'
3
- s.version = '1.6.0'
3
+ s.version = '1.7.0'
4
4
  s.summary = "Ruby bindings for libupskirt"
5
- s.date = '2011-04-12'
5
+ s.description = 'A fast and safe Markdown to (X)HTML parser'
6
+ s.date = '2011-04-15'
6
7
  s.email = 'vicent@github.com'
7
8
  s.homepage = 'http://github.com/tanoku/redcarpet'
8
9
  s.has_rdoc = true
@@ -30,6 +31,7 @@ Gem::Specification.new do |s|
30
31
  test/benchmark.txt
31
32
  test/markdown_test.rb
32
33
  test/redcarpet_test.rb
34
+ upskirt
33
35
  ]
34
36
  # = MANIFEST =
35
37
  s.test_files = ["test/markdown_test.rb", "test/redcarpet_test.rb"]
@@ -60,12 +60,12 @@ class MarkdownTest < Test::Unit::TestCase
60
60
  end
61
61
 
62
62
  def test_that_redcloth_attributes_are_supported
63
- markdown = Markdown.new('Hello World.')
63
+ markdown = RedcarpetCompat.new('Hello World.')
64
64
  assert_respond_to markdown, :fold_lines
65
65
  assert_respond_to markdown, :fold_lines=
66
66
  assert_not_equal true, markdown.fold_lines
67
67
 
68
- markdown = Markdown.new('Hello World.', :fold_lines)
68
+ markdown = RedcarpetCompat.new('Hello World.', :fold_lines)
69
69
  assert_equal true, markdown.fold_lines
70
70
  end
71
71
 
@@ -163,13 +163,13 @@ hello|sailor
163
163
  EOS
164
164
 
165
165
  assert Redcarpet.new(text).to_html !~ /<table/
166
- assert Redcarpet.new(text, :tables).to_html ~ /<table/
166
+ assert Redcarpet.new(text, :tables).to_html =~ /<table/
167
167
  end
168
168
 
169
169
  def test_strikethrough_flag_works
170
170
  text = "this is ~some~ striked ~~text~~"
171
171
  assert Redcarpet.new(text).to_html !~ /text-decoration:line-through;/
172
- assert Redcarpet.new(text, :strikethrough).to_html ~ /text-decoration:line-through;/
172
+ assert Redcarpet.new(text, :strikethrough).to_html =~ /text-decoration:line-through;/
173
173
  end
174
174
 
175
175
  def test_that_fenced_flag_works
@@ -183,7 +183,7 @@ This is some awesome code
183
183
  fenced
184
184
 
185
185
  assert Redcarpet.new(text).to_html !~ /<code/
186
- assert Redcarpet.new(text, :fenced_code).to_html ~ /<code/
186
+ assert Redcarpet.new(text, :fenced_code).to_html =~ /<code/
187
187
  end
188
188
 
189
189
  def test_that_compat_is_working
@@ -194,8 +194,9 @@ hello|sailor
194
194
 
195
195
  This is ~~striked through~~ test
196
196
  EOS
197
- assert rd.to_html ~ /<table/
198
- assert rd.to_html ~ /text-decoration:line-through;/
197
+ assert rd.tables
198
+ assert rd.to_html =~ /<table/
199
+ assert rd.to_html =~ /text-decoration:line-through;/
199
200
  end
200
201
 
201
202
  def test_that_headers_are_linkable
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: 15
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 1.6.0
10
+ version: 1.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Natacha Port\xC3\xA9"
@@ -16,11 +16,11 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-12 00:00:00 -07:00
19
+ date: 2011-04-15 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies: []
22
22
 
23
- description:
23
+ description: A fast and safe Markdown to (X)HTML parser
24
24
  email: vicent@github.com
25
25
  executables:
26
26
  - redcarpet