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>2014-03-21 15:45:16 +0400
committerRonan Collobert <ronan@collobert.com>2014-03-21 15:45:16 +0400
commit5487d066b276640683edd76a27ff1f9b819a952b (patch)
treeda9f5370e996d19e29a662a3ed5faecc080d8897
parent76f1aaabc42afa1334c6f3ac41ea9406f29cb7df (diff)
moved to hoedown libraryhoedown
-rw-r--r--ascii.lua220
-rw-r--r--cdefs.lua145
-rw-r--r--env.lua2
-rw-r--r--html.lua21
-rw-r--r--htmlcdefs.lua71
-rw-r--r--rocks/sundown-scm-1.rockspec24
6 files changed, 358 insertions, 125 deletions
diff --git a/ascii.lua b/ascii.lua
index e033afe..176d015 100644
--- a/ascii.lua
+++ b/ascii.lua
@@ -2,7 +2,7 @@ local sundown = require 'sundown.env'
local C = sundown.C
local ffi = require 'ffi'
-require 'sundown.sdcdefs'
+require 'sundown.cdefs'
local c = {
none = '\27[0m',
@@ -56,7 +56,11 @@ local color_style = {
ulist = c.magenta,
olist = c.magenta,
tableheader = c.magenta,
- superscript = '^'
+ superscript = '^',
+ highlight = c.Red,
+ quote = c.Yellow,
+ underline = c._red,
+ footnote = c.blue
}
local bw_style = {
@@ -83,7 +87,8 @@ local bw_style = {
ulist = '',
olist = '',
tableheader = '',
- superscript = '^'
+ superscript = '^',
+ underline = c._
}
local default_style = color_style
@@ -111,6 +116,8 @@ local function createcallbacks(style)
local n = 0
local callbacks = {
+ opaque = ffi.cast('void*', nil),
+
blockcode =
function(ob, text, lang, opaque)
if text ~= nil and text.data ~= nil then
@@ -118,19 +125,7 @@ local function createcallbacks(style)
text = style.code .. text .. style.none
n = n+1
tree[n] = {tag='blockcode', text=text}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
- end
- end,
-
- header =
- function(ob, text, level, opaque)
- if text ~= nil and text.data ~= nil then
- text = ffi.string(text.data, text.size)
- level = math.max(math.min(level, 6), 1)
- text = style['h' .. level] .. text .. style.none
- n = n+1
- tree[n] = {tag='header', text=text, level=level}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
end
end,
@@ -141,7 +136,7 @@ local function createcallbacks(style)
text = style.blockquote .. text .. style.none
n = n+1
tree[n] = {tag='blockquote', text=text}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
end
end,
@@ -150,11 +145,43 @@ local function createcallbacks(style)
-- do nothing
end,
+ header =
+ function(ob, text, level, opaque)
+ if text ~= nil and text.data ~= nil then
+ text = ffi.string(text.data, text.size)
+ level = math.max(math.min(level, 6), 1)
+ text = style['h' .. level] .. text .. style.none
+ n = n+1
+ tree[n] = {tag='header', text=text, level=level}
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
+ end
+ end,
+
hrule =
function(ob, opaque)
n = n+1
tree[n] = {tag='hrule'}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
+ end,
+
+ list =
+ function(ob, text, flags, opaque)
+ if text and text.data ~= nil then
+ text = ffi.string(text.data, text.size)
+ n = n+1
+ tree[n] = {tag='list', text=text, type=bit.band(flags, 1)}
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
+ end
+ end,
+
+ listitem =
+ function(ob, text, flags, opaque)
+ if text ~= nil and text.data ~= nil then
+ text = ffi.string(text.data, text.size)
+ n = n+1
+ tree[n] = {tag='listitem', text=text}
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
+ end
end,
paragraph =
@@ -163,7 +190,7 @@ local function createcallbacks(style)
text = ffi.string(text.data, text.size)
n = n+1
tree[n] = {tag='paragraph', text=text}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
end
end,
@@ -184,7 +211,7 @@ local function createcallbacks(style)
if text or header then
n = n+1
tree[n] = {tag='tbl', text=text, header=header}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
end
end,
@@ -194,7 +221,7 @@ local function createcallbacks(style)
text = ffi.string(text.data, text.size)
n = n+1
tree[n] = {tag='tblrow', text=text}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
end
end,
@@ -215,45 +242,27 @@ local function createcallbacks(style)
right=(flags==2),
center=(flags==3)
}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
end
end,
- list =
- function(ob, text, flags, opaque)
- if text and text.data ~= nil then
- text = ffi.string(text.data, text.size)
- n = n+1
- tree[n] = {tag='list', text=text, type=bit.band(flags, 1)}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
- end
- end,
-
- listitem =
- function(ob, text, flags, opaque)
- if text ~= nil and text.data ~= nil then
- text = ffi.string(text.data, text.size)
- n = n+1
- tree[n] = {tag='listitem', text=text}
- C.sd_bufputs(ob, '\030' .. n .. '\031')
- end
- end,
-
- normal_text =
+ footnotes =
function(ob, text, opaque)
- if text ~= nil and text.data ~= nil then
+ if text and text.data ~= nil then
text = ffi.string(text.data, text.size)
- text = text:gsub('[\029\030\031]', '')
- C.sd_bufputs(ob, text)
- end
+ n = n + 1
+ tree[n] = {tag='footnotes', text=text}
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
+ end
end,
- entity =
- function(ob, text, opaque)
- if text ~= nil and text.data ~= nil then
+ footnote_def =
+ function(ob, text, num, opaque)
+ if text and text.data ~= nil then
text = ffi.string(text.data, text.size)
- text = text:gsub('[\029\030\031]', '')
- C.sd_bufputs(ob, text)
+ n = n + 1
+ tree[n] = {tag='footnote', text=text, num=num}
+ C.hoedown_buffer_puts(ob, '\030' .. n .. '\031')
end
end,
@@ -262,7 +271,7 @@ local function createcallbacks(style)
if link ~= nil and link.data ~= nil then
link = ffi.string(link.data, link.size)
link = style.link .. link .. style.none
- C.sd_bufputs(ob, link)
+ C.hoedown_buffer_puts(ob, link)
end
return 1
end,
@@ -272,7 +281,7 @@ local function createcallbacks(style)
if text ~= nil and text.data ~= nil then
text = ffi.string(text.data, text.size)
text = style.code .. text .. style.none
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
end
return 1
end,
@@ -281,7 +290,7 @@ local function createcallbacks(style)
function(ob, text, opaque)
if text ~= nil and text.data ~= nil then
text = style.doubleemph .. ffi.string(text.data, text.size) .. style.none
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
end
return 1
end,
@@ -290,7 +299,34 @@ local function createcallbacks(style)
function(ob, text, opaque)
if text ~= nil and text.data ~= nil then
text = style.emph .. ffi.string(text.data, text.size) .. style.none
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
+ end
+ return 1
+ end,
+
+ underline =
+ function(ob, text, opaque)
+ if text ~= nil and text.data ~= nil then
+ text = style.underline .. ffi.string(text.data, text.size) .. style.none
+ C.hoedown_buffer_puts(ob, text)
+ end
+ return 1
+ end,
+
+ highlight =
+ function(ob, text, opaque)
+ if text ~= nil and text.data ~= nil then
+ text = style.highlight .. ffi.string(text.data, text.size) .. style.none
+ C.hoedown_buffer_puts(ob, text)
+ end
+ return 1
+ end,
+
+ quote =
+ function(ob, text, opaque)
+ if text ~= nil and text.data ~= nil then
+ text = style.quote .. ffi.string(text.data, text.size) .. style.none
+ C.hoedown_buffer_puts(ob, text)
end
return 1
end,
@@ -306,14 +342,15 @@ local function createcallbacks(style)
text = text .. ffi.string(link.data, link.size)
end
text = text .. ']' .. style.none
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
return 1
end,
linebreak =
function(ob, opaque)
local text = '\029'
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
+ return 1
end,
link =
@@ -329,7 +366,7 @@ local function createcallbacks(style)
end
end
if #text > 0 then
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
end
return 1
end,
@@ -344,7 +381,7 @@ local function createcallbacks(style)
function(ob, text, opaque)
if text ~= nil and text.data ~= nil then
text = style.tripleemph .. ffi.string(text.data, text.size) .. style.none
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
end
return 1
end,
@@ -353,7 +390,7 @@ local function createcallbacks(style)
function(ob, text, opaque)
if text ~= nil and text.data ~= nil then
text = style.strikethrough .. ffi.string(text.data, text.size) .. style.none
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
end
return 1
end,
@@ -362,11 +399,36 @@ local function createcallbacks(style)
function(ob, text, opaque)
if text ~= nil and text.data ~= nil then
text = style.superscript .. ffi.string(text.data, text.size) .. style.none
- C.sd_bufputs(ob, text)
+ C.hoedown_buffer_puts(ob, text)
end
return 1
end,
+ footnote_ref =
+ function(ob, num, opaque)
+ text = style.footnote .. '[' .. tonumber(num) .. ']' .. style.none
+ C.hoedown_buffer_puts(ob, text)
+ return 1
+ end,
+
+ normal_text =
+ function(ob, text, opaque)
+ if text ~= nil and text.data ~= nil then
+ text = ffi.string(text.data, text.size)
+ text = text:gsub('[\029\030\031]', '')
+ C.hoedown_buffer_puts(ob, text)
+ end
+ end,
+
+ entity =
+ function(ob, text, opaque)
+ if text ~= nil and text.data ~= nil then
+ text = ffi.string(text.data, text.size)
+ text = text:gsub('[\029\030\031]', '')
+ C.hoedown_buffer_puts(ob, text)
+ end
+ end,
+
doc_header =
function(ob, opaque)
end,
@@ -381,21 +443,22 @@ end
local function preprocess(txt, style)
- local callbacks, tree = createcallbacks(style)
- local c_callbacks = ffi.new('struct sd_callbacks', callbacks)
- local markdown = C.sd_markdown_new(0xfff, 16, c_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)
+ local ob = C.hoedown_buffer_new(64);
+ local callbacks, tree = createcallbacks(style)
+ local c_callbacks = ffi.new('struct hoedown_renderer', callbacks)
+ local document = C.hoedown_document_new(c_callbacks, 0xfff, 16)
+ C.hoedown_document_render(document, ob, ffi.cast('const char*', txt), #txt);
+ C.hoedown_document_free(document);
for name,_ in pairs(callbacks) do
- c_callbacks[name]:free()
+ if name ~= 'opaque' then
+ c_callbacks[name]:free()
+ end
end
- txt = ffi.string(outbuf.data, outbuf.size)
- C.sd_bufrelease(outbuf)
+ txt = ffi.string(ob.data, ob.size)
+ C.hoedown_buffer_free(ob);
return txt, tree
end
@@ -508,6 +571,19 @@ local function show(out, txt, tree, indent, style, maxlsz)
table.insert(out, '')
elseif node.tag == 'listitem' then
show(out, node.text, tree, indent, style, maxlsz)
+ elseif node.tag == 'footnotes' then
+ table.insert(out, '')
+ showindent(out, style.hrule .. string.rep('_', math.min(20, maxlsz-indent)) .. style.none, indent)
+ table.insert(out, '')
+ show(out, node.text, tree, indent+1, style, maxlsz)
+ table.insert(out, '')
+ elseif node.tag == 'footnote' then
+ local num = node.num
+ while node.text:match('^(%b\030\031)') do
+ node = tree[ tonumber( node.text:match('^(%b\030\031)'):sub(2, -2) ) ]
+ end
+ local text = style.footnote .. '[' .. num .. '] ' .. style.none .. node.text
+ showindent(out, text, indent, maxlsz, style)
elseif node.tag == 'tbl' then
-- find cell sizes
local function rendertblsz(text, maxsz)
diff --git a/cdefs.lua b/cdefs.lua
new file mode 100644
index 0000000..0c3095d
--- /dev/null
+++ b/cdefs.lua
@@ -0,0 +1,145 @@
+local ffi = require 'ffi'
+
+ffi.cdef[[
+
+typedef enum {
+ HOEDOWN_BUF_OK = 0,
+ HOEDOWN_BUF_ENOMEM = -1
+} hoedown_buferror_t;
+
+
+struct hoedown_buffer {
+ uint8_t *data;
+ size_t size;
+ size_t asize;
+ size_t unit;
+};
+
+typedef struct hoedown_buffer hoedown_buffer;
+hoedown_buffer *hoedown_buffer_new(size_t unit) __attribute__ ((malloc));
+void hoedown_buffer_free(hoedown_buffer *buf);
+void hoedown_buffer_reset(hoedown_buffer *buf);
+int hoedown_buffer_grow(hoedown_buffer *buf, size_t neosz);
+void hoedown_buffer_put(hoedown_buffer *buf, const void *data, size_t len);
+void hoedown_buffer_puts(hoedown_buffer *buf, const char *str);
+void hoedown_buffer_putc(hoedown_buffer *buf, uint8_t c);
+int hoedown_buffer_prefix(const hoedown_buffer *buf, const char *prefix);
+void hoedown_buffer_slurp(hoedown_buffer *buf, size_t len);
+const char *hoedown_buffer_cstr(hoedown_buffer *buf);
+void hoedown_buffer_printf(hoedown_buffer *buf, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
+
+enum {
+ HOEDOWN_AUTOLINK_SHORT_DOMAINS = (1 << 0)
+};
+
+int hoedown_autolink_is_safe(const uint8_t *link, size_t link_len);
+
+size_t hoedown_autolink__www(size_t *rewind_p, hoedown_buffer *link,
+ uint8_t *data, size_t offset, size_t size, unsigned int flags);
+
+size_t hoedown_autolink__email(size_t *rewind_p, hoedown_buffer *link,
+ uint8_t *data, size_t offset, size_t size, unsigned int flags);
+
+size_t hoedown_autolink__url(size_t *rewind_p, hoedown_buffer *link,
+ uint8_t *data, size_t offset, size_t size, unsigned int flags);
+
+enum hoedown_extensions {
+
+ HOEDOWN_EXT_SPACE_HEADERS = (1 << 0),
+ HOEDOWN_EXT_TABLES = (1 << 1),
+ HOEDOWN_EXT_FENCED_CODE = (1 << 2),
+ HOEDOWN_EXT_FOOTNOTES = (1 << 3),
+
+
+ HOEDOWN_EXT_AUTOLINK = (1 << 4),
+ HOEDOWN_EXT_STRIKETHROUGH = (1 << 5),
+ HOEDOWN_EXT_UNDERLINE = (1 << 6),
+ HOEDOWN_EXT_HIGHLIGHT = (1 << 7),
+ HOEDOWN_EXT_QUOTE = (1 << 8),
+ HOEDOWN_EXT_SUPERSCRIPT = (1 << 9),
+
+
+ HOEDOWN_EXT_LAX_SPACING = (1 << 10),
+ HOEDOWN_EXT_NO_INTRA_EMPHASIS = (1 << 11),
+
+
+ HOEDOWN_EXT_DISABLE_INDENTED_CODE = (1 << 12)
+};
+
+enum hoedown_listflags {
+ HOEDOWN_LIST_ORDERED = (1 << 0),
+ HOEDOWN_LI_BLOCK = (1 << 1),
+};
+
+enum hoedown_tableflags {
+ HOEDOWN_TABLE_ALIGN_LEFT = 1,
+ HOEDOWN_TABLE_ALIGN_RIGHT = 2,
+ HOEDOWN_TABLE_ALIGN_CENTER = 3,
+ HOEDOWN_TABLE_ALIGNMASK = 3,
+ HOEDOWN_TABLE_HEADER = 4
+};
+
+enum hoedown_autolink {
+ HOEDOWN_AUTOLINK_NONE,
+ HOEDOWN_AUTOLINK_NORMAL,
+ HOEDOWN_AUTOLINK_EMAIL
+};
+
+struct hoedown_renderer {
+
+ void *opaque;
+
+ void (*blockcode)(hoedown_buffer *ob, const hoedown_buffer *text, const hoedown_buffer *lang, void *opaque);
+ void (*blockquote)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ void (*blockhtml)(hoedown_buffer *ob,const hoedown_buffer *text, void *opaque);
+ void (*header)(hoedown_buffer *ob, const hoedown_buffer *text, int level, void *opaque);
+ void (*hrule)(hoedown_buffer *ob, void *opaque);
+ void (*list)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque);
+ void (*listitem)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque);
+ void (*paragraph)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ void (*table)(hoedown_buffer *ob, const hoedown_buffer *header, const hoedown_buffer *body, void *opaque);
+ void (*table_row)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ void (*table_cell)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int flags, void *opaque);
+ void (*footnotes)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ void (*footnote_def)(hoedown_buffer *ob, const hoedown_buffer *text, unsigned int num, void *opaque);
+
+ int (*autolink)(hoedown_buffer *ob, const hoedown_buffer *link, enum hoedown_autolink type, void *opaque);
+ int (*codespan)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*double_emphasis)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*emphasis)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*underline)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*highlight)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*quote)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*image)(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *alt, void *opaque);
+ int (*linebreak)(hoedown_buffer *ob, void *opaque);
+ int (*link)(hoedown_buffer *ob, const hoedown_buffer *link, const hoedown_buffer *title, const hoedown_buffer *content, void *opaque);
+ int (*raw_html_tag)(hoedown_buffer *ob, const hoedown_buffer *tag, void *opaque);
+ int (*triple_emphasis)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*strikethrough)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*superscript)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+ int (*footnote_ref)(hoedown_buffer *ob, unsigned int num, void *opaque);
+
+ void (*entity)(hoedown_buffer *ob, const hoedown_buffer *entity, void *opaque);
+ void (*normal_text)(hoedown_buffer *ob, const hoedown_buffer *text, void *opaque);
+
+ void (*doc_header)(hoedown_buffer *ob, void *opaque);
+ void (*doc_footer)(hoedown_buffer *ob, void *opaque);
+};
+
+typedef struct hoedown_renderer hoedown_renderer;
+struct hoedown_document;
+typedef struct hoedown_document hoedown_document;
+
+extern hoedown_document *
+hoedown_document_new(
+ const hoedown_renderer *renderer,
+ unsigned int extensions,
+ size_t max_nesting);
+
+extern void
+hoedown_document_render(hoedown_document *doc, hoedown_buffer *ob, const uint8_t *document, size_t doc_size);
+
+extern void
+hoedown_document_free(hoedown_document *doc);
+
+]]
diff --git a/env.lua b/env.lua
index 757de7c..201e813 100644
--- a/env.lua
+++ b/env.lua
@@ -2,6 +2,6 @@ local ffi = require 'ffi'
local sundown = {}
-sundown.C = ffi.load(package.searchpath('libsundown', package.cpath))
+sundown.C = ffi.load(package.searchpath('libhoedown', package.cpath))
return sundown
diff --git a/html.lua b/html.lua
index 349cfec..efa9b8d 100644
--- a/html.lua
+++ b/html.lua
@@ -2,20 +2,21 @@ local sundown = require 'sundown.env'
local ffi = require 'ffi'
local C = sundown.C
-require 'sundown.sdcdefs'
+require 'sundown.cdefs'
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)
+ local ob = C.hoedown_buffer_new(64);
+
+ local renderer = C.hoedown_html_renderer_new(0, 0)
+ local document = C.hoedown_document_new(renderer, 0xfff, 16)
+ C.hoedown_document_render(document, ob, ffi.cast('const char*', txt), #txt);
+ C.hoedown_document_free(document);
+ C.hoedown_html_renderer_free(renderer);
+
+ txt = ffi.string(ob.data, ob.size)
+ C.hoedown_buffer_free(ob);
return txt
end
diff --git a/htmlcdefs.lua b/htmlcdefs.lua
index 9b2f9e9..5b12a8a 100644
--- a/htmlcdefs.lua
+++ b/htmlcdefs.lua
@@ -2,44 +2,55 @@ local ffi = require 'ffi'
ffi.cdef[[
-struct sd_html_renderopt {
- struct {
- int header_count;
- int current_level;
- int level_offset;
- } toc_data;
+typedef enum {
+ HOEDOWN_HTML_SKIP_HTML = (1 << 0),
+ HOEDOWN_HTML_SKIP_STYLE = (1 << 1),
+ HOEDOWN_HTML_SKIP_IMAGES = (1 << 2),
+ HOEDOWN_HTML_SKIP_LINKS = (1 << 3),
+ HOEDOWN_HTML_EXPAND_TABS = (1 << 4),
+ HOEDOWN_HTML_SAFELINK = (1 << 5),
+ HOEDOWN_HTML_TOC = (1 << 6),
+ HOEDOWN_HTML_HARD_WRAP = (1 << 7),
+ HOEDOWN_HTML_USE_XHTML = (1 << 8),
+ HOEDOWN_HTML_ESCAPE = (1 << 9)
+} hoedown_html_render_mode;
+
+typedef enum {
+ HOEDOWN_HTML_TAG_NONE = 0,
+ HOEDOWN_HTML_TAG_OPEN,
+ HOEDOWN_HTML_TAG_CLOSE
+} hoedown_html_tag;
+
+struct hoedown_html_renderer_state {
+ void *opaque;
- unsigned int flags;
+ struct {
+ int header_count;
+ int current_level;
+ int level_offset;
+ int nesting_level;
+ } toc_data;
- /* extra callbacks */
- void (*link_attributes)(struct sd_buf *ob, const struct sd_buf *url, void *self);
+ unsigned int flags;
+
+ void (*link_attributes)(hoedown_buffer *ob, const hoedown_buffer *url, void *self);
};
-typedef enum {
- HTML_SKIP_HTML = (1 << 0),
- HTML_SKIP_STYLE = (1 << 1),
- HTML_SKIP_IMAGES = (1 << 2),
- HTML_SKIP_LINKS = (1 << 3),
- HTML_EXPAND_TABS = (1 << 4),
- HTML_SAFELINK = (1 << 5),
- HTML_TOC = (1 << 6),
- HTML_HARD_WRAP = (1 << 7),
- HTML_USE_XHTML = (1 << 8),
- HTML_ESCAPE = (1 << 9),
-} sd_html_render_mode;
+typedef struct hoedown_html_renderer_state hoedown_html_renderer_state;
-typedef enum {
- HTML_TAG_NONE = 0,
- HTML_TAG_OPEN,
- HTML_TAG_CLOSE,
-} sd_html_tag;
+int
+hoedown_html_is_tag(const uint8_t *tag_data, size_t tag_size, const char *tagname);
-int sd_html_is_tag(const uint8_t *tag_data, size_t tag_size, const char *tagname);
+extern hoedown_renderer *
+hoedown_html_renderer_new(unsigned int render_flags, int nesting_level);
-void sd_html_renderer(struct sd_callbacks *callbacks, struct sd_html_renderopt *options_ptr, unsigned int render_flags);
+extern hoedown_renderer *
+hoedown_html_toc_renderer_new(int nesting_level);
-void sd_html_toc_renderer(struct sd_callbacks *callbacks, struct sd_html_renderopt *options_ptr);
+extern void
+hoedown_html_renderer_free(hoedown_renderer *renderer);
-void sd_html_smartypants(struct sd_buf *ob, const uint8_t *text, size_t size);
+extern void
+hoedown_html_smartypants(hoedown_buffer *ob, const uint8_t *text, size_t size);
]]
diff --git a/rocks/sundown-scm-1.rockspec b/rocks/sundown-scm-1.rockspec
index 586c5a4..c2a1347 100644
--- a/rocks/sundown-scm-1.rockspec
+++ b/rocks/sundown-scm-1.rockspec
@@ -27,24 +27,24 @@ build = {
modules = {
["sundown.env"] = "env.lua",
["sundown.init"] = "init.lua",
- ["sundown.sdcdefs"] = "sdcdefs.lua",
+ ["sundown.cdefs"] = "cdefs.lua",
["sundown.htmlcdefs"] = "htmlcdefs.lua",
["sundown.html"] = "html.lua",
["sundown.ascii"] = "ascii.lua",
- libsundown = {
+ libhoedown = {
sources = {
- "src/autolink.c",
- "src/buffer.c",
- "src/markdown.c",
- "src/stack.c",
- "html/houdini_href_e.c",
- "html/houdini_html_e.c",
- "html/html.c",
- "html/html_smartypants.c"
+ "hoedown/src/autolink.c",
+ "hoedown/src/buffer.c",
+ "hoedown/src/document.c",
+ "hoedown/src/escape.c",
+ "hoedown/src/html.c",
+ "hoedown/src/html_blocks.c",
+ "hoedown/src/html_smartypants.c",
+ "hoedown/src/stack.c",
+ "hoedown/src/version.c"
},
incdirs = {
- "src/",
- "html/"
+ "hoedown/src/"
}
}
}