Skip to content

Commit 600280f

Browse files
author
St-Ex
authored
Warn user if file to include is not found and skip it rather than crash (#117)
1 parent 6bd2447 commit 600280f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

include-files/include-files.lua

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ function transclude (cb)
4040
for line in cb.text:gmatch('[^\n]+') do
4141
if line:sub(1,2) ~= '//' then
4242
local fh = io.open(line)
43-
local contents = pandoc.read(fh:read '*a', format).blocks
44-
-- recursive transclusion
45-
contents = pandoc.walk_block(
46-
pandoc.Div(contents),
47-
{CodeBlock = transclude}
48-
).content
49-
blocks:extend(shift_headings(contents, shift_heading_level_by))
50-
fh:close()
43+
if not fh then
44+
io.stderr:write("Cannot open file " .. line .. " | Skipping includes\n")
45+
else
46+
local contents = pandoc.read(fh:read '*a', format).blocks
47+
-- recursive transclusion
48+
contents = pandoc.walk_block(
49+
pandoc.Div(contents),
50+
{CodeBlock = transclude}
51+
).content
52+
blocks:extend(shift_headings(contents, shift_heading_level_by))
53+
fh:close()
54+
end
5155
end
5256
end
5357
return blocks

0 commit comments

Comments
 (0)