Skip to content

Commit 8e4f5fd

Browse files
committed
Use functions supplied by pandoc when possible
1 parent 6de2ca7 commit 8e4f5fd

File tree

2 files changed

+11
-35
lines changed

2 files changed

+11
-35
lines changed

src/resources/filters/ast/emulatedfilter.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ make_wrapped_user_filters = function(filterListName)
3737
end
3838

3939
inject_user_filters_at_entry_points = function(filter_list)
40-
local function find_index_of_entry_point(entry_point)
41-
for i, filter in ipairs(filter_list) do
42-
if filter.name == entry_point then
43-
return i
44-
end
45-
end
46-
return nil
40+
local find_index_of_entry_point = function (entry_point)
41+
return pandoc.List.find_if(filter_list,
42+
function (filter) return filter.name == entry_point end)
4743
end
4844
local entry_point_counts = {}
4945
for _, v in ipairs(param("quarto-filters").entryPoints) do

src/resources/filters/common/table.lua

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
-- Copyright (C) 2020-2022 Posit Software, PBC
33

44
-- append values to table
5-
function tappend(t, values)
6-
for i,value in pairs(values) do
7-
table.insert(t, value)
8-
end
9-
end
5+
tappend = pandoc.List.extend
106

117
-- prepend values to table
128
function tprepend(t, values)
13-
for i=1, #values do
14-
table.insert(t, 1, values[#values + 1 - i])
15-
end
9+
local nvals = #values
10+
table.move(t, 1, #t, nvals + 1) -- shift elements to make space
11+
table.move(values, 1, nvals, 1, t) -- copy values into t
12+
return t
1613
end
1714

1815
-- slice elements out of a table
@@ -39,23 +36,12 @@ function tisarray(t)
3936
end
4037

4138
-- map elements of a table
42-
function tmap(tbl, f)
43-
local t = {}
44-
for k,v in pairs(tbl) do
45-
t[k] = f(v)
46-
end
47-
return t
48-
end
39+
tmap = pandoc.List.map
4940

5041
-- does the table contain a value
5142
function tcontains(t,value)
5243
if t and type(t)=="table" and value then
53-
for _, v in ipairs (t) do
54-
if v == value then
55-
return true
56-
end
57-
end
58-
return false
44+
return pandoc.List.includes(t, value)
5945
end
6046
return false
6147
end
@@ -69,13 +55,7 @@ end
6955

7056
-- get keys from table
7157
function tkeys(t)
72-
local keyset=pandoc.List({})
73-
local n=0
74-
for k,v in pairs(t) do
75-
n=n+1
76-
keyset[n]=k
77-
end
78-
return keyset
58+
return pandoc.List(pairs(t))
7959
end
8060

8161
-- sorted pairs. order function takes (t, a,)

0 commit comments

Comments
 (0)