diff --git a/src/resources/filters/ast/emulatedfilter.lua b/src/resources/filters/ast/emulatedfilter.lua index 34d05278f8..8691780f54 100644 --- a/src/resources/filters/ast/emulatedfilter.lua +++ b/src/resources/filters/ast/emulatedfilter.lua @@ -37,13 +37,9 @@ make_wrapped_user_filters = function(filterListName) end inject_user_filters_at_entry_points = function(filter_list) - local function find_index_of_entry_point(entry_point) - for i, filter in ipairs(filter_list) do - if filter.name == entry_point then - return i - end - end - return nil + local find_index_of_entry_point = function (entry_point) + return pandoc.List.find_if(filter_list, + function (filter) return filter.name == entry_point end) end local entry_point_counts = {} for _, v in ipairs(param("quarto-filters").entryPoints) do diff --git a/src/resources/filters/common/list.lua b/src/resources/filters/common/list.lua index f96068964f..2ebcebc85e 100644 --- a/src/resources/filters/common/list.lua +++ b/src/resources/filters/common/list.lua @@ -1,13 +1,4 @@ -- list.lua -- Copyright (C) 2020-2022 Posit Software, PBC -function filter(list, test) - local result = {} - for index, value in ipairs(list) do - if test(value, index) then - result[#result + 1] = value - end - end - return result -end - +filter = pandoc.List.filter diff --git a/src/resources/filters/common/table.lua b/src/resources/filters/common/table.lua index 3c820532ca..28e4977fec 100644 --- a/src/resources/filters/common/table.lua +++ b/src/resources/filters/common/table.lua @@ -2,17 +2,14 @@ -- Copyright (C) 2020-2022 Posit Software, PBC -- append values to table -function tappend(t, values) - for i,value in pairs(values) do - table.insert(t, value) - end -end +tappend = pandoc.List.extend -- prepend values to table function tprepend(t, values) - for i=1, #values do - table.insert(t, 1, values[#values + 1 - i]) - end + local nvals = #values + table.move(t, 1, #t, nvals + 1) -- shift elements to make space + table.move(values, 1, nvals, 1, t) -- copy values into t + return t end -- slice elements out of a table @@ -39,30 +36,19 @@ function tisarray(t) end -- map elements of a table -function tmap(tbl, f) - local t = {} - for k,v in pairs(tbl) do - t[k] = f(v) - end - return t -end +tmap = pandoc.List.map -- does the table contain a value function tcontains(t,value) if t and type(t)=="table" and value then - for _, v in ipairs (t) do - if v == value then - return true - end - end - return false + return pandoc.List.includes(t, value) end return false end -- clear a table function tclear(t) - for k,v in pairs(t) do + for k,_ in pairs(t) do t[k] = nil end end @@ -70,10 +56,8 @@ end -- get keys from table function tkeys(t) local keyset=pandoc.List({}) - local n=0 - for k,v in pairs(t) do - n=n+1 - keyset[n]=k + for key in pairs(t) do + keyset:insert(key) end return keyset end