diff options
author | Ronan Collobert <ronan@collobert.com> | 2013-10-10 19:06:49 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2013-10-10 19:06:49 +0400 |
commit | 6168b5e286434cd81e2c9ea4b324305272c0ed4c (patch) | |
tree | 325431ae14fbaf39bfcb50e1f516e0988bdce59c | |
parent | 05e6170f0e025e2ef4696c21225a22a2838f347e (diff) |
added easy render() function
-rw-r--r-- | init.lua | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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 |