redcarpet 1.0.0 → 1.0.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.

@@ -936,6 +936,8 @@ parse_blockquote(struct buf *ob, struct render *rndr, char *data, size_t size, i
936
936
  return end;
937
937
  }
938
938
 
939
+ static size_t
940
+ parse_htmlblock(struct buf *ob, struct render *rndr, char *data, size_t size, int do_render);
939
941
 
940
942
  /* parse_blockquote • hanldes parsing of a regular paragraph */
941
943
  static size_t
@@ -946,16 +948,29 @@ parse_paragraph(struct buf *ob, struct render *rndr,
946
948
  struct buf work = { data, 0, 0, 0, 0 }; /* volatile working buffer */
947
949
 
948
950
  while (i < size) {
949
- for (end = i + 1; end < size && data[end - 1] != '\n';
950
- end += 1);
951
- if (is_empty(data + i, size - i)
952
- || (level = is_headerline(data + i, size - i)) != 0)
951
+ size_t html_size;
952
+
953
+ for (end = i + 1; end < size && data[end - 1] != '\n'; end++) /* empty */;
954
+
955
+ if (is_empty(data + i, size - i) || (level = is_headerline(data + i, size - i)) != 0)
956
+ break;
957
+
958
+ /* HTML blocks should not nest inside the paragraph, even if they
959
+ * are not separated by a blank line; we run `parse_htmlblock` without
960
+ * actually generating any output, to make sure that this is indeed
961
+ * a HTML block */
962
+ if (data[i] == '<' && rndr->make.blockhtml && parse_htmlblock(ob, rndr, data + i, size - i, 0)) {
963
+ end = i;
953
964
  break;
954
- if (data[i] == '#'
955
- || is_hrule(data + i, size - i)) {
965
+ }
966
+
967
+ if (data[i] == '#' || is_hrule(data + i, size - i)) {
956
968
  end = i;
957
- break; }
958
- i = end; }
969
+ break;
970
+ }
971
+
972
+ i = end;
973
+ }
959
974
 
960
975
  work.size = i;
961
976
  while (work.size && data[work.size - 1] == '\n')
@@ -1238,7 +1253,7 @@ htmlblock_end(struct html_tag *tag, char *data, size_t size) {
1238
1253
 
1239
1254
  /* parse_htmlblock • parsing of inline HTML block */
1240
1255
  static size_t
1241
- parse_htmlblock(struct buf *ob, struct render *rndr, char *data, size_t size) {
1256
+ parse_htmlblock(struct buf *ob, struct render *rndr, char *data, size_t size, int do_render) {
1242
1257
  size_t i, j = 0;
1243
1258
  struct html_tag *curtag;
1244
1259
  int found;
@@ -1250,43 +1265,48 @@ parse_htmlblock(struct buf *ob, struct render *rndr, char *data, size_t size) {
1250
1265
 
1251
1266
  /* handling of special cases */
1252
1267
  if (!curtag) {
1268
+
1253
1269
  /* HTML comment, laxist form */
1254
- if (size > 5 && data[1] == '!'
1255
- && data[2] == '-' && data[3] == '-') {
1270
+ if (size > 5 && data[1] == '!' && data[2] == '-' && data[3] == '-') {
1256
1271
  i = 5;
1257
- while (i < size
1258
- && !(data[i - 2] == '-' && data[i - 1] == '-'
1259
- && data[i] == '>'))
1260
- i += 1;
1261
- i += 1;
1272
+
1273
+ while (i < size && !(data[i - 2] == '-' && data[i - 1] == '-' && data[i] == '>'))
1274
+ i++;
1275
+
1276
+ i++;
1277
+
1262
1278
  if (i < size)
1263
1279
  j = is_empty(data + i, size - i);
1264
- if (j) {
1265
- work.size = i + j;
1266
- if (rndr->make.blockhtml)
1267
- rndr->make.blockhtml(ob, &work,
1268
- &rndr->make.render_options);
1269
- return work.size; } }
1280
+
1281
+ if (j) {
1282
+ work.size = i + j;
1283
+ if (do_render && rndr->make.blockhtml)
1284
+ rndr->make.blockhtml(ob, &work, &rndr->make.render_options);
1285
+ return work.size;
1286
+ }
1287
+ }
1270
1288
 
1271
1289
  /* HR, which is the only self-closing block tag considered */
1272
- if (size > 4
1273
- && (data[1] == 'h' || data[1] == 'H')
1274
- && (data[2] == 'r' || data[2] == 'R')) {
1290
+ if (size > 4 && (data[1] == 'h' || data[1] == 'H') && (data[2] == 'r' || data[2] == 'R')) {
1275
1291
  i = 3;
1276
1292
  while (i < size && data[i] != '>')
1277
1293
  i += 1;
1294
+
1278
1295
  if (i + 1 < size) {
1279
1296
  i += 1;
1280
1297
  j = is_empty(data + i, size - i);
1281
1298
  if (j) {
1282
1299
  work.size = i + j;
1283
- if (rndr->make.blockhtml)
1284
- rndr->make.blockhtml(ob, &work,
1285
- &rndr->make.render_options);
1286
- return work.size; } } }
1300
+ if (do_render && rndr->make.blockhtml)
1301
+ rndr->make.blockhtml(ob, &work, &rndr->make.render_options);
1302
+ return work.size;
1303
+ }
1304
+ }
1305
+ }
1287
1306
 
1288
1307
  /* no special case recognised */
1289
- return 0; }
1308
+ return 0;
1309
+ }
1290
1310
 
1291
1311
  /* looking for an unindented matching closing tag */
1292
1312
  /* followed by a blank line */
@@ -1311,24 +1331,32 @@ parse_htmlblock(struct buf *ob, struct render *rndr, char *data, size_t size) {
1311
1331
  if (!found && curtag != INS_TAG && curtag != DEL_TAG) {
1312
1332
  i = 1;
1313
1333
  while (i < size) {
1314
- i += 1;
1315
- while (i < size
1316
- && !(data[i - 1] == '<' && data[i] == '/'))
1317
- i += 1;
1318
- if (i + 2 + curtag->size >= size) break;
1319
- j = htmlblock_end(curtag, data + i - 1, size - i + 1);
1320
- if (j) {
1321
- i += j - 1;
1322
- found = 1;
1323
- break; } } }
1334
+ i++;
1335
+ while (i < size && !(data[i - 1] == '<' && data[i] == '/'))
1336
+ i++;
1337
+
1338
+ if (i + 2 + curtag->size >= size)
1339
+ break;
1340
+
1341
+ j = htmlblock_end(curtag, data + i - 1, size - i + 1);
1342
+
1343
+ if (j) {
1344
+ i += j - 1;
1345
+ found = 1;
1346
+ break;
1347
+ }
1348
+ }
1349
+ }
1324
1350
 
1325
1351
  if (!found) return 0;
1326
1352
 
1327
1353
  /* the end of the block has been found */
1328
1354
  work.size = i;
1329
- if (rndr->make.blockhtml)
1355
+ if (do_render && rndr->make.blockhtml)
1330
1356
  rndr->make.blockhtml(ob, &work, &rndr->make.render_options);
1331
- return i; }
1357
+
1358
+ return i;
1359
+ }
1332
1360
 
1333
1361
 
1334
1362
  /* parse_block • parsing of one block, returning next char to parse */
@@ -1347,7 +1375,7 @@ parse_block(struct buf *ob, struct render *rndr, char *data, size_t size, int de
1347
1375
  if (data[beg] == '#')
1348
1376
  beg += parse_atxheader(ob, rndr, txt_data, end);
1349
1377
  else if (data[beg] == '<' && rndr->make.blockhtml
1350
- && (i = parse_htmlblock(ob, rndr, txt_data, end)) != 0)
1378
+ && (i = parse_htmlblock(ob, rndr, txt_data, end, 1)) != 0)
1351
1379
  beg += i;
1352
1380
  else if ((i = is_empty(txt_data, end)) != 0)
1353
1381
  beg += i;
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.0.0'
29
+ VERSION = '1.0.1'
30
30
 
31
31
  # Original Markdown formatted text.
32
32
  attr_reader :text
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'redcarpet'
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
  s.summary = "Ruby bindings for libupskirt"
5
5
  s.date = '2011-03-29'
6
6
  s.email = 'vicent@github.com'
@@ -128,6 +128,16 @@ class MarkdownTest < Test::Unit::TestCase
128
128
  markdown.to_html
129
129
  end
130
130
 
131
+ def test_para_before_block_html_should_not_wrap_in_p_tag
132
+ markdown = Redcarpet.new(
133
+ "Things to watch out for\n" +
134
+ "<ul>\n<li>Blah</li>\n</ul>\n"
135
+ )
136
+ assert_equal "<p>Things to watch out for</p>\n\n" +
137
+ "<ul>\n<li>Blah</li>\n</ul>\n",
138
+ markdown.to_html
139
+ end
140
+
131
141
  # FIXME: These two tests are not really on the standard
132
142
  # def test_ul_with_zero_space_indent
133
143
  # markdown = Markdown.new("- foo\n\n- bar\n\n baz\n")
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Natacha Port\xC3\xA9"