redcarpet 3.1.1 → 3.1.2
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.
- checksums.yaml +4 -4
- data/README.markdown +24 -24
- data/ext/redcarpet/buffer.c +1 -1
- data/ext/redcarpet/buffer.h +1 -1
- data/ext/redcarpet/html.c +5 -5
- data/ext/redcarpet/markdown.c +16 -8
- data/ext/redcarpet/markdown.h +2 -2
- data/ext/redcarpet/rc_render.c +2 -2
- data/lib/redcarpet.rb +1 -1
- data/lib/redcarpet/render_strip.rb +6 -1
- data/redcarpet.gemspec +2 -2
- data/test/html_toc_render_test.rb +0 -14
- data/test/markdown_test.rb +5 -0
- data/test/stripdown_render_test.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 794753edf10a2310e7bcb5cdef1cf39f69c20a0f
|
4
|
+
data.tar.gz: 9b2baf785cca27311b402c760b8a3d453acee40e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddd0407e934865e45d5c2914f1b396054c16db71b854d77db320905c92b343b41d8ad23fed0db1cd591cfbb10d27fc1ba0a559c6985fe3e5c4ef3ffe072458cb
|
7
|
+
data.tar.gz: 701d3101a85b4e716ae0734dca3cd77ae8d4636540ffc05eaad2cfe7262aebcb18c0fac7b4642341e83c28142a9073408c94535a5c9aae8ed9221a671bad0df5
|
data/README.markdown
CHANGED
@@ -32,6 +32,7 @@ The Redcarpet source is available at GitHub:
|
|
32
32
|
|
33
33
|
$ git clone git://github.com/vmg/redcarpet.git
|
34
34
|
|
35
|
+
|
35
36
|
And it's like *really* simple to use
|
36
37
|
------------------------------------
|
37
38
|
|
@@ -45,14 +46,23 @@ required settings, and reused between parses.
|
|
45
46
|
|
46
47
|
~~~~~ ruby
|
47
48
|
# Initializes a Markdown parser
|
48
|
-
Redcarpet::Markdown.new(renderer, extensions = {})
|
49
|
+
markdown = Redcarpet::Markdown.new(renderer, extensions = {})
|
49
50
|
~~~~~
|
50
51
|
|
51
|
-
|
52
52
|
Here, the `renderer` variable refers to a renderer object, inheriting
|
53
53
|
from `Redcarpet::Render::Base`. If the given object has not been
|
54
54
|
instantiated, the library will do it with default arguments.
|
55
55
|
|
56
|
+
Rendering with the `Markdown` object is done through `Markdown#render`.
|
57
|
+
Unlike in the RedCloth API, the text to render is passed as an argument
|
58
|
+
and not stored inside the `Markdown` instance, to encourage reusability.
|
59
|
+
Example:
|
60
|
+
|
61
|
+
~~~~~ ruby
|
62
|
+
markdown.render("This is *bongos*, indeed.")
|
63
|
+
# => "<p>This is <em>bongos</em>, indeed.</p>"
|
64
|
+
~~~~~
|
65
|
+
|
56
66
|
You can also specify a hash containing the Markdown extensions which the
|
57
67
|
parser will identify. The following extensions are accepted:
|
58
68
|
|
@@ -108,20 +118,9 @@ within the document (e.g. `[^1]: This is a footnote.`).
|
|
108
118
|
|
109
119
|
Example:
|
110
120
|
|
111
|
-
|
112
|
-
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :
|
113
|
-
~~~~~
|
114
|
-
|
115
|
-
Rendering with the `Markdown` object is done through `Markdown#render`.
|
116
|
-
Unlike in the RedCloth API, the text to render is passed as an argument
|
117
|
-
and not stored inside the `Markdown` instance, to encourage reusability.
|
118
|
-
Example:
|
119
|
-
|
120
|
-
~~~~~ ruby
|
121
|
-
markdown.render("This is *bongos*, indeed.")
|
122
|
-
# => "<p>This is <em>bongos</em>, indeed</p>"
|
123
|
-
~~~~~
|
124
|
-
|
121
|
+
~~~ruby
|
122
|
+
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
|
123
|
+
~~~~~
|
125
124
|
|
126
125
|
Darling, I packed you a couple renderers for lunch
|
127
126
|
--------------------------------------------------
|
@@ -169,7 +168,7 @@ Markdown document had newlines (by default, Markdown ignores these newlines).
|
|
169
168
|
Example:
|
170
169
|
|
171
170
|
~~~~~ ruby
|
172
|
-
renderer = Redcarpet::Render::HTML.new(:
|
171
|
+
renderer = Redcarpet::Render::HTML.new(no_links: true, hard_wrap: true)
|
173
172
|
~~~~~
|
174
173
|
|
175
174
|
|
@@ -196,11 +195,11 @@ built-in renderers, `HTML` and `XHTML` may be extended as such:
|
|
196
195
|
# create a custom renderer that allows highlighting of code blocks
|
197
196
|
class HTMLwithPygments < Redcarpet::Render::HTML
|
198
197
|
def block_code(code, language)
|
199
|
-
Pygments.highlight(code, :
|
198
|
+
Pygments.highlight(code, lexer: language)
|
200
199
|
end
|
201
200
|
end
|
202
201
|
|
203
|
-
markdown = Redcarpet::Markdown.new(HTMLwithPygments, :
|
202
|
+
markdown = Redcarpet::Markdown.new(HTMLwithPygments, fenced_code_blocks: true)
|
204
203
|
~~~~~
|
205
204
|
|
206
205
|
But new renderers can also be created from scratch (see `lib/redcarpet/render_man.rb` for
|
@@ -235,7 +234,7 @@ end
|
|
235
234
|
* block_html(raw_html)
|
236
235
|
* footnotes(content)
|
237
236
|
* footnote_def(content, number)
|
238
|
-
* header(text, header_level
|
237
|
+
* header(text, header_level)
|
239
238
|
* hrule()
|
240
239
|
* list(contents, list_type)
|
241
240
|
* list_item(text, list_type)
|
@@ -266,6 +265,11 @@ be copied verbatim:
|
|
266
265
|
* quote(text)
|
267
266
|
* footnote_ref(number)
|
268
267
|
|
268
|
+
**Note**: When overriding a renderer's method, be sure to return a HTML
|
269
|
+
element with a level that match the level of that method (e.g. return a block
|
270
|
+
element when overriding a block-level callback). Otherwise, the output may
|
271
|
+
be unexpected.
|
272
|
+
|
269
273
|
### Low level rendering
|
270
274
|
|
271
275
|
* entity(text)
|
@@ -360,10 +364,6 @@ that's a maintenance nightmare and won't work.
|
|
360
364
|
On a related topic: if your Markdown gem has a `lib/markdown.rb` file that
|
361
365
|
monkeypatches the Markdown class, you're a terrible human being. Just saying.
|
362
366
|
|
363
|
-
Testing
|
364
|
-
-------
|
365
|
-
Tests run a lot faster without `bundle exec` :)
|
366
|
-
|
367
367
|
Boring legal stuff
|
368
368
|
------------------
|
369
369
|
|
data/ext/redcarpet/buffer.c
CHANGED
data/ext/redcarpet/buffer.h
CHANGED
@@ -55,7 +55,7 @@ int bufgrow(struct buf *, size_t);
|
|
55
55
|
struct buf *bufnew(size_t) __attribute__ ((malloc));
|
56
56
|
|
57
57
|
/* bufnullterm: NUL-termination of the string array (making a C-string) */
|
58
|
-
const char *bufcstr(
|
58
|
+
const char *bufcstr(struct buf *);
|
59
59
|
|
60
60
|
/* bufprefix: compare the beginning of a buffer with a string */
|
61
61
|
int bufprefix(const struct buf *buf, const char *prefix);
|
data/ext/redcarpet/html.c
CHANGED
@@ -265,7 +265,7 @@ rndr_linebreak(struct buf *ob, void *opaque)
|
|
265
265
|
return 1;
|
266
266
|
}
|
267
267
|
|
268
|
-
char *header_anchor(
|
268
|
+
char *header_anchor(struct buf *text)
|
269
269
|
{
|
270
270
|
VALUE str = rb_str_new2(bufcstr(text));
|
271
271
|
VALUE space_regex = rb_reg_new(" +", 2 /* length */, 0);
|
@@ -279,7 +279,7 @@ char *header_anchor(const struct buf *text)
|
|
279
279
|
}
|
280
280
|
|
281
281
|
static void
|
282
|
-
rndr_header(struct buf *ob, const struct buf *text, int level,
|
282
|
+
rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
283
283
|
{
|
284
284
|
struct html_renderopt *options = opaque;
|
285
285
|
|
@@ -287,7 +287,7 @@ rndr_header(struct buf *ob, const struct buf *text, int level, char *anchor, voi
|
|
287
287
|
bufputc(ob, '\n');
|
288
288
|
|
289
289
|
if ((options->flags & HTML_TOC) && (level <= options->toc_data.nesting_level))
|
290
|
-
bufprintf(ob, "<h%d id=\"%s\">", level,
|
290
|
+
bufprintf(ob, "<h%d id=\"%s\">", level, header_anchor(text));
|
291
291
|
else
|
292
292
|
bufprintf(ob, "<h%d>", level);
|
293
293
|
|
@@ -607,7 +607,7 @@ rndr_footnote_ref(struct buf *ob, unsigned int num, void *opaque)
|
|
607
607
|
}
|
608
608
|
|
609
609
|
static void
|
610
|
-
toc_header(struct buf *ob, const struct buf *text, int level,
|
610
|
+
toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
611
611
|
{
|
612
612
|
struct html_renderopt *options = opaque;
|
613
613
|
|
@@ -635,7 +635,7 @@ toc_header(struct buf *ob, const struct buf *text, int level, char *anchor, void
|
|
635
635
|
BUFPUTSL(ob,"</li>\n<li>\n");
|
636
636
|
}
|
637
637
|
|
638
|
-
bufprintf(ob, "<a href=\"#%s\">",
|
638
|
+
bufprintf(ob, "<a href=\"#%s\">", header_anchor(text));
|
639
639
|
if (text) escape_html(ob, text->data, text->size);
|
640
640
|
BUFPUTSL(ob, "</a>\n");
|
641
641
|
}
|
data/ext/redcarpet/markdown.c
CHANGED
@@ -333,6 +333,14 @@ free_footnote_list(struct footnote_list *list, int free_refs)
|
|
333
333
|
}
|
334
334
|
}
|
335
335
|
|
336
|
+
/*
|
337
|
+
Wrap isalnum so that characters outside of the ASCII range don't count.
|
338
|
+
*/
|
339
|
+
static inline int
|
340
|
+
_isalnum(int c)
|
341
|
+
{
|
342
|
+
return isalnum(c) && c < 0x7f;
|
343
|
+
}
|
336
344
|
|
337
345
|
/*
|
338
346
|
* Check whether a char is a Markdown space.
|
@@ -364,7 +372,7 @@ is_mail_autolink(uint8_t *data, size_t size)
|
|
364
372
|
|
365
373
|
/* address is assumed to be: [-@._a-zA-Z0-9]+ with exactly one '@' */
|
366
374
|
for (i = 0; i < size; ++i) {
|
367
|
-
if (
|
375
|
+
if (_isalnum(data[i]))
|
368
376
|
continue;
|
369
377
|
|
370
378
|
switch (data[i]) {
|
@@ -400,14 +408,14 @@ tag_length(uint8_t *data, size_t size, enum mkd_autolink *autolink)
|
|
400
408
|
if (data[0] != '<') return 0;
|
401
409
|
i = (data[1] == '/') ? 2 : 1;
|
402
410
|
|
403
|
-
if (!
|
411
|
+
if (!_isalnum(data[i]))
|
404
412
|
return 0;
|
405
413
|
|
406
414
|
/* scheme test */
|
407
415
|
*autolink = MKDA_NOT_AUTOLINK;
|
408
416
|
|
409
417
|
/* try to find the beginning of an URI */
|
410
|
-
while (i < size && (
|
418
|
+
while (i < size && (_isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-'))
|
411
419
|
i++;
|
412
420
|
|
413
421
|
if (i > 1 && data[i] == '@') {
|
@@ -600,7 +608,7 @@ parse_emph1(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t size
|
|
600
608
|
if (data[i] == c && !_isspace(data[i - 1])) {
|
601
609
|
|
602
610
|
if (rndr->ext_flags & MKDEXT_NO_INTRA_EMPHASIS) {
|
603
|
-
if (i + i < size &&
|
611
|
+
if (i + i < size && _isalnum(data[i + 1]))
|
604
612
|
continue;
|
605
613
|
}
|
606
614
|
|
@@ -702,7 +710,7 @@ char_emphasis(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t of
|
|
702
710
|
size_t ret;
|
703
711
|
|
704
712
|
if (rndr->ext_flags & MKDEXT_NO_INTRA_EMPHASIS) {
|
705
|
-
if (offset > 0 &&
|
713
|
+
if (offset > 0 && _isalnum(data[-1]))
|
706
714
|
return 0;
|
707
715
|
}
|
708
716
|
|
@@ -868,7 +876,7 @@ char_entity(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t offs
|
|
868
876
|
if (end < size && data[end] == '#')
|
869
877
|
end++;
|
870
878
|
|
871
|
-
while (end < size &&
|
879
|
+
while (end < size && _isalnum(data[end]))
|
872
880
|
end++;
|
873
881
|
|
874
882
|
if (end < size && data[end] == ';')
|
@@ -1712,7 +1720,7 @@ parse_paragraph(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t
|
|
1712
1720
|
parse_inline(header_work, rndr, work.data, work.size);
|
1713
1721
|
|
1714
1722
|
if (rndr->cb.header)
|
1715
|
-
rndr->cb.header(ob, header_work, (int)level,
|
1723
|
+
rndr->cb.header(ob, header_work, (int)level, rndr->opaque);
|
1716
1724
|
|
1717
1725
|
rndr_popbuf(rndr, BUFFER_SPAN);
|
1718
1726
|
}
|
@@ -1992,7 +2000,7 @@ parse_atxheader(struct buf *ob, struct sd_markdown *rndr, uint8_t *data, size_t
|
|
1992
2000
|
parse_inline(work, rndr, data + i, end - i);
|
1993
2001
|
|
1994
2002
|
if (rndr->cb.header)
|
1995
|
-
rndr->cb.header(ob, work, (int)level,
|
2003
|
+
rndr->cb.header(ob, work, (int)level, rndr->opaque);
|
1996
2004
|
|
1997
2005
|
rndr_popbuf(rndr, BUFFER_SPAN);
|
1998
2006
|
}
|
data/ext/redcarpet/markdown.h
CHANGED
@@ -67,7 +67,7 @@ struct sd_callbacks {
|
|
67
67
|
void (*blockcode)(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque);
|
68
68
|
void (*blockquote)(struct buf *ob, const struct buf *text, void *opaque);
|
69
69
|
void (*blockhtml)(struct buf *ob,const struct buf *text, void *opaque);
|
70
|
-
void (*header)(struct buf *ob, const struct buf *text, int level,
|
70
|
+
void (*header)(struct buf *ob, const struct buf *text, int level, void *opaque);
|
71
71
|
void (*hrule)(struct buf *ob, void *opaque);
|
72
72
|
void (*list)(struct buf *ob, const struct buf *text, int flags, void *opaque);
|
73
73
|
void (*listitem)(struct buf *ob, const struct buf *text, int flags, void *opaque);
|
@@ -105,7 +105,7 @@ struct sd_callbacks {
|
|
105
105
|
};
|
106
106
|
|
107
107
|
/* header methods used internally in Redcarpet */
|
108
|
-
char* header_anchor(
|
108
|
+
char* header_anchor(struct buf *text);
|
109
109
|
|
110
110
|
struct sd_markdown;
|
111
111
|
|
data/ext/redcarpet/rc_render.c
CHANGED
@@ -61,9 +61,9 @@ rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
|
|
61
61
|
}
|
62
62
|
|
63
63
|
static void
|
64
|
-
rndr_header(struct buf *ob, const struct buf *text, int level,
|
64
|
+
rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
65
65
|
{
|
66
|
-
BLOCK_CALLBACK("header",
|
66
|
+
BLOCK_CALLBACK("header", 2, buf2str(text), INT2FIX(level));
|
67
67
|
}
|
68
68
|
|
69
69
|
static void
|
data/lib/redcarpet.rb
CHANGED
@@ -31,11 +31,16 @@ module Redcarpet
|
|
31
31
|
content
|
32
32
|
end
|
33
33
|
|
34
|
+
def image(link, title, content)
|
35
|
+
content &&= content + " "
|
36
|
+
"#{content}#{link}"
|
37
|
+
end
|
38
|
+
|
34
39
|
def paragraph(text)
|
35
40
|
text + "\n"
|
36
41
|
end
|
37
42
|
|
38
|
-
def header(text, header_level
|
43
|
+
def header(text, header_level)
|
39
44
|
text + "\n"
|
40
45
|
end
|
41
46
|
end
|
data/redcarpet.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'redcarpet'
|
4
|
-
s.version = '3.1.
|
4
|
+
s.version = '3.1.2'
|
5
5
|
s.summary = "Markdown that smells nice"
|
6
6
|
s.description = 'A fast, safe and extensible Markdown to (X)HTML parser'
|
7
|
-
s.date = '2014-
|
7
|
+
s.date = '2014-05-10'
|
8
8
|
s.email = 'vicent@github.com'
|
9
9
|
s.homepage = 'http://github.com/vmg/redcarpet'
|
10
10
|
s.authors = ["Natacha Porté", "Vicent Martí"]
|
@@ -2,12 +2,6 @@
|
|
2
2
|
require 'test_helper'
|
3
3
|
|
4
4
|
class HTMLTOCRenderTest < Test::Unit::TestCase
|
5
|
-
class CustomTocRender < Redcarpet::Render::HTML_TOC
|
6
|
-
def header(text, level, anchor)
|
7
|
-
"<h#{level} id=\"foo-bar-#{anchor}\">#{text}</h1>"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
5
|
def setup
|
12
6
|
@render = Redcarpet::Render::HTML_TOC
|
13
7
|
@markdown = "# A title \n## A __nice__ subtitle\n## Another one \n### A sub-sub-title"
|
@@ -44,12 +38,4 @@ class HTMLTOCRenderTest < Test::Unit::TestCase
|
|
44
38
|
assert_match /another-one/, output
|
45
39
|
assert_match /a-sub-sub-title/, output
|
46
40
|
end
|
47
|
-
|
48
|
-
def test_header_callback
|
49
|
-
renderer = Redcarpet::Markdown.new(CustomTocRender)
|
50
|
-
output = renderer.render(@markdown)
|
51
|
-
|
52
|
-
assert_match /A title/, output
|
53
|
-
assert_match /foo-bar-a-title/, output
|
54
|
-
end
|
55
41
|
end
|
data/test/markdown_test.rb
CHANGED
@@ -269,10 +269,15 @@ text
|
|
269
269
|
assert render_with({:no_intra_emphasis => true}, "this fails: hello_world_") !~ /<em>/
|
270
270
|
assert render_with({:no_intra_emphasis => true}, "this also fails: hello_world_#bye") !~ /<em>/
|
271
271
|
assert render_with({:no_intra_emphasis => true}, "this works: hello_my_world") !~ /<em>/
|
272
|
+
assert render_with({:no_intra_emphasis => true}, "句中**粗體**測試") =~ /<strong>/
|
272
273
|
|
273
274
|
markdown = "This is (**bold**) and this_is_not_italic!"
|
274
275
|
html = "<p>This is (<strong>bold</strong>) and this_is_not_italic!</p>\n"
|
275
276
|
assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
|
277
|
+
|
278
|
+
markdown = "This is \"**bold**\""
|
279
|
+
html = "<p>This is "<strong>bold</strong>"</p>\n"
|
280
|
+
assert_equal html, render_with({:no_intra_emphasis => true}, markdown)
|
276
281
|
end
|
277
282
|
|
278
283
|
def test_ordered_lists_with_lax_spacing
|
@@ -23,9 +23,20 @@ Hello world! Please visit [this site](https://github.com/).
|
|
23
23
|
|
24
24
|
class Foo
|
25
25
|
end
|
26
|
+
|
27
|
+
Look at this ![picture](http://example.org/picture.png)
|
28
|
+
And this: ![](http://example.org/image.jpg)
|
26
29
|
Markdown
|
30
|
+
plaintext = <<-Plaintext
|
31
|
+
Foo bar
|
32
|
+
Hello world! Please visit this site.
|
33
|
+
class Foo
|
34
|
+
end
|
35
|
+
Look at this picture http://example.org/picture.png
|
36
|
+
And this: http://example.org/image.jpg
|
37
|
+
Plaintext
|
27
38
|
|
28
39
|
html = @markdown.render(markdown)
|
29
|
-
html_equal
|
40
|
+
html_equal plaintext, html
|
30
41
|
end
|
31
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redcarpet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Natacha Porté
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|