redcarpet 1.13.0 → 1.13.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.

@@ -1100,6 +1100,26 @@ is_codefence(char *data, size_t size, struct buf *syntax)
1100
1100
  return i + 1;
1101
1101
  }
1102
1102
 
1103
+ /* is_atxheader • returns whether the line is a hash-prefixed header */
1104
+ static int
1105
+ is_atxheader(struct render *rndr, char *data, size_t size)
1106
+ {
1107
+ if (data[0] != '#')
1108
+ return 0;
1109
+
1110
+ if (rndr->ext_flags & MKDEXT_SPACE_HEADERS) {
1111
+ size_t level = 0;
1112
+
1113
+ while (level < size && level < 6 && data[level] == '#')
1114
+ level++;
1115
+
1116
+ if (level < size && data[level] != ' ' && data[level] != '\t')
1117
+ return 0;
1118
+ }
1119
+
1120
+ return 1;
1121
+ }
1122
+
1103
1123
  /* is_headerline • returns whether the line is a setext-style hdr underline */
1104
1124
  static int
1105
1125
  is_headerline(char *data, size_t size)
@@ -1248,7 +1268,7 @@ parse_paragraph(struct buf *ob, struct render *rndr, char *data, size_t size)
1248
1268
  }
1249
1269
  }
1250
1270
 
1251
- if (data[i] == '#' || is_hrule(data + i, size - i)) {
1271
+ if (is_atxheader(rndr, data + i, size - i) || is_hrule(data + i, size - i)) {
1252
1272
  end = i;
1253
1273
  break;
1254
1274
  }
@@ -1532,7 +1552,6 @@ parse_list(struct buf *ob, struct render *rndr, char *data, size_t size, int fla
1532
1552
  return i;
1533
1553
  }
1534
1554
 
1535
-
1536
1555
  /* parse_atxheader • parsing of atx-style headers */
1537
1556
  static size_t
1538
1557
  parse_atxheader(struct buf *ob, struct render *rndr, char *data, size_t size)
@@ -1540,9 +1559,6 @@ parse_atxheader(struct buf *ob, struct render *rndr, char *data, size_t size)
1540
1559
  size_t level = 0;
1541
1560
  size_t i, end, skip;
1542
1561
 
1543
- if (!size || data[0] != '#')
1544
- return 0;
1545
-
1546
1562
  while (level < size && level < 6 && data[level] == '#')
1547
1563
  level++;
1548
1564
 
@@ -1887,7 +1903,7 @@ parse_block(struct buf *ob, struct render *rndr, char *data, size_t size)
1887
1903
  txt_data = data + beg;
1888
1904
  end = size - beg;
1889
1905
 
1890
- if (data[beg] == '#')
1906
+ if (is_atxheader(rndr, txt_data, end))
1891
1907
  beg += parse_atxheader(ob, rndr, txt_data, end);
1892
1908
 
1893
1909
  else if (data[beg] == '<' && rndr->make.blockhtml &&
@@ -39,6 +39,7 @@ enum mkd_extensions {
39
39
  MKDEXT_AUTOLINK = (1 << 3),
40
40
  MKDEXT_STRIKETHROUGH = (1 << 4),
41
41
  MKDEXT_LAX_HTML_BLOCKS = (1 << 5),
42
+ MKDEXT_SPACE_HEADERS = (1 << 6),
42
43
  };
43
44
 
44
45
  /* mkd_renderer • functions for rendering parsed data */
@@ -72,6 +72,9 @@ static void rb_redcarpet__get_flags(VALUE ruby_obj,
72
72
  if (rb_funcall(ruby_obj, rb_intern("lax_htmlblock"), 0) == Qtrue)
73
73
  extensions |= MKDEXT_LAX_HTML_BLOCKS;
74
74
 
75
+ if (rb_funcall(ruby_obj, rb_intern("space_header"), 0) == Qtrue)
76
+ extensions |= MKDEXT_SPACE_HEADERS;
77
+
75
78
  *enabled_extensions_p = extensions;
76
79
  *render_flags_p = render_flags;
77
80
  }
data/lib/redcarpet.rb CHANGED
@@ -26,7 +26,7 @@
26
26
  # end
27
27
  #
28
28
  class Redcarpet
29
- VERSION = '1.13.0'
29
+ VERSION = '1.13.1'
30
30
 
31
31
  # Original Markdown formatted text.
32
32
  attr_reader :text
@@ -79,6 +79,9 @@ class Redcarpet
79
79
  # Generate XHTML 1.0 compilant self-closing tags (e.g. <br/>)
80
80
  attr_accessor :xhtml
81
81
 
82
+ # Force a space between header hashes and the header itself
83
+ attr_accessor :space_header
84
+
82
85
  def initialize(text, *extensions)
83
86
  @text = text
84
87
  extensions.each { |e| send("#{e}=", true) }
data/redcarpet.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'redcarpet'
3
- s.version = '1.13.0'
3
+ s.version = '1.13.1'
4
4
  s.summary = "Ruby bindings for libupskirt"
5
5
  s.description = 'A fast and safe Markdown to (X)HTML parser'
6
6
  s.date = '2011-05-06'
@@ -233,4 +233,9 @@ text
233
233
 
234
234
  assert rd.to_html =~ /<br>/
235
235
  end
236
+
237
+ def test_spaced_headers
238
+ rd = Redcarpet.new("#123 a header yes\n", :space_header)
239
+ assert rd.to_html !~ /<h1>/
240
+ end
236
241
  end
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: 35
4
+ hash: 33
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 13
9
- - 0
10
- version: 1.13.0
9
+ - 1
10
+ version: 1.13.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Natacha Port\xC3\xA9"