func render(w io.Writer, extensions, renderModes, rndr uint, p []byte) (n int, err error) { var md *C.struct_sd_markdown var ob *C.struct_buf var ib C.struct_buf var callbacks C.struct_sd_callbacks var options C.struct_html_renderopt ib.data = (*C.uint8_t)(unsafe.Pointer(&p[0])) ib.size = C.size_t(len(p)) ib.asize = ib.size ib.unit = C.size_t(0) ob = C.bufnew(128) C.bufgrow(ob, C.size_t(float64(ib.size)*1.2)) switch rndr { case HTMLRenderer: C.sdhtml_renderer(&callbacks, &options, C.uint(renderModes&^HTML_SMARTYPANTS)) case TOCRenderer: C.sdhtml_toc_renderer(&callbacks, &options) default: panic("unknown renderer") } //C.sd_markdown(ob, &ib, C.uint(extensions), &callbacks, unsafe.Pointer(&options)) md = C.sd_markdown_new(0, 16, &callbacks, unsafe.Pointer(&options)) C.sd_markdown_render(ob, ib.data, ib.size, md) C.sd_markdown_free(md) if renderModes&HTML_SMARTYPANTS > 0 { sb := C.bufnew(128) C.sdhtml_smartypants(sb, ob.data, ob.size) n, err = w.Write((*[1 << 30]byte)(unsafe.Pointer(sb.data))[0:sb.size]) C.bufrelease(sb) } else { n, err = w.Write((*[1 << 30]byte)(unsafe.Pointer(ob.data))[0:ob.size]) } C.bufrelease(ob) return }
func Markdownify(md string) string { buf := C.markdownify(C.CString(md)) html := C.GoString((*buf).data) C.bufrelease(buf) return html }