Hyphenation: add custom hyphenation rules (#7746)

The hyphenation of a word can be changed from its default
by long pressing for 3 seconds and selecting 'Hyphenate'.
These overrides are stored in a per-language file, i.e:
koreader/settings/user-German.hyph.
This commit is contained in:
zwim
2021-05-31 20:34:26 +02:00
committed by GitHub
parent b30e366ccd
commit f25da5d0d5
39 changed files with 355 additions and 256 deletions

View File

@@ -612,7 +612,6 @@ end
function OPDSBrowser:createNewDownloadDialog(path, buttons)
self.download_dialog = ButtonDialogTitle:new{
title = T(_("Download folder:\n%1\n\nDownload file type:"), BD.dirpath(path)),
use_info_style = true,
buttons = buttons
}
end
@@ -651,10 +650,10 @@ function OPDSBrowser:showDownloads(item)
table.insert(buttons, line)
end
table.insert(buttons, {})
-- Set download folder and book info buttons.
-- Set download folder button.
table.insert(buttons, {
{
text = _("Select folder"),
text = _("Select another folder"),
callback = function()
require("ui/downloadmgr"):new{
onConfirm = function(path)
@@ -668,18 +667,7 @@ function OPDSBrowser:showDownloads(item)
end,
}:chooseDir()
end,
},
{
text = _("Book information"),
enabled = type(item.content) == "string",
callback = function()
local TextViewer = require("ui/widget/textviewer")
UIManager:show(TextViewer:new{
title = item.text,
text = util.htmlToPlainTextIfHtml(item.content),
})
end,
},
}
})
self:createNewDownloadDialog(self.getCurrentDownloadDir(), buttons)

View File

@@ -72,6 +72,10 @@ function OPDSParser:createFlatXTable(xlex, curr_element)
end
function OPDSParser:parse(text)
-- Murder Calibre's whole "content" block, because luxl doesn't really deal well with various XHTML quirks,
-- as the list of crappy replacements below attests to...
-- There's also a high probability of finding orphaned tags or badly nested ones in there, which will screw everything up.
text = text:gsub('<content type="xhtml">.-</content>', '')
-- luxl doesn't handle XML comments, so strip them
text = text:gsub("<!%-%-.-%-%->", "")
-- luxl is also particular about the syntax for self-closing, empty & orphaned tags...
@@ -80,18 +84,8 @@ function OPDSParser:parse(text)
text = text:gsub("<([bh]r)>", "<%1 />")
-- Some OPDS catalogs wrap text in a CDATA section, remove it as it causes parsing problems
text = text:gsub("<!%[CDATA%[(.-)%]%]>", function (s)
return s:gsub("%p", {["&"] = "&amp;", ["<"] = "&lt;", [">"] = "&gt;"})
return s:gsub( "%p", {["&"] = "&amp;", ["<"] = "&lt;", [">"] = "&gt;" } )
end )
-- NOTE: OPDS content tags are likely to contain a bunch of HTML or XHTML. We do *NOT* want to let luxl parse that,
-- because it doesn't really deal well with various XHTML quirks, as the list of crappy replacements above attests to...
-- There's also a high probability of finding orphaned tags or badly nested ones in there, which would screw everything up.
-- In any case, we just want to treat the whole thing as a single text node anyway, so, just mangle the markup to force luxl's hand.
text = text:gsub('<content type=".-">', "<content>")
text = text:gsub("<content>(.-)</content>", function (s)
return '<content type="text">' .. s:gsub("%p", {["<"] = "&lt;", [">"] = "&gt;", ['"'] = "&quot;", ["'"] = "&apos;"}) .. "</content>"
end )
local xlex = luxl.new(text, #text)
return assert(self:createFlatXTable(xlex))
end