コード例 #1
0
ファイル: upskirt.c プロジェクト: buu700/upskirt.go
/* char* markdownify (char *in) { */
struct buf* markdownify (char *in) {
	struct buf *ib, *ob, *ob1;
	struct mkd_renderer renderer;

	/* reading everything */
	ib = bufnew (READ_UNIT);
	ib->size = strlen (in);
	ib->data = in;
	
	ob = bufnew (OUTPUT_UNIT);
	ob->size = 0;
	
	ob1 = bufnew (OUTPUT_UNIT);
	ob1->size = 0;

	
	/* Markdown parse */
	upshtml_renderer (&renderer, 65535);
	ups_markdown (ob, ib, &renderer, 65535);
	upshtml_free_renderer (&renderer);
	bufrelease (ib);
		
	upshtml_smartypants (ob1, ob);
	bufrelease (ob);
	
	
	return ob1;
}
コード例 #2
0
ファイル: redcarpet.c プロジェクト: nono/redcarpet
static VALUE rb_redcarpet__render(VALUE self, RendererType render_type)
{
    VALUE text = rb_funcall(self, rb_intern("text"), 0);
    VALUE result;

    struct buf input_buf, *output_buf;
    struct mkd_renderer renderer;
    unsigned int enabled_extensions, render_flags;

    Check_Type(text, T_STRING);

    memset(&input_buf, 0x0, sizeof(struct buf));
    input_buf.data = RSTRING_PTR(text);
    input_buf.size = RSTRING_LEN(text);

    output_buf = bufnew(128);
    bufgrow(output_buf, RSTRING_LEN(text) * 1.2f);

    rb_redcarpet__get_flags(self, &enabled_extensions, &render_flags);

    switch (render_type) {
    case REDCARPET_RENDER_HTML:
        upshtml_renderer(&renderer, render_flags);
        break;

    case REDCARPET_RENDER_TOC:
        upshtml_toc_renderer(&renderer);
        break;

    default:
        return Qnil;
    }

    ups_markdown(output_buf, &input_buf, &renderer, enabled_extensions);

    if (rb_funcall(self, rb_intern("smart"), 0) == Qtrue) {
        struct buf *smart_buf = bufnew(128);
        upshtml_smartypants(smart_buf, output_buf);
        result = rb_str_new(smart_buf->data, smart_buf->size);
        bufrelease(smart_buf);
    } else {
        result = rb_str_new(output_buf->data, output_buf->size);
    }

    bufrelease(output_buf);
    upshtml_free_renderer(&renderer);

    /* force the input encoding */
    if (rb_respond_to(text, rb_intern("encoding"))) {
        VALUE encoding = rb_funcall(text, rb_intern("encoding"), 0);
        rb_funcall(result, rb_intern("force_encoding"), 1, encoding);
    }

    return result;
}
コード例 #3
0
ファイル: misaka.c プロジェクト: heintz/misaka
static PyObject *
misaka_render(const char *text, unsigned int extensions,
                 unsigned int render_flags, char toc_only)
{
    struct buf *ib, *ob;
    struct mkd_renderer renderer;

    /* Input buffer */
    ib = bufnew(1);
    bufputs(ib, text);

    /* Output buffer */
    ob = bufnew(ib->size * 1.2);

    /* Parse Markdown */
    if (toc_only != -1) {
        upshtml_toc_renderer(&renderer);
    } else {
        upshtml_renderer(&renderer, render_flags);
    }

    ups_markdown(ob, ib, &renderer, extensions);
    upshtml_free_renderer(&renderer);

    /* Smartypants actions */
    if (render_flags & HTML_SMARTYPANTS)
    {
        struct buf *sb = bufnew(1);
        upshtml_smartypants(sb, ob);
        ob = bufdup(sb, sb->size); /* Duplicate Smartypants buffer to output buffer */
        bufrelease(sb); /* Cleanup Smartypants buffer */
    }

    /* Append a null terminator to the output buffer and make a Python string */
    bufnullterm(ob);
    PyObject *html = Py_BuildValue("s", ob->data);

    /* Cleanup */
    bufrelease(ib);
    bufrelease(ob);

    return html;
}