Add chapter title when exporting notes in Evernote (JSON/HTML, remote) (#6146)

closes #4566
closes #6138
This commit is contained in:
Galunid
2020-06-17 23:51:02 +02:00
committed by GitHub
parent 5aab341ed0
commit cd440acdc4
5 changed files with 96 additions and 6 deletions

View File

@@ -203,7 +203,7 @@ function ReaderToc:getTocIndexByPage(pn_or_xp)
if #self.toc == 0 then return end
local pageno = pn_or_xp
if type(pn_or_xp) == "string" then
pageno = self.ui.document:getPageFromXPointer(pn_or_xp)
return self:getAccurateTocIndexByXPointer(pn_or_xp)
end
local pre_index = 1
for _k,_v in ipairs(self.toc) do
@@ -215,6 +215,38 @@ function ReaderToc:getTocIndexByPage(pn_or_xp)
return pre_index
end
function ReaderToc:getAccurateTocIndexByXPointer(xptr)
local pageno = self.ui.document:getPageFromXPointer(xptr)
-- get toc entry(index) on for the current page
-- we don't get infinite loop, because the this call is not
-- with xpointer, but with page
local index = self:getTocIndexByPage(pageno)
if not index or not self.toc[index] then return end
local initial_comparison = self.ui.document:compareXPointers(self.toc[index].xpointer, xptr)
if initial_comparison and initial_comparison < 0 then
local i = index - 1
while self.toc[i] do
local toc_xptr = self.toc[i].xpointer
local cmp = self.ui.document:compareXPointers(toc_xptr, xptr)
if cmp and cmp >= 0 then -- toc_xptr is before xptr(xptr >= toc_xptr)
return i
end
i = i - 1
end
else
local i = index + 1
while self.toc[i] do
local toc_xptr = self.toc[i].xpointer
local cmp = self.ui.document:compareXPointers(toc_xptr, xptr)
if cmp and cmp < 0 then -- toc_xptr is after xptr(xptr < toc_xptr)
return i - 1
end
i = i + 1
end
end
return index
end
function ReaderToc:getTocTitleByPage(pn_or_xp)
local index = self:getTocIndexByPage(pn_or_xp)
if index then