redcarpet 1.7.0 → 1.7.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
@@ -945,9 +945,10 @@ is_hrule(char *data, size_t size)
945
945
 
946
946
  /* check if a line is a code fence; return its size if it is */
947
947
  static size_t
948
- is_codefence(char *data, size_t size)
948
+ is_codefence(char *data, size_t size, struct buf *syntax)
949
949
  {
950
- size_t i = 0, n = 0;
950
+ size_t i = 0, n = 0, syn;
951
+ char c;
951
952
 
952
953
  /* skipping initial spaces */
953
954
  if (size < 3) return 0;
@@ -956,18 +957,45 @@ is_codefence(char *data, size_t size)
956
957
  if (data[2] == ' ') { i += 1; } } }
957
958
 
958
959
  /* looking at the hrule char */
959
- if (i + 2 >= size || data[i] != '~')
960
+ if (i + 2 >= size || !(data[i] == '~' || data[i] == '`'))
960
961
  return 0;
961
962
 
963
+ c = data[i];
964
+
962
965
  /* the whole line must be the char or whitespace */
963
- while (i < size && data[i] != '\n') {
964
- if (data[i] == '~') n++;
965
- else if (data[i] != ' ' && data[i] != '\t')
966
- return 0;
967
- i++;
966
+ while (i < size && data[i] == c) {
967
+ n++; i++;
968
968
  }
969
969
 
970
- return n >= 3 ? i + 1 : 0;
970
+ if (n < 3)
971
+ return 0;
972
+
973
+ if (syntax == NULL) {
974
+ while (i < size && data[i] != '\n') {
975
+ if (!isspace(data[i]))
976
+ return 0;
977
+
978
+ i++;
979
+ }
980
+ } else {
981
+ syntax->data = data + i;
982
+ syn = 0;
983
+
984
+ while (i < size && data[i] != '\n') {
985
+ syn++; i++;
986
+ }
987
+
988
+ while (syn > 0 && isspace(syntax->data[syn - 1]))
989
+ syn--;
990
+
991
+ while (syn > 0 && isspace(syntax->data[0])) {
992
+ syntax->data++; syn--;
993
+ }
994
+
995
+ syntax->size = syn;
996
+ }
997
+
998
+ return i + 1;
971
999
  }
972
1000
 
973
1001
  /* is_headerline • returns whether the line is a setext-style hdr underline */
@@ -1210,14 +1238,15 @@ parse_paragraph(struct buf *ob, struct render *rndr, char *data, size_t size)
1210
1238
  return end;
1211
1239
  }
1212
1240
 
1213
- /* parse_blockquote • hanldes parsing of a block-level code fragment */
1241
+ /* parse_fencedcode • hanldes parsing of a block-level code fragment */
1214
1242
  static size_t
1215
1243
  parse_fencedcode(struct buf *ob, struct render *rndr, char *data, size_t size)
1216
1244
  {
1217
1245
  size_t beg, end;
1218
1246
  struct buf *work = 0;
1247
+ struct buf syntax = { 0, 0, 0, 0, 0 };
1219
1248
 
1220
- beg = is_codefence(data, size);
1249
+ beg = is_codefence(data, size, &syntax);
1221
1250
  if (beg == 0) return 0;
1222
1251
 
1223
1252
  if (rndr->work.size < rndr->work.asize) {
@@ -1231,7 +1260,7 @@ parse_fencedcode(struct buf *ob, struct render *rndr, char *data, size_t size)
1231
1260
  while (beg < size) {
1232
1261
  size_t fence_end;
1233
1262
 
1234
- fence_end = is_codefence(data + beg, size - beg);
1263
+ fence_end = is_codefence(data + beg, size - beg, NULL);
1235
1264
  if (fence_end != 0) {
1236
1265
  beg += fence_end;
1237
1266
  break;
@@ -1253,7 +1282,7 @@ parse_fencedcode(struct buf *ob, struct render *rndr, char *data, size_t size)
1253
1282
  bufputc(work, '\n');
1254
1283
 
1255
1284
  if (rndr->make.blockcode)
1256
- rndr->make.blockcode(ob, work, rndr->make.opaque);
1285
+ rndr->make.blockcode(ob, work, syntax.size ? &syntax : NULL, rndr->make.opaque);
1257
1286
 
1258
1287
  rndr->work.size -= 1;
1259
1288
  return beg;
@@ -1293,7 +1322,7 @@ parse_blockcode(struct buf *ob, struct render *rndr, char *data, size_t size)
1293
1322
  work->size -= 1;
1294
1323
  bufputc(work, '\n');
1295
1324
  if (rndr->make.blockcode)
1296
- rndr->make.blockcode(ob, work, rndr->make.opaque);
1325
+ rndr->make.blockcode(ob, work, NULL, rndr->make.opaque);
1297
1326
  rndr->work.size -= 1;
1298
1327
  return beg;
1299
1328
  }
data/ext/markdown.h CHANGED
@@ -47,7 +47,7 @@ enum mkd_extensions {
47
47
  /* mkd_renderer • functions for rendering parsed data */
48
48
  struct mkd_renderer {
49
49
  /* block level callbacks - NULL skips the block */
50
- void (*blockcode)(struct buf *ob, struct buf *text, void *opaque);
50
+ void (*blockcode)(struct buf *ob, struct buf *text, struct buf *syntax, void *opaque);
51
51
  void (*blockquote)(struct buf *ob, struct buf *text, void *opaque);
52
52
  void (*blockhtml)(struct buf *ob, struct buf *text, void *opaque);
53
53
  void (*header)(struct buf *ob, struct buf *text, int level, void *opaque);
data/ext/xhtml.c CHANGED
@@ -112,11 +112,20 @@ rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *op
112
112
  }
113
113
 
114
114
  static void
115
- rndr_blockcode(struct buf *ob, struct buf *text, void *opaque)
115
+ rndr_blockcode(struct buf *ob, struct buf *text, struct buf *syntax, void *opaque)
116
116
  {
117
117
  if (ob->size) bufputc(ob, '\n');
118
- BUFPUTSL(ob, "<pre><code>");
119
- if (text) lus_attr_escape(ob, text->data, text->size);
118
+
119
+ if (syntax && syntax->size) {
120
+ BUFPUTSL(ob, "<pre lang=\"");
121
+ bufput(ob, syntax->data, syntax->size);
122
+ BUFPUTSL(ob, "\"><code>");
123
+ } else
124
+ BUFPUTSL(ob, "<pre><code>");
125
+
126
+ if (text)
127
+ lus_attr_escape(ob, text->data, text->size);
128
+
120
129
  BUFPUTSL(ob, "</code></pre>\n");
121
130
  }
122
131
 
data/lib/redcarpet.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.7.0'
29
+ VERSION = '1.7.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.7.0'
3
+ s.version = '1.7.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-15'
6
+ s.date = '2011-04-16'
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: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 7
9
- - 0
10
- version: 1.7.0
9
+ - 1
10
+ version: 1.7.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-15 00:00:00 +03:00
19
+ date: 2011-04-16 00:00:00 +03:00
20
20
  default_executable:
21
21
  dependencies: []
22
22