Add context_text extraction for text-search-based CFI conversion

This commit is contained in:
2026-05-31 11:55:17 -04:00
parent 1621f1eaa2
commit 109dedc10f
+23
View File
@@ -662,6 +662,27 @@ function Bookhoard:getBookhoardUUID()
return self.ui.doc_settings:readSetting("bookhoard_uuid") return self.ui.doc_settings:readSetting("bookhoard_uuid")
end end
function Bookhoard:getContextText()
if not self.ui.document or self.ui.document.info.has_pages then
return ""
end
local xp = self:getLastProgress()
if not xp then return "" end
local text = self.ui.document:getTextFromXPointer(xp)
if not text or text == "" then
text = self.ui.document:getTextFromXPointer(self.ui.document:getNormalizedXPointer(xp))
end
if not text or text == "" then return "" end
if #text > 100 then
text = text:sub(1, 100)
end
text = text:gsub("%s+", " "):match("^%s*(.-)%s*$") or ""
return text
end
function Bookhoard:collectBookData() function Bookhoard:collectBookData()
local props = self.ui.doc_props local props = self.ui.doc_props
local file_path = self.ui.document.file local file_path = self.ui.document.file
@@ -680,6 +701,7 @@ function Bookhoard:collectBookData()
local progress = self:getLastProgress() local progress = self:getLastProgress()
local page = self.ui:getCurrentPage() local page = self.ui:getCurrentPage()
local total_pages = self.ui.document:getPageCount() local total_pages = self.ui.document:getPageCount()
local context_text = self:getContextText()
local book_data = { local book_data = {
uuid = book_uuid, uuid = book_uuid,
@@ -688,6 +710,7 @@ function Bookhoard:collectBookData()
authors = authors, authors = authors,
percentage = percentage, percentage = percentage,
epubcfi = progress, epubcfi = progress,
context_text = context_text,
page = page, page = page,
total_pages = total_pages, total_pages = total_pages,
file_path = file_path, file_path = file_path,