-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.lua
39 lines (32 loc) · 808 Bytes
/
file.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
function fileinfo(path)
filename, basename, extension = path:match('(([^/]-).?([^.]+))$')
return {
path = string.sub(path, 0, -#filename - 1),
filename = filename,
basename = basename,
extension = extension,
}
end
function resolve_file(name)
if PANDOC_STATE == nil or file_exists(name) then return name end
for _, file in pairs(PANDOC_STATE.input_files) do
path = fileinfo(file).path .. name
if file_exists(path) then
return path
end
end
return name
end
function file_exists(name)
local f = io.open(name, 'r')
if f ~= nil then io.close(f) return true else return false end
end
function read_file(name)
local content = ''
local f = io.open(name, 'r')
if f ~= nil then
content = f:read('*all')
io.close(f)
end
return content
end