2022-05-06 20:44:28 +00:00
|
|
|
local util = require("ffi/util")
|
|
|
|
local T = util.template
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
-- text exporter
|
|
|
|
local TextExporter = require("base"):new {
|
|
|
|
name = "text",
|
|
|
|
extension = "txt",
|
2022-10-26 09:18:27 +00:00
|
|
|
mimetype = "text/plain",
|
2022-05-06 20:44:28 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 17:56:10 +00:00
|
|
|
local function format(booknotes)
|
|
|
|
local wide_space = "\227\128\128"
|
|
|
|
local content = ""
|
|
|
|
if booknotes.title then
|
|
|
|
content = content .. wide_space .. booknotes.title .. "\n" .. wide_space .. "\n"
|
|
|
|
end
|
|
|
|
for ___, entry in ipairs(booknotes) do
|
|
|
|
for ____, clipping in ipairs(entry) do
|
|
|
|
if clipping.chapter then
|
|
|
|
content = content .. wide_space .. clipping.chapter .. "\n" .. wide_space .. "\n"
|
|
|
|
end
|
|
|
|
local text = T(_("-- Page: %1, added on %2\n"), clipping.page, os.date("%c", clipping.time))
|
|
|
|
content = content .. wide_space .. wide_space .. text
|
|
|
|
if clipping.text then
|
|
|
|
content = content .. clipping.text
|
|
|
|
end
|
|
|
|
if clipping.note then
|
|
|
|
content = content .. "\n---\n" .. clipping.note
|
|
|
|
end
|
|
|
|
if clipping.image then
|
|
|
|
content = content .. _("<An image>")
|
|
|
|
end
|
|
|
|
content = content .. "\n-=-=-=-=-=-\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
content = content .. "\n"
|
|
|
|
return content
|
|
|
|
end
|
|
|
|
|
2022-05-06 20:44:28 +00:00
|
|
|
function TextExporter:export(t)
|
|
|
|
-- Use wide_space to avoid crengine to treat it specially.
|
2022-06-03 17:56:10 +00:00
|
|
|
|
2022-05-06 20:44:28 +00:00
|
|
|
local path = self:getFilePath(t)
|
|
|
|
local file = io.open(path, "a")
|
|
|
|
if not file then return false end
|
|
|
|
for __, booknotes in ipairs(t) do
|
2022-06-03 17:56:10 +00:00
|
|
|
local content = format(booknotes)
|
|
|
|
file:write(content)
|
2022-05-06 20:44:28 +00:00
|
|
|
end
|
|
|
|
file:close()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2022-06-03 17:56:10 +00:00
|
|
|
function TextExporter:share(t)
|
|
|
|
local content = format(t)
|
2022-10-26 09:18:27 +00:00
|
|
|
self:shareText(content)
|
2022-06-03 17:56:10 +00:00
|
|
|
end
|
|
|
|
|
2022-05-06 20:44:28 +00:00
|
|
|
return TextExporter
|