File: html.lua

package info (click to toggle)
lua-torch-sundown 0~20160829-g17ea705-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 324 kB
  • ctags: 310
  • sloc: ansic: 3,543; sh: 75; makefile: 9
file content (23 lines) | stat: -rw-r--r-- 649 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 sd_html_renderopt')
   C.sd_html_renderer(callbacks, options, 0)
   local markdown = C.sd_markdown_new(0xfff, 16, callbacks, options)

   local outbuf = C.sd_bufnew(64)
   C.sd_markdown_render(outbuf, ffi.cast('const char*', txt), #txt, markdown)
   C.sd_markdown_free(markdown)
   txt = ffi.string(outbuf.data, outbuf.size)
   C.sd_bufrelease(outbuf)

   return txt
end

return {render=render}