[DRE-commits] [ruby-redcarpet] 01/03: Imported Upstream version 3.1.2

Youhei SASAKI uwabami-guest at moszumanska.debian.org
Thu May 29 15:55:51 UTC 2014


This is an automated email from the git hooks/post-receive script.

uwabami-guest pushed a commit to annotated tag debian/3.1.2-1
in repository ruby-redcarpet.

commit 9a318e22a7165f9d63a8a4af6e8f72f54dd72bbd
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date:   Fri May 30 00:52:16 2014 +0900

    Imported Upstream version 3.1.2
---
 README.markdown               |  48 +++++++++++++++++++++---------------------
 checksums.yaml.gz             | Bin 269 -> 266 bytes
 ext/redcarpet/buffer.c        |   2 +-
 ext/redcarpet/buffer.h        |   2 +-
 ext/redcarpet/html.c          |  10 ++++-----
 ext/redcarpet/markdown.c      |  24 ++++++++++++++-------
 ext/redcarpet/markdown.h      |   4 ++--
 ext/redcarpet/rc_render.c     |   4 ++--
 lib/redcarpet.rb              |   2 +-
 lib/redcarpet/render_strip.rb |   7 +++++-
 metadata.yml                  |   4 ++--
 redcarpet.gemspec             |   4 ++--
 test/html_toc_render_test.rb  |  14 ------------
 test/markdown_test.rb         |   5 +++++
 test/stripdown_render_test.rb |  13 +++++++++++-
 15 files changed, 79 insertions(+), 64 deletions(-)

diff --git a/README.markdown b/README.markdown
index 2af7e18..7351d0c 100644
--- a/README.markdown
+++ b/README.markdown
@@ -32,6 +32,7 @@ The Redcarpet source is available at GitHub:
 
     $ git clone git://github.com/vmg/redcarpet.git
 
+
 And it's like *really* simple to use
 ------------------------------------
 
@@ -45,14 +46,23 @@ required settings, and reused between parses.
 
 ~~~~~ ruby
 # Initializes a Markdown parser
-Redcarpet::Markdown.new(renderer, extensions = {})
+markdown = Redcarpet::Markdown.new(renderer, extensions = {})
 ~~~~~
 
-
 Here, the `renderer` variable refers to a renderer object, inheriting
 from `Redcarpet::Render::Base`. If the given object has not been
 instantiated, the library will do it with default arguments.
 
+Rendering with the `Markdown` object is done through `Markdown#render`.
+Unlike in the RedCloth API, the text to render is passed as an argument
+and not stored inside the `Markdown` instance, to encourage reusability.
+Example:
+
+~~~~~ ruby
+markdown.render("This is *bongos*, indeed.")
+# => "<p>This is <em>bongos</em>, indeed.</p>"
+~~~~~
+
 You can also specify a hash containing the Markdown extensions which the
 parser will identify. The following extensions are accepted:
 
@@ -108,20 +118,9 @@ within the document (e.g. `[^1]: This is a footnote.`).
 
 Example:
 
-~~~~~ ruby
-markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
-~~~~~
-
-Rendering with the `Markdown` object is done through `Markdown#render`.
-Unlike in the RedCloth API, the text to render is passed as an argument
-and not stored inside the `Markdown` instance, to encourage reusability.
-Example:
-
-~~~~~ ruby
-markdown.render("This is *bongos*, indeed.")
-# => "<p>This is <em>bongos</em>, indeed</p>"
-~~~~~
-
+~~~ruby
+markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
+ ~~~~~
 
 Darling, I packed you a couple renderers for lunch
 --------------------------------------------------
@@ -169,7 +168,7 @@ Markdown document had newlines (by default, Markdown ignores these newlines).
 Example:
 
 ~~~~~ ruby
-renderer = Redcarpet::Render::HTML.new(:no_links => true, :hard_wrap => true)
+renderer = Redcarpet::Render::HTML.new(no_links: true, hard_wrap: true)
 ~~~~~
 
 
@@ -196,11 +195,11 @@ built-in renderers, `HTML` and `XHTML` may be extended as such:
 # create a custom renderer that allows highlighting of code blocks
 class HTMLwithPygments < Redcarpet::Render::HTML
   def block_code(code, language)
-    Pygments.highlight(code, :lexer => language)
+    Pygments.highlight(code, lexer: language)
   end
 end
 
-markdown = Redcarpet::Markdown.new(HTMLwithPygments, :fenced_code_blocks => true)
+markdown = Redcarpet::Markdown.new(HTMLwithPygments, fenced_code_blocks: true)
 ~~~~~
 
 But new renderers can also be created from scratch (see `lib/redcarpet/render_man.rb` for
@@ -235,7 +234,7 @@ end
 * block_html(raw_html)
 * footnotes(content)
 * footnote_def(content, number)
-* header(text, header_level, anchor)
+* header(text, header_level)
 * hrule()
 * list(contents, list_type)
 * list_item(text, list_type)
@@ -266,6 +265,11 @@ be copied verbatim:
 * quote(text)
 * footnote_ref(number)
 
+**Note**: When overriding a renderer's method, be sure to return a HTML
+element with a level that match the level of that method (e.g. return a block
+element when overriding a block-level callback). Otherwise, the output may
+be unexpected.
+
 ### Low level rendering
 
 * entity(text)
@@ -360,10 +364,6 @@ that's a maintenance nightmare and won't work.
 On a related topic: if your Markdown gem has a `lib/markdown.rb` file that
 monkeypatches the Markdown class, you're a terrible human being. Just saying.
 
-Testing
--------
-Tests run a lot faster without `bundle exec` :)
-
 Boring legal stuff
 ------------------
 
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
index 1323975..47a21a8 100644
Binary files a/checksums.yaml.gz and b/checksums.yaml.gz differ
diff --git a/ext/redcarpet/buffer.c b/ext/redcarpet/buffer.c
index 6a85f31..1be1f4b 100644
--- a/ext/redcarpet/buffer.c
+++ b/ext/redcarpet/buffer.c
@@ -94,7 +94,7 @@ bufnew(size_t unit)
 
 /* bufnullterm: NULL-termination of the string array */
 const char *
-bufcstr(const struct buf *buf)
+bufcstr(struct buf *buf)
 {
 	assert(buf && buf->unit);
 
diff --git a/ext/redcarpet/buffer.h b/ext/redcarpet/buffer.h
index 581a71c..3d5e82f 100644
--- a/ext/redcarpet/buffer.h
+++ b/ext/redcarpet/buffer.h
@@ -55,7 +55,7 @@ int bufgrow(struct buf *, size_t);
 struct buf *bufnew(size_t) __attribute__ ((malloc));
 
 /* bufnullterm: NUL-termination of the string array (making a C-string) */
-const char *bufcstr(const struct buf *);
+const char *bufcstr(struct buf *);
 
 /* bufprefix: compare the beginning of a buffer with a string */
 int bufprefix(const struct buf *buf, const char *prefix);
diff --git a/ext/redcarpet/html.c b/ext/redcarpet/html.c
index d5c92e2..f4e3a06 100755
--- a/ext/redcarpet/html.c
+++ b/ext/redcarpet/html.c
@@ -265,7 +265,7 @@ rndr_linebreak(struct buf *ob, void *opaque)
 	return 1;
 }
 
-char *header_anchor(const struct buf *text)
+char *header_anchor(struct buf *text)
 {
 	VALUE str = rb_str_new2(bufcstr(text));
 	VALUE space_regex = rb_reg_new(" +", 2 /* length */, 0);
@@ -279,7 +279,7 @@ char *header_anchor(const struct buf *text)
 }
 
 static void
-rndr_header(struct buf *ob, const struct buf *text, int level, char *anchor, void *opaque)
+rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
 {
 	struct html_renderopt *options = opaque;
 
@@ -287,7 +287,7 @@ rndr_header(struct buf *ob, const struct buf *text, int level, char *anchor, voi
 		bufputc(ob, '\n');
 
 	if ((options->flags & HTML_TOC) && (level <= options->toc_data.nesting_level))
-		bufprintf(ob, "<h%d id=\"%s\">", level, anchor);
+		bufprintf(ob, "<h%d id=\"%s\">", level, header_anchor(text));
 	else
 		bufprintf(ob, "<h%d>", level);
 
@@ -607,7 +607,7 @@ rndr_footnote_ref(struct buf *ob, unsigned int num, void *opaque)
 }
 
 static void
-toc_header(struct buf *ob, const struct buf *text, int level, char *anchor, void *opaque)
+toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
 {
 	struct html_renderopt *options = opaque;
 
@@ -635,7 +635,7 @@ toc_header(struct buf *ob, const struct buf *text, int level, char *anchor, void
 			BUFPUTSL(ob,"</li>\n<li>\n");
 		}
 
-		bufprintf(ob, "<a href=\"#%s\">", anchor);
+		bufprintf(ob, "<a href=\"#%s\">", header_anchor(text));
 		if (text) escape_html(ob, text->data, text->size);
 		BUFPUTSL(ob, "</a>\n");
 	}
diff --git a/ext/redcarpet/markdown.c b/ext/redcarpet/markdown.c
index b2b8ca9..c7b3956 100644
--- a/ext/redcarpet/markdown.c
+++ b/ext/redcarpet/markdown.c
@@ -333,6 +333,14 @@ free_footnote_list(struct footnote_list *list, int free_refs)
 	}
 }
 
+/*
+ Wrap isalnum so that characters outside of the ASCII range don't count.
+ */
+static inline int
+_isalnum(int c)
+{
+	return isalnum(c) && c < 0x7f;
+}
 
 /*
  * Check whether a char is a Markdown space.
@@ -364,7 +372,7 @@ is_mail_autolink(uint8_t *data, size_t size)
 
 	/* address is assumed to be: [- at ._a-zA-Z0-9]+ with exactly one '@' */
 	for (i = 0; i < size; ++i) {
-		if (isalnum(data[i]))
+		if (_isalnum(data[i]))
 			continue;
 
 		switch (data[i]) {
@@ -400,14 +408,14 @@ tag_length(uint8_t *data, size_t size, enum mkd_autolink *autolink)
 	if (data[0] != '<') return 0;
 	i = (data[1] == '/') ? 2 : 1;
 
-	if (!isalnum(data[i]))
+	if (!_isalnum(data[i]))
 		return 0;
 
 	/* scheme test */
 	*autolink = MKDA_NOT_AUTOLINK;
 
 	/* try to find the beginning of an URI */
-	while (i < size && (isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-'))
+	while (i < size && (_isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-'))
 		i++;
 
 	if (i > 1 && data[i] == '@') {
@@ -600,7 +608,7 @@ parse_emph1(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t size
 		if (data[i] == c && !_isspace(data[i - 1])) {
 
 			if (rndr->ext_flags & MKDEXT_NO_INTRA_EMPHASIS) {
-				if (i + i < size && isalnum(data[i + 1]))
+				if (i + i < size && _isalnum(data[i + 1]))
 					continue;
 			}
 
@@ -702,7 +710,7 @@ char_emphasis(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t of
 	size_t ret;
 
 	if (rndr->ext_flags & MKDEXT_NO_INTRA_EMPHASIS) {
-		if (offset > 0 && !_isspace(data[-1]) && data[-1] != '>' && data[-1] != '(')
+		if (offset > 0 && _isalnum(data[-1]))
 			return 0;
 	}
 
@@ -868,7 +876,7 @@ char_entity(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t offs
 	if (end < size && data[end] == '#')
 		end++;
 
-	while (end < size && isalnum(data[end]))
+	while (end < size && _isalnum(data[end]))
 		end++;
 
 	if (end < size && data[end] == ';')
@@ -1712,7 +1720,7 @@ parse_paragraph(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t
 		parse_inline(header_work, rndr, work.data, work.size);
 
 		if (rndr->cb.header)
-			rndr->cb.header(ob, header_work, (int)level, header_anchor(header_work), rndr->opaque);
+			rndr->cb.header(ob, header_work, (int)level, rndr->opaque);
 
 		rndr_popbuf(rndr, BUFFER_SPAN);
 	}
@@ -1992,7 +2000,7 @@ parse_atxheader(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t
 		parse_inline(work, rndr, data + i, end - i);
 
 		if (rndr->cb.header)
-			rndr->cb.header(ob, work, (int)level, header_anchor(work), rndr->opaque);
+			rndr->cb.header(ob, work, (int)level, rndr->opaque);
 
 		rndr_popbuf(rndr, BUFFER_SPAN);
 	}
diff --git a/ext/redcarpet/markdown.h b/ext/redcarpet/markdown.h
index f577396..1748d3a 100644
--- a/ext/redcarpet/markdown.h
+++ b/ext/redcarpet/markdown.h
@@ -67,7 +67,7 @@ struct sd_callbacks {
 	void (*blockcode)(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque);
 	void (*blockquote)(struct buf *ob, const struct buf *text, void *opaque);
 	void (*blockhtml)(struct buf *ob,const  struct buf *text, void *opaque);
-	void (*header)(struct buf *ob, const struct buf *text, int level, char *anchor, void *opaque);
+	void (*header)(struct buf *ob, const struct buf *text, int level, void *opaque);
 	void (*hrule)(struct buf *ob, void *opaque);
 	void (*list)(struct buf *ob, const struct buf *text, int flags, void *opaque);
 	void (*listitem)(struct buf *ob, const struct buf *text, int flags, void *opaque);
@@ -105,7 +105,7 @@ struct sd_callbacks {
 };
 
 /* header methods used internally in Redcarpet */
-char* header_anchor(const struct buf *text);
+char* header_anchor(struct buf *text);
 
 struct sd_markdown;
 
diff --git a/ext/redcarpet/rc_render.c b/ext/redcarpet/rc_render.c
index ad97829..cb9e88a 100644
--- a/ext/redcarpet/rc_render.c
+++ b/ext/redcarpet/rc_render.c
@@ -61,9 +61,9 @@ rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
 }
 
 static void
-rndr_header(struct buf *ob, const struct buf *text, int level, char *anchor, void *opaque)
+rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
 {
-	BLOCK_CALLBACK("header", 3, buf2str(text), INT2FIX(level), rb_str_new2(anchor));
+	BLOCK_CALLBACK("header", 2, buf2str(text), INT2FIX(level));
 }
 
 static void
diff --git a/lib/redcarpet.rb b/lib/redcarpet.rb
index c2df8b8..ae5b2f2 100644
--- a/lib/redcarpet.rb
+++ b/lib/redcarpet.rb
@@ -1,7 +1,7 @@
 require 'redcarpet.so'
 
 module Redcarpet
-  VERSION = '3.1.1'
+  VERSION = '3.1.2'
 
   class Markdown
     attr_reader :renderer
diff --git a/lib/redcarpet/render_strip.rb b/lib/redcarpet/render_strip.rb
index a2e7933..b3f6b01 100644
--- a/lib/redcarpet/render_strip.rb
+++ b/lib/redcarpet/render_strip.rb
@@ -31,11 +31,16 @@ module Redcarpet
         content
       end
 
+      def image(link, title, content)
+        content &&= content + " "
+        "#{content}#{link}"
+      end
+
       def paragraph(text)
         text + "\n"
       end
 
-      def header(text, header_level, anchor)
+      def header(text, header_level)
         text + "\n"
       end
     end
diff --git a/metadata.yml b/metadata.yml
index 34c0613..da0c6f3 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,7 +1,7 @@
 --- !ruby/object:Gem::Specification
 name: redcarpet
 version: !ruby/object:Gem::Version
-  version: 3.1.1
+  version: 3.1.2
 platform: ruby
 authors:
 - Natacha Porté
@@ -9,7 +9,7 @@ authors:
 autorequire: 
 bindir: bin
 cert_chain: []
-date: 2014-02-17 00:00:00.000000000 Z
+date: 2014-05-10 00:00:00.000000000 Z
 dependencies:
 - !ruby/object:Gem::Dependency
   name: nokogiri
diff --git a/redcarpet.gemspec b/redcarpet.gemspec
index e3cbaa2..532044b 100644
--- a/redcarpet.gemspec
+++ b/redcarpet.gemspec
@@ -1,10 +1,10 @@
 # encoding: utf-8
 Gem::Specification.new do |s|
   s.name = 'redcarpet'
-  s.version = '3.1.1'
+  s.version = '3.1.2'
   s.summary = "Markdown that smells nice"
   s.description = 'A fast, safe and extensible Markdown to (X)HTML parser'
-  s.date = '2014-02-17'
+  s.date = '2014-05-10'
   s.email = 'vicent at github.com'
   s.homepage = 'http://github.com/vmg/redcarpet'
   s.authors = ["Natacha Porté", "Vicent Martí"]
diff --git a/test/html_toc_render_test.rb b/test/html_toc_render_test.rb
index 246c225..6188ab0 100644
--- a/test/html_toc_render_test.rb
+++ b/test/html_toc_render_test.rb
@@ -2,12 +2,6 @@
 require 'test_helper'
 
 class HTMLTOCRenderTest < Test::Unit::TestCase
-  class CustomTocRender < Redcarpet::Render::HTML_TOC
-    def header(text, level, anchor)
-      "<h#{level} id=\"foo-bar-#{anchor}\">#{text}</h1>"
-    end
-  end
-
   def setup
     @render = Redcarpet::Render::HTML_TOC
     @markdown = "# A title \n## A __nice__ subtitle\n## Another one \n### A sub-sub-title"
@@ -44,12 +38,4 @@ class HTMLTOCRenderTest < Test::Unit::TestCase
     assert_match /another-one/, output
     assert_match /a-sub-sub-title/, output
   end
-
-  def test_header_callback
-    renderer = Redcarpet::Markdown.new(CustomTocRender)
-    output = renderer.render(@markdown)
-
-    assert_match /A title/, output
-    assert_match /foo-bar-a-title/, output
-  end
 end
diff --git a/test/markdown_test.rb b/test/markdown_test.rb
index 5f1e1b6..6dfbbda 100644
--- a/test/markdown_test.rb
+++ b/test/markdown_test.rb
@@ -269,10 +269,15 @@ text
     assert render_with({:no_intra_emphasis => true}, "this fails: hello_world_") !~ /<em>/
     assert render_with({:no_intra_emphasis => true}, "this also fails: hello_world_#bye") !~ /<em>/
     assert render_with({:no_intra_emphasis => true}, "this works: hello_my_world") !~ /<em>/
+    assert render_with({:no_intra_emphasis => true}, "句中**粗體**測試") =~ /<strong>/
 
     markdown = "This is (**bold**) and this_is_not_italic!"
     html = "<p>This is (<strong>bold</strong>) and this_is_not_italic!</p>\n"
     assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
+
+    markdown = "This is \"**bold**\""
+    html = "<p>This is "<strong>bold</strong>"</p>\n"
+    assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
   end
 
   def test_ordered_lists_with_lax_spacing
diff --git a/test/stripdown_render_test.rb b/test/stripdown_render_test.rb
index a8f2721..b06e354 100644
--- a/test/stripdown_render_test.rb
+++ b/test/stripdown_render_test.rb
@@ -23,9 +23,20 @@ Hello world! Please visit [this site](https://github.com/).
 
     class Foo
     end
+
+Look at this ![picture](http://example.org/picture.png)
+And this: ![](http://example.org/image.jpg)
 Markdown
+    plaintext = <<-Plaintext
+Foo bar
+Hello world! Please visit this site.
+class Foo
+end
+Look at this picture http://example.org/picture.png
+And this: http://example.org/image.jpg
+Plaintext
 
     html = @markdown.render(markdown)
-    html_equal "Foo bar\nHello world! Please visit this site.\nclass Foo\nend\n", html
+    html_equal plaintext, html
   end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-redcarpet.git



More information about the Pkg-ruby-extras-commits mailing list