change flags to table

This commit is contained in:
Татьяна Фарбер 2026-02-15 23:59:02 +04:00
parent a4ed4ab40e
commit a418ab63e0
5 changed files with 16 additions and 8 deletions

View File

@ -58,7 +58,7 @@ table:
``` ```
markdown.compile(markdown_text,flag,flag,flag) markdown.compile(markdown_text,flags)
``` ```
@ -103,7 +103,7 @@ Example:
``` ```
markdown.compile(markdown_text,"extrafootnote","toc","notables") markdown.compile(markdown_text,{"extrafootnote","toc","notables"})
``` ```

View File

@ -61,17 +61,25 @@ static int compile(lua_State *L) {
MMIOT *doc; MMIOT *doc;
mkd_flag_t *flags = mkd_flags(); mkd_flag_t *flags = mkd_flags();
char *body = NULL, *toc = NULL, *css = NULL; char *body = NULL, *toc = NULL, *css = NULL;
int body_size, toc_size, css_size, i, argc; int body_size, toc_size, css_size;
size_t input_size; size_t input_size;
const char *input = luaL_checklstring(L, 1, &input_size); const char *input = luaL_checklstring(L, 1, &input_size);
luaL_argcheck(L, input_size < INT_MAX, 1, "string too long"); luaL_argcheck(L, input_size < INT_MAX, 1, "string too long");
for (i = 2, argc = lua_gettop(L); i <= argc; i++) { if (lua_gettop(L) >= 2) {
mkd_set_flag_num(flags, option_codes[luaL_checkoption(L, i, NULL, options)]); luaL_argcheck(L, lua_istable(L, 2), 2, "second argument must be a table");
lua_pushvalue(L, 2);
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
mkd_set_flag_num(flags, option_codes[luaL_checkoption(L, -1, NULL, options)]);
lua_pop(L, 1);
}
lua_pop(L, 1);
} }
doc = mkd_string(input, (int) input_size, flags); doc = mkd_string(input, (int) input_size, flags);
if (unlikely(doc == NULL)) { if (unlikely(doc == NULL)) {
lua_pushnil(L); lua_pushnil(L);
lua_pushstring(L, "mkd_string() returned NULL"); lua_pushstring(L, "mkd_string() returned NULL");

Binary file not shown.

Binary file not shown.

View File

@ -25,13 +25,13 @@ do
end end
do do
local doc = assert(compile("", "toc")) local doc = assert(compile("", {"toc"}))
assert(doc.body == "") assert(doc.body == "")
assert(not doc.index) assert(not doc.index)
end end
do do
local doc = assert(compile("# Heading", "toc")) local doc = assert(compile("# Heading", {"toc"}))
assert(doc.body) assert(doc.body)
assert(doc.index) assert(doc.index)
print(doc.index) print(doc.index)