93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'ext/markdown/gh-markdown.c', line 93
static VALUE rb_ghmd_to_html(VALUE self, VALUE rb_text, VALUE rb_mode)
{
struct buf *output_buf;
struct sd_markdown *md = NULL;
ID mode;
if (NIL_P(rb_text))
return Qnil;
Check_Type(rb_mode, T_SYMBOL);
mode = SYM2ID(rb_mode);
/* check for rendering mode */
if (mode == rb_intern("markdown")) {
md = g_markdown.md;
} else if (mode == rb_intern("gfm")) {
md = g_GFM.md;
} else if (mode == rb_intern("plaintext")) {
md = g_plaintext.md;
} else {
rb_raise(rb_eTypeError, "Invalid render mode");
}
Check_Type(rb_text, T_STRING);
/* initialize buffers */
output_buf = bufnew(128);
/* render the magic */
sd_markdown_render(output_buf, RSTRING_PTR(rb_text), RSTRING_LEN(rb_text), md);
/* build the Ruby string */
rb_text = geefem_str_new(output_buf->data, output_buf->size);
bufrelease(output_buf);
return rb_text;
}
|