redcarpet 2.1.0 → 2.1.1

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.

@@ -9,12 +9,9 @@ case since version 2 -- it now has its own API, but retains the old name. Yes,
9
9
  that does mean that Redcarpet 2 is not backwards-compatible with the 1.X
10
10
  versions.
11
11
 
12
- Redcarpet is powered by the Sundown library, which can be found at
13
-
14
- https://www.github.com/tanoku/sundown
15
-
16
- You might want to find out more about Sundown to see what makes this Ruby
17
- library so awesome.
12
+ Redcarpet is powered by the [Sundown](https://www.github.com/tanoku/sundown)
13
+ library. You might want to find out more about Sundown to see what makes this
14
+ Ruby library so awesome.
18
15
 
19
16
  This library is written by people
20
17
  -------------------------------------------------------
@@ -102,7 +99,7 @@ Rendering with the `Markdown` object is done through `Markdown#render`.
102
99
  Unlike in the RedCloth API, the text to render is passed as an argument
103
100
  and not stored inside the `Markdown` instance, to encourage reusability.
104
101
 
105
- Markdown.render(text)
102
+ Markdown#render(text)
106
103
 
107
104
  Render a Markdown document with the attached renderer
108
105
 
@@ -253,7 +250,10 @@ The following instance methods may be implemented by the renderer:
253
250
  # document before or after the rendering process begins
254
251
  preprocess(full_document)
255
252
  postprocess(full_document)
256
-
253
+
254
+ You can look at
255
+ ["How to extend the Redcarpet 2 Markdown library?"](http://dev.af83.com/2012/02/27/howto-extend-the-redcarpet2-markdown-lib.html)
256
+ for some more explanations.
257
257
 
258
258
  Also, now our Pants are much smarter
259
259
  ------------------------------------
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- # Usage: redcarpet [--parse-<extension>...] [--render-<extension>] [<file>...]
2
+ # Usage: redcarpet [--parse-<extension>...] [--render-<extension>...] [--smarty] [<file>...]
3
3
  # Convert one or more Markdown files to HTML and write to standard output. With
4
4
  # no <file> or when <file> is '-', read Markdown source text from standard input.
5
5
  # With <extension>s, perform additional Markdown processing before writing output.
6
+ # With --smarty, use the SmartyHTML renderer
6
7
  if ARGV.include?('--help')
7
8
  File.read(__FILE__).split("\n").grep(/^# /).each do |line|
8
9
  puts line[2..-1]
@@ -17,6 +18,7 @@ require 'redcarpet'
17
18
 
18
19
  render_extensions = {}
19
20
  parse_extensions = {}
21
+ renderer = Redcarpet::Render::HTML
20
22
 
21
23
  ARGV.delete_if do |arg|
22
24
  if arg =~ /^--render-([\w-]+)$/
@@ -25,10 +27,12 @@ ARGV.delete_if do |arg|
25
27
  elsif arg =~ /^--parse-([\w-]+)$/
26
28
  arg = $1.gsub('-', '_')
27
29
  parse_extensions[arg.to_sym] = true
30
+ elsif arg == '--smarty'
31
+ renderer = Redcarpet::Render::SmartyHTML
28
32
  else
29
33
  false
30
34
  end
31
35
  end
32
36
 
33
- render = Redcarpet::Render::HTML.new(render_extensions)
37
+ render = renderer.new(render_extensions)
34
38
  STDOUT.write(Redcarpet::Markdown.new(render, parse_extensions).render(ARGF.read))
@@ -509,10 +509,18 @@ toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
509
509
 
510
510
  bufprintf(ob, "<a href=\"#toc_%d\">", options->toc_data.header_count++);
511
511
  if (text)
512
- bufput(ob, text->data, text->size);
512
+ escape_html(ob, text->data, text->size);
513
513
  BUFPUTSL(ob, "</a>\n");
514
514
  }
515
515
 
516
+ static int
517
+ toc_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
518
+ {
519
+ if (content && content->size)
520
+ bufput(ob, content->data, content->size);
521
+ return 1;
522
+ }
523
+
516
524
  static void
517
525
  toc_finalize(struct buf *ob, void *opaque)
518
526
  {
@@ -546,7 +554,7 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio
546
554
  rndr_emphasis,
547
555
  NULL,
548
556
  NULL,
549
- NULL,
557
+ toc_link,
550
558
  NULL,
551
559
  rndr_triple_emphasis,
552
560
  rndr_strikethrough,
@@ -694,6 +694,8 @@ char_escape(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t offs
694
694
  rndr->cb.normal_text(ob, &work, rndr->opaque);
695
695
  }
696
696
  else bufputc(ob, data[1]);
697
+ } else if (size == 1) {
698
+ bufputc(ob, data[0]);
697
699
  }
698
700
 
699
701
  return 2;
@@ -886,7 +888,8 @@ char_link(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t offset
886
888
  /* looking for link end: ' " ) */
887
889
  while (i < size) {
888
890
  if (data[i] == '\\') i += 2;
889
- else if (data[i] == ')' || data[i] == '\'' || data[i] == '"') break;
891
+ else if (data[i] == ')') break;
892
+ else if (i >= 1 && _isspace(data[i-1]) && (data[i] == '\'' || data[i] == '"')) break;
890
893
  else i++;
891
894
  }
892
895
 
@@ -1967,10 +1970,13 @@ parse_table_header(
1967
1970
 
1968
1971
  header_end = i;
1969
1972
 
1973
+ while (header_end > 0 && _isspace(data[header_end - 1]))
1974
+ header_end--;
1975
+
1970
1976
  if (data[0] == '|')
1971
1977
  pipes--;
1972
1978
 
1973
- if (i > 2 && data[i - 1] == '|')
1979
+ if (header_end && data[header_end - 1] == '|')
1974
1980
  pipes--;
1975
1981
 
1976
1982
  *columns = pipes + 1;
@@ -2244,8 +2250,8 @@ is_ref(const uint8_t *data, size_t beg, size_t end, size_t *last, struct link_re
2244
2250
  line_end = title_end;
2245
2251
  title_end = i; } }
2246
2252
 
2247
- if (!line_end)
2248
- return 0; /* garbage after the link */
2253
+ if (!line_end || link_end == link_offset)
2254
+ return 0; /* garbage after the link empty link */
2249
2255
 
2250
2256
  /* a valid ref has been found, filling-in return structures */
2251
2257
  if (last)
@@ -2255,6 +2261,8 @@ is_ref(const uint8_t *data, size_t beg, size_t end, size_t *last, struct link_re
2255
2261
  struct link_ref *ref;
2256
2262
 
2257
2263
  ref = add_link_ref(refs, data + id_offset, id_end - id_offset);
2264
+ if (!ref)
2265
+ return 0;
2258
2266
 
2259
2267
  ref->link = bufnew(link_end - link_offset);
2260
2268
  bufput(ref->link, data + link_offset, link_end - link_offset);
@@ -104,6 +104,8 @@ static VALUE rb_redcarpet_md_render(VALUE self, VALUE text)
104
104
 
105
105
  if (rb_respond_to(rb_rndr, rb_intern("preprocess")))
106
106
  text = rb_funcall(rb_rndr, rb_intern("preprocess"), 1, text);
107
+ if (NIL_P(text))
108
+ return Qnil;
107
109
 
108
110
  #ifdef HAVE_RUBY_ENCODING_H
109
111
  {
@@ -1,7 +1,7 @@
1
1
  require 'redcarpet.so'
2
2
 
3
3
  module Redcarpet
4
- VERSION = '2.1.0'
4
+ VERSION = '2.1.1'
5
5
 
6
6
  class Markdown
7
7
  attr_reader :renderer
@@ -86,7 +86,7 @@ class RedcarpetCompat
86
86
  :space_header => :space_after_headers,
87
87
  :strikethrough => :strikethrough,
88
88
  :tables => :tables,
89
- :with_toc_data => :generate_toc,
89
+ :generate_toc => :with_toc_data,
90
90
  :xhtml => :xhtml,
91
91
  # old names with no new mapping
92
92
  :gh_blockcode => nil,
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'redcarpet'
4
- s.version = '2.1.0'
4
+ s.version = '2.1.1'
5
5
  s.summary = "Markdown that smells nice"
6
6
  s.description = 'A fast, safe and extensible Markdown to (X)HTML parser'
7
7
  s.date = '2011-09-14'
@@ -61,6 +61,7 @@ class HTMLRenderTest < Test::Unit::TestCase
61
61
  :no_links => Redcarpet::Render::HTML.new(:no_links => true),
62
62
  :safe_links => Redcarpet::Render::HTML.new(:safe_links_only => true),
63
63
  :escape_html => Redcarpet::Render::HTML.new(:escape_html => true),
64
+ :hard_wrap => Redcarpet::Render::HTML.new(:hard_wrap => true),
64
65
  }
65
66
  end
66
67
 
@@ -114,6 +115,18 @@ EOE
114
115
  rd = render_with(@rndr[:safe_links], "[IRC](irc://chat.freenode.org/#freenode)")
115
116
  html_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>\n", rd
116
117
  end
118
+
119
+ def test_that_hard_wrap_works
120
+ rd = render_with(@rndr[:hard_wrap], <<EOE)
121
+ Hello world,
122
+ this is just a simple test
123
+
124
+ With hard wraps
125
+ and other *things*.
126
+ EOE
127
+
128
+ assert rd =~ /<br>/
129
+ end
117
130
  end
118
131
 
119
132
  class MarkdownTest < Test::Unit::TestCase
@@ -328,6 +341,18 @@ class CustomRenderTest < Test::Unit::TestCase
328
341
  html_equal "<p>This is <em class=\"cool\">just</em> a test</p>",
329
342
  md.render("This is *just* a test")
330
343
  end
344
+
345
+ class NilPreprocessRenderer < Redcarpet::Render::HTML
346
+ def preprocess(fulldoc)
347
+ nil
348
+ end
349
+ end
350
+
351
+ def test_preprocess_returning_nil
352
+ md = Redcarpet::Markdown.new(NilPreprocessRenderer)
353
+ assert_equal(nil,md.render("Anything"))
354
+ end
355
+
331
356
  end
332
357
 
333
358
  class RedcarpetCompatTest < Test::Unit::TestCase
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: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 0
10
- version: 2.1.0
9
+ - 1
10
+ version: 2.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Natacha Port\xC3\xA9"