tight-redcarpet 3.1.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9e24786ab824e442074458d6b37acc2f5cca468
4
- data.tar.gz: 3e99a9c16cdb6e9b8c373088f38936e9c463654a
3
+ metadata.gz: 0d789e647d9d2bfdd99bff901a26d1fe0513acfb
4
+ data.tar.gz: e980f2395afd5e731b7ffbfaa18701c627458bb1
5
5
  SHA512:
6
- metadata.gz: 6da988577142c15cc12fc677fbce214d1356b3ec88b417727a42ec33d35921eba26445299b7f4821602c5afae32dcc339b9ebb5af1b397c8a36cf14cd7610e64
7
- data.tar.gz: 1c1ca54286878e014e2280baea35b6030a4a97bbb2870f89c6f4225e76285b3fb0f21f0b6edfbaa95fa4460013ac997b08b4e42836fa592fc60d97086ffdb817
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 are also handled, and http
82
- links without protocol, but starting with `www`.
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
- If the method for a document element is not implemented, the block will
224
- be skipped.
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 match the level of that method (e.g. return a block
274
- element when overriding a block-level callback). Otherwise, the output may
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-2013, Vicent Martí
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 = "#{pwd}/bin/redcarpet"
33
- test_version = ENV['MARKDOWN_TEST_VER'] || '1.0.3'
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_#{test_version}") do
36
+ chdir("test/MarkdownTest_#{version}") do
37
37
  sh "RUBYLIB=#{lib_dir} ./MarkdownTest.pl --script='#{script}' --tidy"
38
38
  end
39
39
  end
@@ -94,7 +94,7 @@ bufnew(size_t unit)
94
94
 
95
95
  /* bufnullterm: NULL-termination of the string array */
96
96
  const char *
97
- bufcstr(struct buf *buf)
97
+ bufcstr(const struct buf *buf)
98
98
  {
99
99
  assert(buf && buf->unit);
100
100
 
@@ -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 *text)
267
+ char *header_anchor(const struct buf *buffer)
269
268
  {
270
- VALUE str = rb_str_new2(bufcstr(text));
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
- VALUE heading = rb_funcall(str, rb_intern("gsub"), 2, space_regex, rb_str_new2("-"));
275
- heading = rb_funcall(heading, rb_intern("gsub"), 2, tags_regex, rb_str_new2(""));
276
- heading = rb_funcall(heading, rb_intern("downcase"), 0);
271
+ char text[size];
272
+ strcpy(text, bufcstr(buffer));
277
273
 
278
- return StringValueCStr(heading);
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, sz;
399
- if (!text) return;
400
- sz = text->size;
401
- while (sz > 0 && text->data[sz - 1] == '\n') sz--;
402
- org = 0;
403
- while (org < sz && text->data[org] == '\n') org++;
404
- if (org >= sz) return;
405
- if (ob->size) bufputc(ob, '\n');
406
- bufput(ob, text->data + org, sz - org);
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
- if (!link || !link->size) return 0;
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
- * It doens't see if there are any valid tags, just escape all of them. */
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
- if (text) escape_html(ob, text->data, text->size);
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 nesting_level)
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 = HTML_TOC;
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 nesting_level);
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
@@ -1,5 +1,6 @@
1
- /* C code produced by gperf version 3.0.3 */
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 = 37, duplicates = 0 */
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
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
97
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
98
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
99
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
100
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
101
- 8, 30, 25, 20, 15, 10, 38, 38, 38, 38,
102
- 38, 38, 38, 38, 38, 38, 0, 38, 0, 38,
103
- 5, 5, 5, 15, 0, 38, 38, 0, 15, 10,
104
- 0, 38, 38, 15, 0, 5, 38, 38, 38, 38,
105
- 38, 38, 38, 38, 38, 38, 38, 38, 0, 38,
106
- 0, 38, 5, 5, 5, 15, 0, 38, 38, 0,
107
- 15, 10, 0, 38, 38, 15, 0, 5, 38, 38,
108
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
109
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
110
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
111
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
112
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
113
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
114
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
115
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
116
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
117
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
118
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
119
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
120
- 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
121
- 38, 38, 38, 38, 38, 38, 38
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
- #ifdef __GNUC_STDC_INLINE__
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 = 24,
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 = 37
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
- "del",
163
+ "pre",
168
164
  "form",
169
- "blockquote",
165
+ "style",
166
+ "footer",
167
+ "section",
168
+ "", "", "",
170
169
  "figure",
171
- "ol",
170
+ "hr",
172
171
  "fieldset",
172
+ "math",
173
+ "figcaption",
174
+ "header",
175
+ "dl",
176
+ "del",
173
177
  "",
174
- "h1",
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
- "script",
201
+ "aside",
202
+ "output",
180
203
  "h5",
181
- "noscript",
204
+ "", "",
205
+ "tfoot",
182
206
  "",
183
- "style",
184
- "iframe",
185
207
  "h4",
186
- "ins",
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)