From 6168b5e286434cd81e2c9ea4b324305272c0ed4c Mon Sep 17 00:00:00 2001 From: Ronan Collobert Date: Thu, 10 Oct 2013 17:06:49 +0200 Subject: added easy render() function --- init.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 11e051e..c7f4742 100644 --- a/init.lua +++ b/init.lua @@ -3,6 +3,26 @@ local ffi = require 'ffi' require 'sundown.sdcdefs' require 'sundown.htmlcdefs' -local sundown = ffi.load(package.searchpath('libsundown', package.cpath)) +local C = ffi.load(package.searchpath('libsundown', package.cpath)) +local sundown = {C=C} + +function sundown.render(txt) + local callbacks = ffi.new('struct sd_callbacks') + local options = ffi.new('struct sdhtml_renderopt') + C.sdhtml_renderer(callbacks, options, 0) + + local markdown = C.sd_markdown_new(0xfff, 16, callbacks, options) + + local outbuf = ffi.new('struct sd_buf') + outbuf.data = nil + outbuf.size = 0 + outbuf.asize = 0 + outbuf.unit = 64 + + C.sd_markdown_render(outbuf, ffi.cast('const char*', txt), #txt, markdown) + C.sd_markdown_free(markdown) + + return ffi.string(outbuf.data, outbuf.size) +end return sundown -- cgit v1.2.3