tight-redcarpet 3.1.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/COPYING +0 -0
- data/README.markdown +10 -9
- data/Rakefile +4 -4
- data/ext/redcarpet/buffer.c +1 -1
- data/ext/redcarpet/buffer.h +1 -1
- data/ext/redcarpet/html.c +81 -25
- data/ext/redcarpet/html.h +7 -1
- data/ext/redcarpet/html_blocks.h +71 -48
- data/ext/redcarpet/markdown.c +14 -12
- data/ext/redcarpet/markdown.h +0 -3
- data/ext/redcarpet/rc_markdown.c +3 -7
- data/ext/redcarpet/rc_render.c +13 -8
- data/lib/redcarpet.rb +41 -74
- data/lib/redcarpet/compat.rb +70 -0
- data/lib/redcarpet/render_strip.rb +2 -2
- data/redcarpet.gemspec +7 -4
- data/test/benchmark.rb +24 -0
- data/test/html5_test.rb +69 -0
- data/test/html_render_test.rb +82 -73
- data/test/html_toc_render_test.rb +36 -9
- data/test/markdown_test.rb +26 -0
- data/test/safe_render_test.rb +36 -0
- data/test/stripdown_render_test.rb +25 -27
- data/test/test_helper.rb +23 -0
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d789e647d9d2bfdd99bff901a26d1fe0513acfb
|
4
|
+
data.tar.gz: e980f2395afd5e731b7ffbfaa18701c627458bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa7805caaf2ce5bd875e89c9bd723c5ffdfc34e7ce53355619af0c89f472d4c6eef5bb48c37591d3ef6d269a01e125d134879d6fd022bf76f7f255f9bf866c5b
|
7
|
+
data.tar.gz: 350f45ef2e36f7ab9ffb30e5664ab706bcce18e5710d31ac11b905bfe7702e1c99a31fc6599a0ec583fa3099ada9d4327cb93f844de445ed158025f69213e63e
|
data/COPYING
CHANGED
File without changes
|
data/README.markdown
CHANGED
@@ -3,7 +3,7 @@ Redcarpet is written with sugar, spice and everything nice
|
|
3
3
|
|
4
4
|
[![Build Status](https://travis-ci.org/vmg/redcarpet.svg?branch=master)](https://travis-ci.org/vmg/redcarpet)
|
5
5
|
|
6
|
-
Redcarpet is Ruby library for Markdown processing that smells like
|
6
|
+
Redcarpet is a Ruby library for Markdown processing that smells like
|
7
7
|
butterflies and popcorn.
|
8
8
|
|
9
9
|
This library is written by people
|
@@ -78,8 +78,8 @@ be added at the end of the opening fence for the code block.
|
|
78
78
|
|
79
79
|
* `:autolink`: parse links even when they are not enclosed in `<>`
|
80
80
|
characters. Autolinks for the http, https and ftp protocols will be
|
81
|
-
automatically detected. Email addresses
|
82
|
-
|
81
|
+
automatically detected. Email addresses and http links without protocol,
|
82
|
+
but starting with `www` are also handled.
|
83
83
|
|
84
84
|
* `:disable_indented_code_blocks`: do not parse usual markdown
|
85
85
|
code blocks. Markdown converts text with four spaces at
|
@@ -220,8 +220,9 @@ The following instance methods may be implemented by the renderer:
|
|
220
220
|
### Block-level calls
|
221
221
|
|
222
222
|
If the return value of the method is `nil`, the block will be skipped.
|
223
|
-
|
224
|
-
|
223
|
+
Therefore, make sure that your renderer has at least a `paragraph` method
|
224
|
+
implemented. If the method for a document element is not implemented, the
|
225
|
+
block will be skipped.
|
225
226
|
|
226
227
|
Example:
|
227
228
|
|
@@ -270,9 +271,9 @@ be copied verbatim:
|
|
270
271
|
* footnote_ref(number)
|
271
272
|
|
272
273
|
**Note**: When overriding a renderer's method, be sure to return a HTML
|
273
|
-
element with a level that
|
274
|
-
element when overriding a block-level callback). Otherwise, the output
|
275
|
-
be unexpected.
|
274
|
+
element with a level that matches the level of that method (e.g. return a
|
275
|
+
block element when overriding a block-level callback). Otherwise, the output
|
276
|
+
may be unexpected.
|
276
277
|
|
277
278
|
### Low level rendering
|
278
279
|
|
@@ -371,7 +372,7 @@ monkeypatches the Markdown class, you're a terrible human being. Just saying.
|
|
371
372
|
Boring legal stuff
|
372
373
|
------------------
|
373
374
|
|
374
|
-
Copyright (c) 2011-
|
375
|
+
Copyright (c) 2011-2014, Vicent Martí
|
375
376
|
|
376
377
|
Permission to use, copy, modify, and/or distribute this software for any
|
377
378
|
purpose with or without fee is hereby granted, provided that the above
|
data/Rakefile
CHANGED
@@ -27,13 +27,13 @@ end
|
|
27
27
|
|
28
28
|
task 'test:unit' => :compile
|
29
29
|
|
30
|
-
desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0)'
|
30
|
+
desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0.3)'
|
31
31
|
task 'test:conformance' => :compile do |t|
|
32
|
-
script
|
33
|
-
|
32
|
+
script = "#{pwd}/bin/redcarpet"
|
33
|
+
version = ENV['MARKDOWN_TEST_VER'] || '1.0.3'
|
34
34
|
lib_dir = "#{pwd}/lib"
|
35
35
|
|
36
|
-
chdir("test/MarkdownTest_#{
|
36
|
+
chdir("test/MarkdownTest_#{version}") do
|
37
37
|
sh "RUBYLIB=#{lib_dir} ./MarkdownTest.pl --script='#{script}' --tidy"
|
38
38
|
end
|
39
39
|
end
|
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(struct buf *);
|
58
|
+
const char *bufcstr(const 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
@@ -17,7 +17,6 @@
|
|
17
17
|
|
18
18
|
#include "markdown.h"
|
19
19
|
#include "html.h"
|
20
|
-
#include "ruby.h"
|
21
20
|
#include <string.h>
|
22
21
|
#include <stdlib.h>
|
23
22
|
#include <stdio.h>
|
@@ -125,7 +124,7 @@ rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, v
|
|
125
124
|
if (lang && lang->size) {
|
126
125
|
size_t i, cls;
|
127
126
|
if (options->flags & HTML_PRETTIFY) {
|
128
|
-
BUFPUTSL(ob, "<pre><code class=\"prettyprint ");
|
127
|
+
BUFPUTSL(ob, "<pre><code class=\"prettyprint lang-");
|
129
128
|
cls++;
|
130
129
|
} else {
|
131
130
|
BUFPUTSL(ob, "<pre><code class=\"");
|
@@ -265,17 +264,51 @@ rndr_linebreak(struct buf *ob, void *opaque)
|
|
265
264
|
return 1;
|
266
265
|
}
|
267
266
|
|
268
|
-
char *header_anchor(struct buf *
|
267
|
+
char *header_anchor(const struct buf *buffer)
|
269
268
|
{
|
270
|
-
|
271
|
-
VALUE space_regex = rb_reg_new(" +", 2 /* length */, 0);
|
272
|
-
VALUE tags_regex = rb_reg_new("<\\/?[^>]*>", 10, 0);
|
269
|
+
size_t i, j, k, size = buffer->size;
|
273
270
|
|
274
|
-
|
275
|
-
|
276
|
-
heading = rb_funcall(heading, rb_intern("downcase"), 0);
|
271
|
+
char text[size];
|
272
|
+
strcpy(text, bufcstr(buffer));
|
277
273
|
|
278
|
-
|
274
|
+
char raw_string[size];
|
275
|
+
|
276
|
+
/* Strip down the inline HTML markup if needed */
|
277
|
+
if (strchr(text, '<') < strchr(text, '>')) {
|
278
|
+
char* part = strtok(text, "<>");
|
279
|
+
|
280
|
+
/* Once every two times, the yielded token is the
|
281
|
+
content of a HTML tag so we don't need to copy it */
|
282
|
+
for (k = 0; part != NULL; k++) {
|
283
|
+
if (k == 0)
|
284
|
+
strcpy(raw_string, part);
|
285
|
+
else if (k % 2 == 0)
|
286
|
+
strcat(raw_string, part);
|
287
|
+
|
288
|
+
part = strtok(NULL, "<>");
|
289
|
+
}
|
290
|
+
|
291
|
+
size = strlen(raw_string);
|
292
|
+
} else {
|
293
|
+
strcpy(raw_string, text);
|
294
|
+
}
|
295
|
+
|
296
|
+
char* heading = malloc(size * sizeof(char));
|
297
|
+
|
298
|
+
/* Dasherize the string removing extra white spaces
|
299
|
+
and stripped chars */
|
300
|
+
for (i = 0, j = 0; i < size; ++i, ++j) {
|
301
|
+
while (STRIPPED_CHAR(raw_string[i]) && STRIPPED_CHAR(raw_string[i+1]))
|
302
|
+
i++;
|
303
|
+
|
304
|
+
if (STRIPPED_CHAR(raw_string[i]))
|
305
|
+
heading[j] = '-';
|
306
|
+
else
|
307
|
+
heading[j] = tolower(raw_string[i]);
|
308
|
+
}
|
309
|
+
|
310
|
+
heading[j++] = '\0';
|
311
|
+
return heading;
|
279
312
|
}
|
280
313
|
|
281
314
|
static void
|
@@ -395,15 +428,30 @@ rndr_paragraph(struct buf *ob, const struct buf *text, void *opaque)
|
|
395
428
|
static void
|
396
429
|
rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
|
397
430
|
{
|
398
|
-
size_t org,
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
431
|
+
size_t org, size;
|
432
|
+
struct html_renderopt *options = opaque;
|
433
|
+
|
434
|
+
if (!text)
|
435
|
+
return;
|
436
|
+
|
437
|
+
size = text->size;
|
438
|
+
while (size > 0 && text->data[size - 1] == '\n')
|
439
|
+
size--;
|
440
|
+
|
441
|
+
for (org = 0; org < size && text->data[org] == '\n'; ++org)
|
442
|
+
|
443
|
+
if (org >= size)
|
444
|
+
return;
|
445
|
+
|
446
|
+
/* Remove style tags if the `:no_styles` option is enabled */
|
447
|
+
if ((options->flags & HTML_SKIP_STYLE) != 0 &&
|
448
|
+
sdhtml_is_tag(text->data, size, "style"))
|
449
|
+
return;
|
450
|
+
|
451
|
+
if (ob->size)
|
452
|
+
bufputc(ob, '\n');
|
453
|
+
|
454
|
+
bufput(ob, text->data + org, size - org);
|
407
455
|
bufputc(ob, '\n');
|
408
456
|
}
|
409
457
|
|
@@ -429,7 +477,9 @@ static int
|
|
429
477
|
rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
|
430
478
|
{
|
431
479
|
struct html_renderopt *options = opaque;
|
432
|
-
|
480
|
+
|
481
|
+
if (link != NULL && (options->flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size))
|
482
|
+
return 0;
|
433
483
|
|
434
484
|
BUFPUTSL(ob, "<img src=\"");
|
435
485
|
escape_href(ob, link->data, link->size);
|
@@ -452,7 +502,7 @@ rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
|
|
452
502
|
struct html_renderopt *options = opaque;
|
453
503
|
|
454
504
|
/* HTML_ESCAPE overrides SKIP_HTML, SKIP_STYLE, SKIP_LINKS and SKIP_IMAGES
|
455
|
-
|
505
|
+
It doesn't see if there are any valid tags, just escape all of them. */
|
456
506
|
if((options->flags & HTML_ESCAPE) != 0) {
|
457
507
|
escape_html(ob, text->data, text->size);
|
458
508
|
return 1;
|
@@ -636,7 +686,14 @@ toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
|
636
686
|
}
|
637
687
|
|
638
688
|
bufprintf(ob, "<a href=\"#%s\">", header_anchor(text));
|
639
|
-
|
689
|
+
|
690
|
+
if (text) {
|
691
|
+
if (options->flags & HTML_ESCAPE)
|
692
|
+
escape_html(ob, text->data, text->size);
|
693
|
+
else
|
694
|
+
bufput(ob, text->data, text->size);
|
695
|
+
}
|
696
|
+
|
640
697
|
BUFPUTSL(ob, "</a>\n");
|
641
698
|
}
|
642
699
|
}
|
@@ -661,7 +718,7 @@ toc_finalize(struct buf *ob, void *opaque)
|
|
661
718
|
}
|
662
719
|
|
663
720
|
void
|
664
|
-
sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options, int
|
721
|
+
sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options, unsigned int render_flags)
|
665
722
|
{
|
666
723
|
static const struct sd_callbacks cb_default = {
|
667
724
|
NULL,
|
@@ -702,8 +759,7 @@ sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *optio
|
|
702
759
|
};
|
703
760
|
|
704
761
|
memset(options, 0x0, sizeof(struct html_renderopt));
|
705
|
-
options->flags =
|
706
|
-
options->toc_data.nesting_level = nesting_level;
|
762
|
+
options->flags = render_flags;
|
707
763
|
|
708
764
|
memcpy(callbacks, &cb_default, sizeof(struct sd_callbacks));
|
709
765
|
}
|
data/ext/redcarpet/html.h
CHANGED
@@ -65,11 +65,17 @@ extern void
|
|
65
65
|
sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options_ptr, unsigned int render_flags);
|
66
66
|
|
67
67
|
extern void
|
68
|
-
sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options_ptr, int
|
68
|
+
sdhtml_toc_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options_ptr, unsigned int render_flags);
|
69
69
|
|
70
70
|
extern void
|
71
71
|
sdhtml_smartypants(struct buf *ob, const uint8_t *text, size_t size);
|
72
72
|
|
73
|
+
/* header method used internally in Redcarpet */
|
74
|
+
char *header_anchor(const struct buf *buffer);
|
75
|
+
|
76
|
+
#define STRIPPED_CHARS " -&+$,/:;=?@\"#{}|^~[]`\\*()%.!'"
|
77
|
+
#define STRIPPED_CHAR(x) (strchr(STRIPPED_CHARS, x) != NULL)
|
78
|
+
|
73
79
|
#ifdef __cplusplus
|
74
80
|
}
|
75
81
|
#endif
|
data/ext/redcarpet/html_blocks.h
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
/* C code produced by gperf version 3.0.
|
1
|
+
/* C code produced by gperf version 3.0.4 */
|
2
2
|
/* Command-line: gperf -N find_block_tag -H hash_block_tag -C -c -E --ignore-case html_block_names.txt */
|
3
|
+
/* See http://git.io/RN0ncw for the list of recognized elements */
|
3
4
|
/* Computed positions: -k'1-2' */
|
4
5
|
|
5
6
|
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
@@ -29,7 +30,7 @@
|
|
29
30
|
error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
|
30
31
|
#endif
|
31
32
|
|
32
|
-
/* maximum key range =
|
33
|
+
/* maximum key range = 67, duplicates = 0 */
|
33
34
|
|
34
35
|
#ifndef GPERF_DOWNCASE
|
35
36
|
#define GPERF_DOWNCASE 1
|
@@ -93,32 +94,32 @@ hash_block_tag (str, len)
|
|
93
94
|
{
|
94
95
|
static const unsigned char asso_values[] =
|
95
96
|
{
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
0,
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
97
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
98
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
99
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
100
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
101
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
102
|
+
55, 50, 45, 40, 35, 30, 68, 68, 68, 68,
|
103
|
+
68, 68, 68, 68, 68, 15, 10, 15, 15, 15,
|
104
|
+
0, 20, 10, 10, 5, 68, 68, 0, 20, 25,
|
105
|
+
0, 68, 68, 0, 25, 0, 15, 68, 68, 68,
|
106
|
+
68, 68, 68, 68, 68, 68, 68, 15, 10, 15,
|
107
|
+
15, 15, 0, 20, 10, 10, 5, 68, 68, 0,
|
108
|
+
20, 25, 0, 68, 68, 0, 25, 0, 15, 68,
|
109
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
110
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
111
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
112
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
113
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
114
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
115
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
116
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
117
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
118
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
119
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
120
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
121
|
+
68, 68, 68, 68, 68, 68, 68, 68, 68, 68,
|
122
|
+
68, 68, 68, 68, 68, 68, 68
|
122
123
|
};
|
123
124
|
register int hval = len;
|
124
125
|
|
@@ -136,7 +137,7 @@ hash_block_tag (str, len)
|
|
136
137
|
|
137
138
|
#ifdef __GNUC__
|
138
139
|
__inline
|
139
|
-
#
|
140
|
+
#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__
|
140
141
|
__attribute__ ((__gnu_inline__))
|
141
142
|
#endif
|
142
143
|
#endif
|
@@ -147,47 +148,69 @@ find_block_tag (str, len)
|
|
147
148
|
{
|
148
149
|
enum
|
149
150
|
{
|
150
|
-
TOTAL_KEYWORDS =
|
151
|
+
TOTAL_KEYWORDS = 41,
|
151
152
|
MIN_WORD_LENGTH = 1,
|
152
153
|
MAX_WORD_LENGTH = 10,
|
153
154
|
MIN_HASH_VALUE = 1,
|
154
|
-
MAX_HASH_VALUE =
|
155
|
+
MAX_HASH_VALUE = 67
|
155
156
|
};
|
156
157
|
|
157
158
|
static const char * const wordlist[] =
|
158
159
|
{
|
159
160
|
"",
|
160
161
|
"p",
|
161
|
-
"dl",
|
162
|
-
"div",
|
163
|
-
"math",
|
164
|
-
"table",
|
165
|
-
"",
|
166
162
|
"ul",
|
167
|
-
"
|
163
|
+
"pre",
|
168
164
|
"form",
|
169
|
-
"
|
165
|
+
"style",
|
166
|
+
"footer",
|
167
|
+
"section",
|
168
|
+
"", "", "",
|
170
169
|
"figure",
|
171
|
-
"
|
170
|
+
"hr",
|
172
171
|
"fieldset",
|
172
|
+
"math",
|
173
|
+
"figcaption",
|
174
|
+
"header",
|
175
|
+
"dl",
|
176
|
+
"del",
|
173
177
|
"",
|
174
|
-
"
|
178
|
+
"blockquote",
|
179
|
+
"script",
|
180
|
+
"article",
|
181
|
+
"div",
|
182
|
+
"",
|
183
|
+
"video",
|
184
|
+
"hgroup",
|
185
|
+
"ol",
|
186
|
+
"noscript",
|
187
|
+
"", "",
|
188
|
+
"canvas",
|
189
|
+
"dd",
|
190
|
+
"nav",
|
191
|
+
"abbr",
|
192
|
+
"audio",
|
193
|
+
"iframe",
|
194
|
+
"address",
|
195
|
+
"ins",
|
196
|
+
"",
|
197
|
+
"table",
|
175
198
|
"",
|
176
199
|
"h6",
|
177
|
-
"pre",
|
178
200
|
"", "",
|
179
|
-
"
|
201
|
+
"aside",
|
202
|
+
"output",
|
180
203
|
"h5",
|
181
|
-
"
|
204
|
+
"", "",
|
205
|
+
"tfoot",
|
182
206
|
"",
|
183
|
-
"style",
|
184
|
-
"iframe",
|
185
207
|
"h4",
|
186
|
-
"
|
187
|
-
"", "", "",
|
208
|
+
"", "", "", "",
|
188
209
|
"h3",
|
189
210
|
"", "", "", "",
|
190
|
-
"h2"
|
211
|
+
"h2",
|
212
|
+
"", "", "", "",
|
213
|
+
"h1"
|
191
214
|
};
|
192
215
|
|
193
216
|
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|