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 anymore
reviewable/pr10369/r1
Mochitto 1 year ago committed by GitHub
parent cb9cbff10e
commit c0615c3bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -93,7 +93,7 @@ function BaseExporter:getFilePath(t)
if not self.is_remote then
local filename = string.format("%s-%s.%s",
self:getTimeStamp(),
#t == 1 and t[1].output_filename or "all-books",
#t == 1 and t[1].output_filename or self.all_books_title or "all-books",
self.extension)
return self.clipping_dir .. "/" .. getSafeFilename(filename)
end

@ -38,7 +38,7 @@ local _ = require("gettext")
-- migrate settings from old "evernote.koplugin" or from previous (monolithic) "exporter.koplugin"
local function migrateSettings()
local formats = { "html", "joplin", "json", "readwise", "text" }
local formats = { "html", "joplin", "json", "readwise", "text", "my_clippings" }
local settings = G_reader_settings:readSetting("exporter")
if not settings then
@ -104,6 +104,7 @@ local Exporter = WidgetContainer:extend{
markdown = require("target/markdown"),
readwise = require("target/readwise"),
text = require("target/text"),
my_clippings = require("target/my_clippings"),
},
}

@ -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…
Cancel
Save