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

html.lua - github.com/torch/sundown-ffi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e106fc14f853e84a25a25b140817a593da4352bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local sundown = require 'sundown.env'
local ffi = require 'ffi'
local C = sundown.C

require 'sundown.sdcdefs'
require 'sundown.htmlcdefs'

local function 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 {render=render}