generated from tarleb/lua-filter-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexclude-format.lua
38 lines (29 loc) · 981 Bytes
/
exclude-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
--- exclude-format.lua – Keeps parts of a document out of selected output formats.
---
--- Copyright: © 2023 Robert Bachmann
--- License: MIT – see LICENSE for details
-- Makes sure users know if their pandoc version is too old for this
-- filter.
PANDOC_VERSION:must_be_at_least '3'
-- strip path for lua filters
local format = FORMAT:match('^.+[\\/](.+)%.lua$')
if format == nil then
format = FORMAT:gsub('%.lua$', '')
end
local needle = string.format(' %s ', string.lower(format))
local function filter_div(elem)
local exclude_from = elem.attributes['exclude-format']
if not exclude_from or type(exclude_from) ~= 'string' then
return nil -- keep as-is
end
exclude_from = ' ' .. string.lower(exclude_from) .. ' '
exclude_from = string.gsub(exclude_from, "[%s,]+", " ")
if string.find(exclude_from, needle, 1, true) then
return {} -- remove it
end
elem.attributes['exclude-format'] = nil
return elem
end
return {
{ Div = filter_div }
}