Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/sundown-ffi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Collobert <ronan@collobert.com>2013-10-10 19:06:49 +0400
committerRonan Collobert <ronan@collobert.com>2013-10-10 19:06:49 +0400
commit6168b5e286434cd81e2c9ea4b324305272c0ed4c (patch)
tree325431ae14fbaf39bfcb50e1f516e0988bdce59c
parent05e6170f0e025e2ef4696c21225a22a2838f347e (diff)
added easy render() function
-rw-r--r--init.lua22
1 files changed, 21 insertions, 1 deletions
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