redcarpet 1.9.0 → 1.10.0

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/buffer.h CHANGED
@@ -38,6 +38,8 @@ struct buf {
38
38
  * MACROS *
39
39
  **********/
40
40
 
41
+ #define STRLEN(x) (sizeof(x) - 1)
42
+
41
43
  /* CONST_BUF • global buffer from a string litteral */
42
44
  #define CONST_BUF(name, string) \
43
45
  static struct buf name = { string, sizeof string -1, sizeof string }
data/ext/markdown.c CHANGED
@@ -707,7 +707,7 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
707
707
  /* skipping initial whitespace */
708
708
  i += 1;
709
709
 
710
- while (i < size && (data[i] == ' ' || data[i] == '\t'))
710
+ while (i < size && isspace(data[i]))
711
711
  i++;
712
712
 
713
713
  link_b = i;
@@ -740,7 +740,7 @@ char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t
740
740
  }
741
741
 
742
742
  /* remove whitespace at the end of the link */
743
- while (link_e > link_b && (data[link_e - 1] == ' ' || data[link_e - 1] == '\t'))
743
+ while (link_e > link_b && isspace(data[link_e - 1]))
744
744
  link_e--;
745
745
 
746
746
  /* remove optional angle brackets around the link */
@@ -944,8 +944,21 @@ is_codefence(char *data, size_t size, struct buf *syntax)
944
944
 
945
945
  syntax->data = data + i;
946
946
 
947
- while (i < size && !isspace(data[i])) {
948
- syn++; i++;
947
+ if (i < size && data[i] == '{') {
948
+ i++; syntax->data++;
949
+
950
+ while (i < size && data[i] != '}' && data[i] != '\n') {
951
+ syn++; i++;
952
+ }
953
+
954
+ if (i == size || data[i] != '}')
955
+ return 0;
956
+
957
+ i++;
958
+ } else {
959
+ while (i < size && !isspace(data[i])) {
960
+ syn++; i++;
961
+ }
949
962
  }
950
963
 
951
964
  syntax->size = syn;
@@ -1531,21 +1544,9 @@ parse_htmlblock(struct buf *ob, struct render *rndr, char *data, size_t size, in
1531
1544
  i = 1;
1532
1545
  found = 0;
1533
1546
 
1534
- while (i < size) {
1535
- i += 1;
1536
- while (i < size && !(data[i - 2] == '\n'
1537
- && data[i - 1] == '<' && data[i] == '/'))
1538
- i += 1;
1539
- if (i + 2 + curtag->size >= size) break;
1540
- j = htmlblock_end(curtag, rndr, data + i - 1, size - i + 1);
1541
- if (j) {
1542
- i += j - 1;
1543
- found = 1;
1544
- break; } }
1545
-
1546
1547
  /* if not found, trying a second pass looking for indented match */
1547
1548
  /* but not if tag is "ins" or "del" (following original Markdown.pl) */
1548
- if (!found && curtag != INS_TAG && curtag != DEL_TAG) {
1549
+ if (curtag != INS_TAG && curtag != DEL_TAG) {
1549
1550
  i = 1;
1550
1551
  while (i < size) {
1551
1552
  i++;
data/ext/xhtml.c CHANGED
@@ -18,7 +18,7 @@
18
18
  #include "markdown.h"
19
19
  #include "xhtml.h"
20
20
 
21
- #include <strings.h>
21
+ #include <string.h>
22
22
  #include <stdlib.h>
23
23
  #include <stdio.h>
24
24
  #include <ctype.h>
@@ -131,12 +131,38 @@ rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *op
131
131
  static void
132
132
  rndr_blockcode(struct buf *ob, struct buf *text, struct buf *lang, void *opaque)
133
133
  {
134
+ static char *sh_lang = "bash";
135
+ struct buf lang_shebang = {0, 0, 0, 0, 0};
136
+
134
137
  if (ob->size) bufputc(ob, '\n');
135
138
 
139
+ /*
140
+ * Try to guess the language based on the shebang
141
+ */
142
+ if (lang == NULL && text != NULL && text->size > 2) {
143
+ if (bufprefix(text, "#!/usr/bin/env ") == 0) {
144
+ size_t i = STRLEN("#!/usr/bin/env ");
145
+
146
+ lang_shebang.data = text->data + i;
147
+ while (i < text->size && !isspace(text->data[i])) {
148
+ i++; lang_shebang.size++;
149
+ }
150
+
151
+ lang = &lang_shebang;
152
+ } else if (bufprefix(text, "#!/bin/sh") == 0 && isspace(text->data[STRLEN("#!/bin/sh")])) {
153
+ lang_shebang.data = sh_lang;
154
+ lang_shebang.size = strlen(sh_lang);
155
+ lang = &lang_shebang;
156
+ }
157
+ }
158
+
136
159
  if (lang && lang->size) {
137
- BUFPUTSL(ob, "<pre lang=\"");
138
- bufput(ob, lang->data, lang->size);
139
- BUFPUTSL(ob, "\"><code>");
160
+ BUFPUTSL(ob, "<pre><code class=\"");
161
+ if (lang->data[0] == '.')
162
+ bufput(ob, lang->data + 1, lang->size - 1);
163
+ else
164
+ bufput(ob, lang->data, lang->size);
165
+ BUFPUTSL(ob, "\">");
140
166
  } else
141
167
  BUFPUTSL(ob, "<pre><code>");
142
168
 
data/lib/redcarpet.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.9.0'
29
+ VERSION = '1.10.0'
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.9.0'
3
+ s.version = '1.10.0'
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-18'
6
+ s.date = '2011-04-21'
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: 51
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 9
8
+ - 10
9
9
  - 0
10
- version: 1.9.0
10
+ version: 1.10.0
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-18 00:00:00 +03:00
19
+ date: 2011-04-21 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies: []
22
22