redcarpet 2.0.0b3 → 2.0.0b4

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.

@@ -38,6 +38,14 @@ enum mkd_autolink {
38
38
  MKDA_EMAIL, /* e-mail link without explit mailto: */
39
39
  };
40
40
 
41
+ enum mkd_tableflags {
42
+ MKD_TABLE_ALIGN_L = 1,
43
+ MKD_TABLE_ALIGN_R = 2,
44
+ MKD_TABLE_ALIGN_CENTER = 3,
45
+ MKD_TABLE_ALIGNMASK = 3,
46
+ MKD_TABLE_HEADER = 4
47
+ };
48
+
41
49
  enum mkd_extensions {
42
50
  MKDEXT_NO_INTRA_EMPHASIS = (1 << 0),
43
51
  MKDEXT_TABLES = (1 << 1),
@@ -52,41 +60,43 @@ enum mkd_extensions {
52
60
  /* sd_callbacks - functions for rendering parsed data */
53
61
  struct sd_callbacks {
54
62
  /* block level callbacks - NULL skips the block */
55
- void (*blockcode)(struct buf *ob, struct buf *text, struct buf *lang, void *opaque);
56
- void (*blockquote)(struct buf *ob, struct buf *text, void *opaque);
57
- void (*blockhtml)(struct buf *ob, struct buf *text, void *opaque);
58
- void (*header)(struct buf *ob, struct buf *text, int level, void *opaque);
63
+ void (*blockcode)(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque);
64
+ void (*blockquote)(struct buf *ob, const struct buf *text, void *opaque);
65
+ void (*blockhtml)(struct buf *ob,const struct buf *text, void *opaque);
66
+ void (*header)(struct buf *ob, const struct buf *text, int level, void *opaque);
59
67
  void (*hrule)(struct buf *ob, void *opaque);
60
- void (*list)(struct buf *ob, struct buf *text, int flags, void *opaque);
61
- void (*listitem)(struct buf *ob, struct buf *text, int flags, void *opaque);
62
- void (*paragraph)(struct buf *ob, struct buf *text, void *opaque);
63
- void (*table)(struct buf *ob, struct buf *header, struct buf *body, void *opaque);
64
- void (*table_row)(struct buf *ob, struct buf *text, void *opaque);
65
- void (*table_cell)(struct buf *ob, struct buf *text, int flags, void *opaque);
68
+ void (*list)(struct buf *ob, const struct buf *text, int flags, void *opaque);
69
+ void (*listitem)(struct buf *ob, const struct buf *text, int flags, void *opaque);
70
+ void (*paragraph)(struct buf *ob, const struct buf *text, void *opaque);
71
+ void (*table)(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque);
72
+ void (*table_row)(struct buf *ob, const struct buf *text, void *opaque);
73
+ void (*table_cell)(struct buf *ob, const struct buf *text, int flags, void *opaque);
66
74
 
67
75
 
68
76
  /* span level callbacks - NULL or return 0 prints the span verbatim */
69
- int (*autolink)(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque);
70
- int (*codespan)(struct buf *ob, struct buf *text, void *opaque);
71
- int (*double_emphasis)(struct buf *ob, struct buf *text, void *opaque);
72
- int (*emphasis)(struct buf *ob, struct buf *text, void *opaque);
73
- int (*image)(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque);
77
+ int (*autolink)(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque);
78
+ int (*codespan)(struct buf *ob, const struct buf *text, void *opaque);
79
+ int (*double_emphasis)(struct buf *ob, const struct buf *text, void *opaque);
80
+ int (*emphasis)(struct buf *ob, const struct buf *text, void *opaque);
81
+ int (*image)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque);
74
82
  int (*linebreak)(struct buf *ob, void *opaque);
75
- int (*link)(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque);
76
- int (*raw_html_tag)(struct buf *ob, struct buf *tag, void *opaque);
77
- int (*triple_emphasis)(struct buf *ob, struct buf *text, void *opaque);
78
- int (*strikethrough)(struct buf *ob, struct buf *text, void *opaque);
79
- int (*superscript)(struct buf *ob, struct buf *text, void *opaque);
83
+ int (*link)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque);
84
+ int (*raw_html_tag)(struct buf *ob, const struct buf *tag, void *opaque);
85
+ int (*triple_emphasis)(struct buf *ob, const struct buf *text, void *opaque);
86
+ int (*strikethrough)(struct buf *ob, const struct buf *text, void *opaque);
87
+ int (*superscript)(struct buf *ob, const struct buf *text, void *opaque);
80
88
 
81
89
  /* low level callbacks - NULL copies input directly into the output */
82
- void (*entity)(struct buf *ob, struct buf *entity, void *opaque);
83
- void (*normal_text)(struct buf *ob, struct buf *text, void *opaque);
90
+ void (*entity)(struct buf *ob, const struct buf *entity, void *opaque);
91
+ void (*normal_text)(struct buf *ob, const struct buf *text, void *opaque);
84
92
 
85
93
  /* header and footer */
86
94
  void (*doc_header)(struct buf *ob, void *opaque);
87
95
  void (*doc_footer)(struct buf *ob, void *opaque);
88
96
  };
89
97
 
98
+ struct sd_markdown;
99
+
90
100
  /*********
91
101
  * FLAGS *
92
102
  *********/
@@ -95,19 +105,23 @@ struct sd_callbacks {
95
105
  #define MKD_LIST_ORDERED 1
96
106
  #define MKD_LI_BLOCK 2 /* <li> containing block data */
97
107
 
98
- #define MKD_TABLE_ALIGN_L (1 << 0)
99
- #define MKD_TABLE_ALIGN_R (1 << 1)
100
- #define MKD_TABLE_ALIGN_CENTER (MKD_TABLE_ALIGN_L | MKD_TABLE_ALIGN_R)
101
-
102
108
  /**********************
103
109
  * EXPORTED FUNCTIONS *
104
110
  **********************/
105
111
 
106
- /* sd_markdown * parses the input buffer and renders it into the output buffer */
112
+ extern struct sd_markdown *
113
+ sd_markdown_new(
114
+ unsigned int extensions,
115
+ size_t max_nesting,
116
+ const struct sd_callbacks *callbacks,
117
+ void *opaque);
118
+
119
+ extern void
120
+ sd_markdown_render(struct buf *ob, const uint8_t *document, size_t doc_size, struct sd_markdown *md);
121
+
107
122
  extern void
108
- sd_markdown(struct buf *ob, const struct buf *ib, unsigned int extensions, const struct sd_callbacks *rndr, void *opaque);
123
+ sd_markdown_free(struct sd_markdown *md);
109
124
 
110
- /* sd_version * returns the library version as major.minor.rev */
111
125
  extern void
112
126
  sd_version(int *major, int *minor, int *revision);
113
127
 
@@ -20,82 +20,108 @@ VALUE rb_cMarkdown;
20
20
 
21
21
  extern VALUE rb_cRenderBase;
22
22
 
23
- static void rb_redcarpet_md_flags(VALUE ruby_obj, unsigned int *enabled_extensions_p)
23
+ static void rb_redcarpet_md_flags(VALUE hash, unsigned int *enabled_extensions_p)
24
24
  {
25
25
  unsigned int extensions = 0;
26
26
 
27
27
  /**
28
- * Markdown extensions -- all disabled by default
28
+ * Markdown extensions -- all disabled by default
29
29
  */
30
- if (rb_funcall(ruby_obj, rb_intern("no_intra_emphasis"), 0) == Qtrue)
30
+ if (rb_hash_lookup(hash, CSTR2SYM("no_intra_emphasis")) == Qtrue)
31
31
  extensions |= MKDEXT_NO_INTRA_EMPHASIS;
32
32
 
33
- if (rb_funcall(ruby_obj, rb_intern("tables"), 0) == Qtrue)
33
+ if (rb_hash_lookup(hash, CSTR2SYM("tables")) == Qtrue)
34
34
  extensions |= MKDEXT_TABLES;
35
35
 
36
- if (rb_funcall(ruby_obj, rb_intern("fenced_code_blocks"), 0) == Qtrue)
36
+ if (rb_hash_lookup(hash, CSTR2SYM("fenced_code_blocks")) == Qtrue)
37
37
  extensions |= MKDEXT_FENCED_CODE;
38
38
 
39
- if (rb_funcall(ruby_obj, rb_intern("autolink"), 0) == Qtrue)
39
+ if (rb_hash_lookup(hash, CSTR2SYM("autolink")) == Qtrue)
40
40
  extensions |= MKDEXT_AUTOLINK;
41
41
 
42
- if (rb_funcall(ruby_obj, rb_intern("strikethrough"), 0) == Qtrue)
42
+ if (rb_hash_lookup(hash, CSTR2SYM("strikethrough")) == Qtrue)
43
43
  extensions |= MKDEXT_STRIKETHROUGH;
44
44
 
45
- if (rb_funcall(ruby_obj, rb_intern("lax_html_blocks"), 0) == Qtrue)
45
+ if (rb_hash_lookup(hash, CSTR2SYM("lax_html_blocks")) == Qtrue)
46
46
  extensions |= MKDEXT_LAX_HTML_BLOCKS;
47
47
 
48
- if (rb_funcall(ruby_obj, rb_intern("space_after_headers"), 0) == Qtrue)
48
+ if (rb_hash_lookup(hash, CSTR2SYM("space_after_headers")) == Qtrue)
49
49
  extensions |= MKDEXT_SPACE_HEADERS;
50
50
 
51
- if (rb_funcall(ruby_obj, rb_intern("superscript"), 0) == Qtrue)
51
+ if (rb_hash_lookup(hash, CSTR2SYM("superscript")) == Qtrue)
52
52
  extensions |= MKDEXT_SUPERSCRIPT;
53
53
 
54
54
  *enabled_extensions_p = extensions;
55
55
  }
56
56
 
57
- static VALUE rb_redcarpet_md_render_with(VALUE self, VALUE rb_rndr, VALUE text)
57
+ static void
58
+ rb_redcarpet_md__free(void *markdown)
58
59
  {
59
- VALUE result;
60
+ sd_markdown_free((struct sd_markdown *)markdown);
61
+ }
62
+
63
+ static VALUE rb_redcarpet_md__new(int argc, VALUE *argv, VALUE klass)
64
+ {
65
+ VALUE rb_markdown, rb_rndr, hash;
66
+ unsigned int extensions = 0;
60
67
 
61
68
  struct rb_redcarpet_rndr *rndr;
62
- struct buf input_buf, *output_buf;
63
- unsigned int enabled_extensions = 0;
69
+ struct sd_markdown *markdown;
64
70
 
65
- Check_Type(text, T_STRING);
71
+ if (rb_scan_args(argc, argv, "11", &rb_rndr, &hash) == 2)
72
+ rb_redcarpet_md_flags(hash, &extensions);
73
+
74
+ if (rb_obj_is_kind_of(rb_rndr, rb_cClass))
75
+ rb_rndr = rb_funcall(rb_rndr, rb_intern("new"), 0);
66
76
 
67
77
  if (!rb_obj_is_kind_of(rb_rndr, rb_cRenderBase))
68
- rb_raise(rb_eTypeError, "Invalid Renderer instance");
78
+ rb_raise(rb_eTypeError, "Invalid Renderer instance given");
79
+
80
+ Data_Get_Struct(rb_rndr, struct rb_redcarpet_rndr, rndr);
81
+
82
+ markdown = sd_markdown_new(extensions, 16, &rndr->callbacks, &rndr->options);
83
+ if (!markdown)
84
+ rb_raise(rb_eRuntimeError, "Failed to create new Renderer class");
85
+
86
+ rb_markdown = Data_Wrap_Struct(klass, NULL, rb_redcarpet_md__free, markdown);
87
+ rb_iv_set(rb_markdown, "@renderer", rb_rndr);
88
+
89
+ return rb_markdown;
90
+ }
91
+
92
+ static VALUE rb_redcarpet_md_render(VALUE self, VALUE text)
93
+ {
94
+ VALUE rb_rndr;
95
+ struct buf *output_buf;
96
+ struct sd_markdown *markdown;
97
+
98
+ Check_Type(text, T_STRING);
99
+
100
+ rb_rndr = rb_iv_get(self, "@renderer");
101
+ Data_Get_Struct(self, struct sd_markdown, markdown);
69
102
 
70
103
  if (rb_respond_to(rb_rndr, rb_intern("preprocess")))
71
104
  text = rb_funcall(rb_rndr, rb_intern("preprocess"), 1, text);
72
105
 
73
- Data_Get_Struct(rb_rndr, struct rb_redcarpet_rndr, rndr);
74
-
75
106
  /* initialize buffers */
76
- memset(&input_buf, 0x0, sizeof(struct buf));
77
- input_buf.data = RSTRING_PTR(text);
78
- input_buf.size = RSTRING_LEN(text);
79
-
80
107
  output_buf = bufnew(128);
81
108
 
82
109
  /* render the magic */
83
- rb_redcarpet_md_flags(self, &enabled_extensions);
84
- sd_markdown(output_buf, &input_buf, enabled_extensions, &rndr->callbacks, &rndr->options);
85
- result = rb_str_new(output_buf->data, output_buf->size);
86
- rb_enc_copy(result, text);
110
+ sd_markdown_render(
111
+ output_buf,
112
+ RSTRING_PTR(text),
113
+ RSTRING_LEN(text),
114
+ markdown);
115
+
116
+ /* build the Ruby string */
117
+ text = redcarpet_str_new(output_buf->data, output_buf->size);
87
118
 
88
119
  bufrelease(output_buf);
89
120
 
90
121
  if (rb_respond_to(rb_rndr, rb_intern("postprocess")))
91
- result = rb_funcall(rb_rndr, rb_intern("postprocess"), 1, result);
92
-
93
- return result;
94
- }
122
+ text = rb_funcall(rb_rndr, rb_intern("postprocess"), 1, text);
95
123
 
96
- static VALUE rb_redcarpet_md_render(VALUE self, VALUE text)
97
- {
98
- return rb_redcarpet_md_render_with(self, rb_iv_get(self, "@renderer"), text);
124
+ return text;
99
125
  }
100
126
 
101
127
  void Init_redcarpet()
@@ -103,8 +129,8 @@ void Init_redcarpet()
103
129
  rb_mRedcarpet = rb_define_module("Redcarpet");
104
130
 
105
131
  rb_cMarkdown = rb_define_class_under(rb_mRedcarpet, "Markdown", rb_cObject);
132
+ rb_define_singleton_method(rb_cMarkdown, "new", rb_redcarpet_md__new, -1);
106
133
  rb_define_method(rb_cMarkdown, "render", rb_redcarpet_md_render, 1);
107
- rb_define_method(rb_cMarkdown, "render_with", rb_redcarpet_md_render_with, 2);
108
134
 
109
135
  Init_redcarpet_rndr();
110
136
  }
@@ -41,33 +41,33 @@ VALUE rb_cRenderHTML_TOC;
41
41
  VALUE rb_mSmartyPants;
42
42
 
43
43
  static inline VALUE
44
- buf2str(struct buf *text)
44
+ buf2str(const struct buf *text)
45
45
  {
46
46
  if (!text || !text->size) return Qnil;
47
- return rb_str_new(text->data, text->size);
47
+ return redcarpet_str_new(text->data, text->size);
48
48
  }
49
49
 
50
50
 
51
51
  static void
52
- rndr_blockcode(struct buf *ob, struct buf *text, struct buf *lang, void *opaque)
52
+ rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
53
53
  {
54
54
  BLOCK_CALLBACK("block_code", 2, buf2str(text), buf2str(lang));
55
55
  }
56
56
 
57
57
  static void
58
- rndr_blockquote(struct buf *ob, struct buf *text, void *opaque)
58
+ rndr_blockquote(struct buf *ob, const struct buf *text, void *opaque)
59
59
  {
60
60
  BLOCK_CALLBACK("block_quote", 1, buf2str(text));
61
61
  }
62
62
 
63
63
  static void
64
- rndr_raw_block(struct buf *ob, struct buf *text, void *opaque)
64
+ rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
65
65
  {
66
66
  BLOCK_CALLBACK("block_html", 1, buf2str(text));
67
67
  }
68
68
 
69
69
  static void
70
- rndr_header(struct buf *ob, struct buf *text, int level, void *opaque)
70
+ rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
71
71
  {
72
72
  BLOCK_CALLBACK("header", 2, buf2str(text), INT2FIX(level));
73
73
  }
@@ -79,39 +79,39 @@ rndr_hrule(struct buf *ob, void *opaque)
79
79
  }
80
80
 
81
81
  static void
82
- rndr_list(struct buf *ob, struct buf *text, int flags, void *opaque)
82
+ rndr_list(struct buf *ob, const struct buf *text, int flags, void *opaque)
83
83
  {
84
84
  BLOCK_CALLBACK("list", 2, buf2str(text),
85
85
  (flags & MKD_LIST_ORDERED) ? CSTR2SYM("ordered") : CSTR2SYM("unordered"));
86
86
  }
87
87
 
88
88
  static void
89
- rndr_listitem(struct buf *ob, struct buf *text, int flags, void *opaque)
89
+ rndr_listitem(struct buf *ob, const struct buf *text, int flags, void *opaque)
90
90
  {
91
91
  BLOCK_CALLBACK("list_item", 2, buf2str(text),
92
92
  (flags & MKD_LIST_ORDERED) ? CSTR2SYM("ordered") : CSTR2SYM("unordered"));
93
93
  }
94
94
 
95
95
  static void
96
- rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
96
+ rndr_paragraph(struct buf *ob, const struct buf *text, void *opaque)
97
97
  {
98
98
  BLOCK_CALLBACK("paragraph", 1, buf2str(text));
99
99
  }
100
100
 
101
101
  static void
102
- rndr_table(struct buf *ob, struct buf *header, struct buf *body, void *opaque)
102
+ rndr_table(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque)
103
103
  {
104
104
  BLOCK_CALLBACK("table", 2, buf2str(header), buf2str(body));
105
105
  }
106
106
 
107
107
  static void
108
- rndr_tablerow(struct buf *ob, struct buf *text, void *opaque)
108
+ rndr_tablerow(struct buf *ob, const struct buf *text, void *opaque)
109
109
  {
110
110
  BLOCK_CALLBACK("table_row", 1, buf2str(text));
111
111
  }
112
112
 
113
113
  static void
114
- rndr_tablecell(struct buf *ob, struct buf *text, int align, void *opaque)
114
+ rndr_tablecell(struct buf *ob, const struct buf *text, int align, void *opaque)
115
115
  {
116
116
  VALUE rb_align;
117
117
 
@@ -143,32 +143,32 @@ rndr_tablecell(struct buf *ob, struct buf *text, int align, void *opaque)
143
143
  * SPAN LEVEL
144
144
  */
145
145
  static int
146
- rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque)
146
+ rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
147
147
  {
148
148
  SPAN_CALLBACK("autolink", 2, buf2str(link),
149
149
  type == MKDA_NORMAL ? CSTR2SYM("url") : CSTR2SYM("email"));
150
150
  }
151
151
 
152
152
  static int
153
- rndr_codespan(struct buf *ob, struct buf *text, void *opaque)
153
+ rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
154
154
  {
155
155
  SPAN_CALLBACK("codespan", 1, buf2str(text));
156
156
  }
157
157
 
158
158
  static int
159
- rndr_double_emphasis(struct buf *ob, struct buf *text, void *opaque)
159
+ rndr_double_emphasis(struct buf *ob, const struct buf *text, void *opaque)
160
160
  {
161
161
  SPAN_CALLBACK("double_emphasis", 1, buf2str(text));
162
162
  }
163
163
 
164
164
  static int
165
- rndr_emphasis(struct buf *ob, struct buf *text, void *opaque)
165
+ rndr_emphasis(struct buf *ob, const struct buf *text, void *opaque)
166
166
  {
167
167
  SPAN_CALLBACK("emphasis", 1, buf2str(text));
168
168
  }
169
169
 
170
170
  static int
171
- rndr_image(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque)
171
+ rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
172
172
  {
173
173
  SPAN_CALLBACK("image", 3, buf2str(link), buf2str(title), buf2str(alt));
174
174
  }
@@ -180,31 +180,31 @@ rndr_linebreak(struct buf *ob, void *opaque)
180
180
  }
181
181
 
182
182
  static int
183
- rndr_link(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque)
183
+ rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
184
184
  {
185
185
  SPAN_CALLBACK("link", 3, buf2str(link), buf2str(title), buf2str(content));
186
186
  }
187
187
 
188
188
  static int
189
- rndr_raw_html(struct buf *ob, struct buf *text, void *opaque)
189
+ rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
190
190
  {
191
191
  SPAN_CALLBACK("raw_html", 1, buf2str(text));
192
192
  }
193
193
 
194
194
  static int
195
- rndr_triple_emphasis(struct buf *ob, struct buf *text, void *opaque)
195
+ rndr_triple_emphasis(struct buf *ob, const struct buf *text, void *opaque)
196
196
  {
197
197
  SPAN_CALLBACK("triple_emphasis", 1, buf2str(text));
198
198
  }
199
199
 
200
200
  static int
201
- rndr_strikethrough(struct buf *ob, struct buf *text, void *opaque)
201
+ rndr_strikethrough(struct buf *ob, const struct buf *text, void *opaque)
202
202
  {
203
203
  SPAN_CALLBACK("strikethrough", 1, buf2str(text));
204
204
  }
205
205
 
206
206
  static int
207
- rndr_superscript(struct buf *ob, struct buf *text, void *opaque)
207
+ rndr_superscript(struct buf *ob, const struct buf *text, void *opaque)
208
208
  {
209
209
  SPAN_CALLBACK("superscript", 1, buf2str(text));
210
210
  }
@@ -213,13 +213,13 @@ rndr_superscript(struct buf *ob, struct buf *text, void *opaque)
213
213
  * direct writes
214
214
  */
215
215
  static void
216
- rndr_entity(struct buf *ob, struct buf *text, void *opaque)
216
+ rndr_entity(struct buf *ob, const struct buf *text, void *opaque)
217
217
  {
218
218
  BLOCK_CALLBACK("entity", 1, buf2str(text));
219
219
  }
220
220
 
221
221
  static void
222
- rndr_normal_text(struct buf *ob, struct buf *text, void *opaque)
222
+ rndr_normal_text(struct buf *ob, const struct buf *text, void *opaque)
223
223
  {
224
224
  BLOCK_CALLBACK("normal_text", 1, buf2str(text));
225
225
  }
@@ -357,7 +357,7 @@ static VALUE rb_redcarpet_html_init(int argc, VALUE *argv, VALUE self)
357
357
  render_flags |= HTML_SKIP_HTML;
358
358
 
359
359
  /* no_image */
360
- if (rb_hash_aref(hash, CSTR2SYM("no_image")) == Qtrue)
360
+ if (rb_hash_aref(hash, CSTR2SYM("no_images")) == Qtrue)
361
361
  render_flags |= HTML_SKIP_IMAGES;
362
362
 
363
363
  /* no_links */
@@ -379,7 +379,7 @@ static VALUE rb_redcarpet_html_init(int argc, VALUE *argv, VALUE self)
379
379
  render_flags |= HTML_HARD_WRAP;
380
380
 
381
381
  if (rb_hash_aref(hash, CSTR2SYM("xhtml")) == Qtrue)
382
- render_flags |= HTML_USE_XHTML;
382
+ render_flags |= HTML_USE_XHTML;
383
383
  }
384
384
 
385
385
  sdhtml_renderer(&rndr->callbacks, (struct html_renderopt *)&rndr->options.html, render_flags);
@@ -402,20 +402,14 @@ static VALUE rb_redcarpet_htmltoc_init(VALUE self)
402
402
  static VALUE rb_redcarpet_smartypants_render(VALUE self, VALUE text)
403
403
  {
404
404
  VALUE result;
405
- struct buf input_buf, *output_buf;
405
+ struct buf *output_buf;
406
406
 
407
407
  Check_Type(text, T_STRING);
408
408
 
409
- memset(&input_buf, 0x0, sizeof(struct buf));
410
- input_buf.data = RSTRING_PTR(text);
411
- input_buf.size = RSTRING_LEN(text);
412
-
413
409
  output_buf = bufnew(128);
414
- bufgrow(output_buf, RSTRING_LEN(text) * 1.1f);
415
410
 
416
- sdhtml_smartypants(output_buf, &input_buf);
417
- result = rb_str_new(output_buf->data, output_buf->size);
418
- rb_enc_copy(result, text);
411
+ sdhtml_smartypants(output_buf, RSTRING_PTR(text), RSTRING_LEN(text));
412
+ result = redcarpet_str_new(output_buf->data, output_buf->size);
419
413
 
420
414
  bufrelease(output_buf);
421
415
  return result;