mirror of https://github.com/koreader/koreader
Feature: Export to kindle's myClippings (#10263)
* Feature: Added the possibility to export using kindle's myClippings formatting * Fix: files that have the same extension don't collide anymorereviewable/pr10369/r1
parent
cb9cbff10e
commit
c0615c3bda
@ -0,0 +1,52 @@
|
||||
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
|
Loading…
Reference in New Issue