-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnot-in-format.lua
39 lines (33 loc) · 1.28 KB
/
not-in-format.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
--- # not-in-format - keep document parts out of selected output formats.
--
-- This Lua filter for Pandoc that keeps parts of a document out of
-- selected outputs formats.
--
-- @author Julien Dutant <[email protected]>, Albert Krewinkel
-- @copyright 2021 Julien Dutant, Albert Krewinkel
-- @license MIT - see LICENSE file for details.
-- @release 1.0
--- Main Div filter.
-- Removes Divs tagged with `not-in-format` if the
-- output format matches one of the Div's attributes
-- @param element a Div element
-- @return an empty block if the Div classes include `not-in-format`
-- and the target format
function Div(element)
-- the find_if method returns the first value x in the list
-- element.classes for which FORMAT:match(x) evaluates as true,
-- and nil otherwise. Within the if clause that value evaluates
-- as true and nil evaluates as false.
if element.classes:includes('not-in-format') and
element.classes:find_if(function (x) return FORMAT:match(x) end) then
return {}
end
if element.classes:includes('only-in-format') then
if element.classes:find_if(function (x) return FORMAT:match(x) end) then
return nil -- do not change anything
else
return {}
end
end
-- else the function returns `nil` and Pandoc leaves the element as is
end