Skip to content

Commit dd354a6

Browse files
authored
Merge pull request #31 from gjtorikian/fixups
Update cmark to 0.27.1
2 parents f2e3beb + 2c1b7b6 commit dd354a6

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

ext/commonmarker/cmark

Submodule cmark updated from 636d601 to 4d2f310

ext/commonmarker/commonmarker.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ static VALUE sym_image;
2828
static VALUE sym_bullet_list;
2929
static VALUE sym_ordered_list;
3030

31+
static VALUE encode_utf8_string(char *c_string) {
32+
VALUE string = rb_str_new2(c_string);
33+
int enc = rb_enc_find_index("UTF-8");
34+
rb_enc_associate_index(string, enc);
35+
return string;
36+
}
37+
3138
static void rb_mark_c_struct(void *data) {
3239
cmark_node *node = data;
3340
cmark_node *child;
@@ -231,7 +238,7 @@ static VALUE rb_node_get_string_content(VALUE self) {
231238
rb_raise(rb_mNodeError, "could not get string content");
232239
}
233240

234-
return rb_str_new2(text);
241+
return encode_utf8_string(text);
235242
}
236243

237244
/*

ext/commonmarker/commonmarker.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include "cmark.h"
99
#include "ruby.h"
10+
#include "ruby/encoding.h"
1011

1112
#define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
1213

test/test_encoding.rb

+7
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ def test_encoding
99
render = doc.to_html
1010
assert_equal render.rstrip, '<p>This curly quote “makes commonmarker throw an exception”.</p>'
1111
end
12+
13+
def test_string_content_is_utf8
14+
doc = CommonMarker.render_doc('Hi *there*')
15+
text = doc.first_child.last_child.first_child
16+
assert_equal text.string_content, 'there'
17+
assert_equal text.string_content.encoding.name, 'UTF-8'
18+
end
1219
end

0 commit comments

Comments
 (0)