Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/use pandoc lua functions #11671

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/resources/filters/ast/emulatedfilter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 select(2, pandoc.List.find_if(filter_list,
function (f) return f.name == entry_point end))
end
local entry_point_counts = {}
for _, v in ipairs(param("quarto-filters").entryPoints) do
Expand Down Expand Up @@ -76,4 +72,4 @@ inject_user_filters_at_entry_points = function(filter_list)
end
table.insert(filter_list, index, filter)
end
end
end
11 changes: 1 addition & 10 deletions src/resources/filters/common/list.lua
Original file line number Diff line number Diff line change
@@ -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
36 changes: 10 additions & 26 deletions src/resources/filters/common/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,41 +36,28 @@ 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

-- 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
Expand Down
Loading