redcarpet 1.10.0 → 1.10.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.

data/ext/markdown.c CHANGED
@@ -137,7 +137,7 @@ is_safe_link(const char *link, size_t link_len)
137
137
  for (i = 0; i < valid_uris_count; ++i) {
138
138
  size_t len = strlen(valid_uris[i]);
139
139
 
140
- if (link_len > len && memcmp(link, valid_uris[i], len) == 0)
140
+ if (link_len > len && strncasecmp(link, valid_uris[i], len) == 0)
141
141
  return 1;
142
142
  }
143
143
 
@@ -397,7 +397,7 @@ parse_emph1(struct buf *ob, struct render *rndr, char *data, size_t size, char c
397
397
 
398
398
  work = rndr_newbuf(rndr);
399
399
  parse_inline(work, rndr, data, i);
400
- r = rndr->make.emphasis(ob, work, c, rndr->make.opaque);
400
+ r = rndr->make.emphasis(ob, work, rndr->make.opaque);
401
401
  rndr_popbuf(rndr);
402
402
  return r ? i + 1 : 0;
403
403
  }
@@ -410,11 +410,14 @@ parse_emph1(struct buf *ob, struct render *rndr, char *data, size_t size, char c
410
410
  static size_t
411
411
  parse_emph2(struct buf *ob, struct render *rndr, char *data, size_t size, char c)
412
412
  {
413
+ int (*render_method)(struct buf *ob, struct buf *text, void *opaque);
413
414
  size_t i = 0, len;
414
415
  struct buf *work = 0;
415
416
  int r;
416
417
 
417
- if (!rndr->make.double_emphasis)
418
+ render_method = (c == '~') ? rndr->make.strikethrough : rndr->make.double_emphasis;
419
+
420
+ if (!render_method)
418
421
  return 0;
419
422
 
420
423
  while (i < size) {
@@ -425,7 +428,7 @@ parse_emph2(struct buf *ob, struct render *rndr, char *data, size_t size, char c
425
428
  if (i + 1 < size && data[i] == c && data[i + 1] == c && i && !isspace(data[i - 1])) {
426
429
  work = rndr_newbuf(rndr);
427
430
  parse_inline(work, rndr, data, i);
428
- r = rndr->make.double_emphasis(ob, work, c, rndr->make.opaque);
431
+ r = render_method(ob, work, rndr->make.opaque);
429
432
  rndr_popbuf(rndr);
430
433
  return r ? i + 2 : 0;
431
434
  }
@@ -456,7 +459,7 @@ parse_emph3(struct buf *ob, struct render *rndr, char *data, size_t size, char c
456
459
  struct buf *work = rndr_newbuf(rndr);
457
460
 
458
461
  parse_inline(work, rndr, data, i);
459
- r = rndr->make.triple_emphasis(ob, work, c, rndr->make.opaque);
462
+ r = rndr->make.triple_emphasis(ob, work, rndr->make.opaque);
460
463
  rndr_popbuf(rndr);
461
464
  return r ? i + 3 : 0;
462
465
 
@@ -484,8 +487,9 @@ char_emphasis(struct buf *ob, struct render *rndr, char *data, size_t offset, si
484
487
  size_t ret;
485
488
 
486
489
  if (size > 2 && data[1] != c) {
487
- /* whitespace cannot follow an opening emphasis */
488
- if (isspace(data[1]) || (ret = parse_emph1(ob, rndr, data + 1, size - 1, c)) == 0)
490
+ /* whitespace cannot follow an opening emphasis;
491
+ * strikethrough only takes two characters '~~' */
492
+ if (c == '~' || isspace(data[1]) || (ret = parse_emph1(ob, rndr, data + 1, size - 1, c)) == 0)
489
493
  return 0;
490
494
 
491
495
  return ret + 1;
@@ -499,7 +503,7 @@ char_emphasis(struct buf *ob, struct render *rndr, char *data, size_t offset, si
499
503
  }
500
504
 
501
505
  if (size > 4 && data[1] == c && data[2] == c && data[3] != c) {
502
- if (isspace(data[3]) || (ret = parse_emph3(ob, rndr, data + 3, size - 3, c)) == 0)
506
+ if (c == '~' || isspace(data[3]) || (ret = parse_emph3(ob, rndr, data + 3, size - 3, c)) == 0)
503
507
  return 0;
504
508
 
505
509
  return ret + 3;
@@ -1970,8 +1974,13 @@ ups_markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndrer,
1970
1974
 
1971
1975
  if (extensions & MKDEXT_AUTOLINK) {
1972
1976
  rndr.active_char['h'] = char_autolink; // http, https
1977
+ rndr.active_char['H'] = char_autolink;
1978
+
1973
1979
  rndr.active_char['f'] = char_autolink; // ftp
1980
+ rndr.active_char['F'] = char_autolink;
1981
+
1974
1982
  rndr.active_char['m'] = char_autolink; // mailto
1983
+ rndr.active_char['M'] = char_autolink;
1975
1984
  }
1976
1985
 
1977
1986
  /* Extension data */
data/ext/markdown.h CHANGED
@@ -61,13 +61,14 @@ struct mkd_renderer {
61
61
  /* span level callbacks - NULL or return 0 prints the span verbatim */
62
62
  int (*autolink)(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque);
63
63
  int (*codespan)(struct buf *ob, struct buf *text, void *opaque);
64
- int (*double_emphasis)(struct buf *ob, struct buf *text, char c, void *opaque);
65
- int (*emphasis)(struct buf *ob, struct buf *text, char c,void *opaque);
64
+ int (*double_emphasis)(struct buf *ob, struct buf *text, void *opaque);
65
+ int (*emphasis)(struct buf *ob, struct buf *text, void *opaque);
66
66
  int (*image)(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque);
67
67
  int (*linebreak)(struct buf *ob, void *opaque);
68
68
  int (*link)(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque);
69
69
  int (*raw_html_tag)(struct buf *ob, struct buf *tag, void *opaque);
70
- int (*triple_emphasis)(struct buf *ob, struct buf *text, char c, void *opaque);
70
+ int (*triple_emphasis)(struct buf *ob, struct buf *text, void *opaque);
71
+ int (*strikethrough)(struct buf *ob, struct buf *text, void *opaque);
71
72
 
72
73
  /* low level callbacks - NULL copies input directly into the output */
73
74
  void (*entity)(struct buf *ob, struct buf *entity, void *opaque);
data/ext/xhtml.c CHANGED
@@ -29,18 +29,23 @@ struct xhtml_renderopt {
29
29
  int current_level;
30
30
  } toc_data;
31
31
 
32
+ struct {
33
+ int in_squote;
34
+ int in_dquote;
35
+ } quotes;
36
+
32
37
  unsigned int flags;
33
38
  };
34
39
 
35
- static inline int
40
+ static inline void
36
41
  put_scaped_char(struct buf *ob, char c)
37
42
  {
38
43
  switch (c) {
39
- case '<': BUFPUTSL(ob, "&lt;"); return 1;
40
- case '>': BUFPUTSL(ob, "&gt;"); return 1;
41
- case '&': BUFPUTSL(ob, "&amp;"); return 1;
42
- case '"': BUFPUTSL(ob, "&quot;"); return 1;
43
- default: return 0;
44
+ case '<': BUFPUTSL(ob, "&lt;"); break;
45
+ case '>': BUFPUTSL(ob, "&gt;"); break;
46
+ case '&': BUFPUTSL(ob, "&amp;"); break;
47
+ case '"': BUFPUTSL(ob, "&quot;"); break;
48
+ default: bufputc(ob, c); break;
44
49
  }
45
50
  }
46
51
 
@@ -190,28 +195,34 @@ rndr_codespan(struct buf *ob, struct buf *text, void *opaque)
190
195
  }
191
196
 
192
197
  static int
193
- rndr_double_emphasis(struct buf *ob, struct buf *text, char c, void *opaque)
198
+ rndr_strikethrough(struct buf *ob, struct buf *text, void *opaque)
194
199
  {
195
200
  if (!text || !text->size)
196
201
  return 0;
197
202
 
198
- if (c == '~') {
199
- BUFPUTSL(ob, "<del>");
200
- bufput(ob, text->data, text->size);
201
- BUFPUTSL(ob, "</del>");
202
- } else {
203
- BUFPUTSL(ob, "<strong>");
204
- bufput(ob, text->data, text->size);
205
- BUFPUTSL(ob, "</strong>");
206
- }
203
+ BUFPUTSL(ob, "<del>");
204
+ bufput(ob, text->data, text->size);
205
+ BUFPUTSL(ob, "</del>");
206
+ return 1;
207
+ }
208
+
209
+ static int
210
+ rndr_double_emphasis(struct buf *ob, struct buf *text, void *opaque)
211
+ {
212
+ if (!text || !text->size)
213
+ return 0;
214
+
215
+ BUFPUTSL(ob, "<strong>");
216
+ bufput(ob, text->data, text->size);
217
+ BUFPUTSL(ob, "</strong>");
207
218
 
208
219
  return 1;
209
220
  }
210
221
 
211
222
  static int
212
- rndr_emphasis(struct buf *ob, struct buf *text, char c, void *opaque)
223
+ rndr_emphasis(struct buf *ob, struct buf *text, void *opaque)
213
224
  {
214
- if (!text || !text->size || c == '~') return 0;
225
+ if (!text || !text->size) return 0;
215
226
  BUFPUTSL(ob, "<em>");
216
227
  if (text) bufput(ob, text->data, text->size);
217
228
  BUFPUTSL(ob, "</em>");
@@ -311,6 +322,10 @@ rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
311
322
  bufput(ob, &text->data[i], text->size - i);
312
323
  }
313
324
  BUFPUTSL(ob, "</p>\n");
325
+
326
+ /* Close any open quotes at the end of the paragraph */
327
+ options->quotes.in_squote = 0;
328
+ options->quotes.in_dquote = 0;
314
329
  }
315
330
 
316
331
  static void
@@ -329,7 +344,7 @@ rndr_raw_block(struct buf *ob, struct buf *text, void *opaque)
329
344
  }
330
345
 
331
346
  static int
332
- rndr_triple_emphasis(struct buf *ob, struct buf *text, char c, void *opaque)
347
+ rndr_triple_emphasis(struct buf *ob, struct buf *text, void *opaque)
333
348
  {
334
349
  if (!text || !text->size) return 0;
335
350
  BUFPUTSL(ob, "<strong><em>");
@@ -546,8 +561,8 @@ rndr_normal_text(struct buf *ob, struct buf *text, void *opaque)
546
561
  static void
547
562
  rndr_smartypants(struct buf *ob, struct buf *text, void *opaque)
548
563
  {
564
+ struct xhtml_renderopt *options = opaque;
549
565
  size_t i;
550
- int open_single = 0, open_double = 0, open_tag = 0;
551
566
 
552
567
  if (!text)
553
568
  return;
@@ -572,78 +587,17 @@ rndr_smartypants(struct buf *ob, struct buf *text, void *opaque)
572
587
  continue;
573
588
 
574
589
  switch (c) {
575
- case '<':
576
- open_tag = 1;
577
- break;
578
-
579
- case '>':
580
- open_tag = 0;
581
- break;
582
-
583
- #if 0
584
- /*
585
- * FIXME: this is bongos.
586
- *
587
- * The markdown spec defines that code blocks can be delimited
588
- * by more than one backtick, e.g.
589
- *
590
- * ``There is a literal backtick (`) here.``
591
- * <p><code>There is a literal backtick (`) here.</code></p>
592
- *
593
- * Obviously, there's no way to differentiate between the start
594
- * of a code block and the start of a quoted string for smartypants
595
- *
596
- * Look at this piece of Python code:
597
- *
598
- * ``result = ''.join(['this', 'is', 'bongos'])``
599
- *
600
- * This MD expression is clearly ambiguous since it can be parsed as:
601
- *
602
- * <p>&ldquo;result = &rdquo;.join ...</p>
603
- *
604
- * Or also as:
605
- *
606
- * <p><code>result = ''.join(['this', 'is', 'bongos'])</code></p>
607
- *
608
- * Fuck everything about this. This is temporarily disabled, because at GitHub
609
- * it's probably smarter to prioritize code blocks than pretty cutesy punctuation.
610
- *
611
- * The equivalent closing tag for the (``), ('') has also been disabled, because
612
- * it makes no sense to have closing tags without opening tags.
613
- */
614
- case '`':
615
- if (open_tag == 0) {
616
- if (i + 1 < text->size && text->data[i + 1] == '`') {
617
- BUFPUTSL(ob, "&ldquo;"); i++;
618
- continue;
619
- }
620
- }
621
- break;
622
- #endif
623
-
624
590
  case '\"':
625
- if (open_tag == 0) {
626
- if (smartypants_quotes(ob, text, i, open_double)) {
627
- open_double = !open_double;
628
- continue;
629
- }
591
+ if (smartypants_quotes(ob, text, i, options->quotes.in_dquote)) {
592
+ options->quotes.in_dquote = !options->quotes.in_dquote;
593
+ continue;
630
594
  }
631
595
  break;
632
596
 
633
597
  case '\'':
634
- if (open_tag == 0) {
635
-
636
- #if 0 /* temporarily disabled, see previous comment */
637
- if (i + 1 < text->size && text->data[i + 1] == '\'') {
638
- BUFPUTSL(ob, "&rdquo;"); i++;
639
- continue;
640
- }
641
- #endif
642
-
643
- if (smartypants_quotes(ob, text, i, open_single)) {
644
- open_single = !open_single;
645
- continue;
646
- }
598
+ if (smartypants_quotes(ob, text, i, options->quotes.in_squote)) {
599
+ options->quotes.in_squote = !options->quotes.in_squote;
600
+ continue;
647
601
  }
648
602
  break;
649
603
  }
@@ -651,8 +605,7 @@ rndr_smartypants(struct buf *ob, struct buf *text, void *opaque)
651
605
  /*
652
606
  * Copy raw character
653
607
  */
654
- if (!put_scaped_char(ob, c))
655
- bufputc(ob, c);
608
+ put_scaped_char(ob, c);
656
609
  }
657
610
  }
658
611
 
@@ -720,6 +673,7 @@ ups_toc_renderer(struct mkd_renderer *renderer)
720
673
  NULL,
721
674
  NULL,
722
675
  rndr_triple_emphasis,
676
+ rndr_strikethrough,
723
677
 
724
678
  NULL,
725
679
  NULL,
@@ -763,6 +717,7 @@ ups_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
763
717
  rndr_link,
764
718
  rndr_raw_html,
765
719
  rndr_triple_emphasis,
720
+ rndr_strikethrough,
766
721
 
767
722
  NULL,
768
723
  rndr_normal_text,
data/lib/redcarpet.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.10.0'
29
+ VERSION = '1.10.1'
30
30
 
31
31
  # Original Markdown formatted text.
32
32
  attr_reader :text
data/redcarpet.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'redcarpet'
3
- s.version = '1.10.0'
3
+ s.version = '1.10.1'
4
4
  s.summary = "Ruby bindings for libupskirt"
5
5
  s.description = 'A fast and safe Markdown to (X)HTML parser'
6
- s.date = '2011-04-21'
6
+ s.date = '2011-04-22'
7
7
  s.email = 'vicent@github.com'
8
8
  s.homepage = 'http://github.com/tanoku/redcarpet'
9
9
  s.has_rdoc = true
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: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 10
9
- - 0
10
- version: 1.10.0
9
+ - 1
10
+ version: 1.10.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Natacha Port\xC3\xA9"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-21 00:00:00 +03:00
19
+ date: 2011-04-22 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies: []
22
22