[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.
reviewable/pr9031/r1
Utsob Roy 2 years ago committed by GitHub
parent 5ac9463c09
commit 4e517f4839
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

Loading…
Cancel
Save