[plugin] Exporter: properly sort highlights when exporting (#9021)

Since the bookmarks table is sorted based on the bookmarks'
position in the book, it is possible to sort clippings in
the exporter plugin based on that.
This commit is contained in:
Utsob Roy
2022-04-23 00:13:36 +06:00
committed by GitHub
parent 5ac9463c09
commit 4e517f4839

View File

@@ -286,7 +286,15 @@ function MyClipping:parseHighlight(highlights, bookmarks, book)
end
end
end
table.sort(book, function(v1, v2) return v1[1].page < v2[1].page end)
-- A table to map bookmarks timestamp to index in the bookmarks table
-- to facilitate sorting clippings by their position in the book
-- since highlights are not sorted by position while bookmarks are.
local bookmark_indexes = {}
for i, bookmark in ipairs(bookmarks) do
bookmark_indexes[self:getTime(bookmark.datetime)] = i
end
-- Sort clippings by their position in the book.
table.sort(book, function(v1, v2) return bookmark_indexes[v1[1].time] > bookmark_indexes[v2[1].time] end)
end
function MyClipping:parseHistoryFile(clippings, history_file, doc_file)