mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
fix #1035 by CDATA tidy
This commit is contained in:
parent
7a22c60256
commit
fea7b93b62
2
base
2
base
@ -1 +1 @@
|
|||||||
Subproject commit 1c623700fb4499e4dcb2d56f59319c4be235fe3b
|
Subproject commit 267cfbd223d6d606329d3f13b6f3b6bd486239eb
|
@ -32,6 +32,25 @@ function ReaderDictionary:onLookupWord(word, box, highlight)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function tidyCDATA(results)
|
||||||
|
local cdata_tag = "<!%[CDATA%[(.-)%]%]>"
|
||||||
|
local format_escape = "&[29Ib%+]{(.-)}"
|
||||||
|
for _, result in ipairs(results) do
|
||||||
|
-- parse CDATA text in XML
|
||||||
|
if result.definition:find(cdata_tag) then
|
||||||
|
local def = result.definition:gsub(cdata_tag, "%1")
|
||||||
|
-- ignore all tags
|
||||||
|
def = def:gsub("%b<>", "")
|
||||||
|
-- ignore format strings
|
||||||
|
while def:find(format_escape) do
|
||||||
|
def = def:gsub(format_escape, "%1")
|
||||||
|
end
|
||||||
|
result.definition = def
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return results
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderDictionary:stardictLookup(word, box)
|
function ReaderDictionary:stardictLookup(word, box)
|
||||||
DEBUG("lookup word:", word, box)
|
DEBUG("lookup word:", word, box)
|
||||||
if word then
|
if word then
|
||||||
@ -47,7 +66,7 @@ function ReaderDictionary:stardictLookup(word, box)
|
|||||||
local ok, results = pcall(JSON.decode, JSON, results_str)
|
local ok, results = pcall(JSON.decode, JSON, results_str)
|
||||||
if ok and results then
|
if ok and results then
|
||||||
DEBUG("lookup result table:", word, results)
|
DEBUG("lookup result table:", word, results)
|
||||||
self:showDict(word, results, box)
|
self:showDict(word, tidyCDATA(results), box)
|
||||||
else
|
else
|
||||||
-- dummy results
|
-- dummy results
|
||||||
results = {
|
results = {
|
||||||
|
Loading…
Reference in New Issue
Block a user