Exemplo n.º 1
0
static VALUE rb_redcarpet_md_render(VALUE self, VALUE text)
{
	VALUE rb_rndr;
	struct buf *output_buf;
	struct sd_markdown *markdown;

	Check_Type(text, T_STRING);
	check_utf8_encoding(text);

	rb_rndr = rb_iv_get(self, "@renderer");
	Data_Get_Struct(self, struct sd_markdown, markdown);

	if (rb_respond_to(rb_rndr, rb_intern("preprocess")))
		text = rb_funcall(rb_rndr, rb_intern("preprocess"), 1, text);

	/* initialize buffers */
	output_buf = bufnew(128);

	/* render the magic */
	sd_markdown_render(
		output_buf,
		RSTRING_PTR(text),
		RSTRING_LEN(text),
		markdown);

	/* build the Ruby string */
	text = redcarpet_str_new(output_buf->data, output_buf->size);

	bufrelease(output_buf);

	if (rb_respond_to(rb_rndr, rb_intern("postprocess")))
		text = rb_funcall(rb_rndr, rb_intern("postprocess"), 1, text);

	return text;
}
Exemplo n.º 2
0
static VALUE rb_redcarpet_smartypants_render(VALUE self, VALUE text)
{
	VALUE result;
	struct buf *output_buf;

	Check_Type(text, T_STRING);

	output_buf = bufnew(128);

	sdhtml_smartypants(output_buf, RSTRING_PTR(text), RSTRING_LEN(text));
	result = redcarpet_str_new(output_buf->data, output_buf->size, rb_enc_get(text));

	bufrelease(output_buf);
	return result;
}
Exemplo n.º 3
0
static inline VALUE
buf2str(const struct buf *text)
{
    if (!text || !text->size) return Qnil;
    return redcarpet_str_new(text->data, text->size);
}