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:
Diffstat (limited to 'init.lua')
-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