2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/plugins/exporter.koplugin/target/my_clippings.lua

53 lines
1.7 KiB
Lua
Raw Normal View History

local util = require("ffi/util")
local T = util.template
local _ = require("gettext")
-- myClippings exporter
local ClippingsExporter = require("base"):new {
name = "myClippings",
extension = "txt",
mimetype = "text/plain",
all_books_title = "myClippings"
}
local function format(booknotes)
local content = ""
for ___, entry in ipairs(booknotes) do
for ____, clipping in ipairs(entry) do
if booknotes.title and clipping.text then
content = content .. booknotes.title .. "\n"
local header = T(_("- Your Highlight on page %1 | Added on %2\n\n"), clipping.page, os.date("%A, %B %d, %Y %I:%M:%S %p", clipping.time))
content = content .. header
content = content .. clipping.text
content = content .. "\n==========\n"
if clipping.note then
content = content .. booknotes.title .. "\n"
header = T(_("- Your Note on page %1 | Added on %2\n\n"), clipping.page, os.date("%A, %B %d, %Y %I:%M:%S %p", clipping.time))
content = content .. header .. clipping.note
content = content .. "\n==========\n"
end
end
end
end
return content
end
function ClippingsExporter:export(t)
local path = self:getFilePath(t)
local file = io.open(path, "a")
if not file then return false end
for __, booknotes in ipairs(t) do
local content = format(booknotes)
file:write(content)
end
file:close()
return true
end
function ClippingsExporter:share(t)
local content = format(t)
self:shareText(content)
end
return ClippingsExporter