Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML widget in GoodReads review #3929

Merged
merged 1 commit into from May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 2 additions & 23 deletions plugins/goodreads.koplugin/goodreadsapi.lua
Expand Up @@ -88,28 +88,6 @@ function GoodreadsApi:getTotalResults()
return self.total_result
end

local function cleanHTMLTags(str_html)
local cleaner = {
{ "&", "&" },
{ "—", "-" },
{ "’", "'" },
{ " ", " " },
{ "<!%[CDATA%[(.*)%]%]>", "%1" },
{ "<br%s/>", "\n" },
{ "%-%-", "%-" },
{ "</p>", "\n" },
{ "(%b<>)", "" },
{ "\n\n*", "\n" },
{ "\n*$", "" },
{ "^\n*", "" },
}
for i=1, #cleaner do
local cleans = cleaner[i]
str_html = string.gsub(str_html, cleans[1], cleans[2])
end
return str_html
end

local function showIdTable(data)
if data == nil then
UIManager:show(InfoMessage:new{text =_("Network problem.\nCheck connection.")})
Expand All @@ -132,7 +110,8 @@ local function showIdTable(data)
local id = data1:match("<id>([^<]+)</id>"):gsub("<![[]CDATA[[]", ""):gsub("]]>$", "")
local author = data1:match("<name>([^<]+)</name>")
local description = data1:match("<description>(.*)</description>")
description = cleanHTMLTags(description)
description = string.gsub(description, "<!%[CDATA%[(.*)%]%]>", "%1")
description = string.gsub(description, "%-%-", "%—")
--change format from medium to large
local image = data1:match("<image_url>([^<]+)</image_url>"):gsub("([0-9]+)m/", "%1l/")
local day = data1:match("<original_publication_day[^>]+>([^<]+)</original_publication_day>")
Expand Down
23 changes: 17 additions & 6 deletions plugins/goodreads.koplugin/goodreadsbook.lua
Expand Up @@ -17,7 +17,7 @@ local TextWidget = require("ui/widget/textwidget")
local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local Screen = require("device").screen
local ScrollTextWidget = require("ui/widget/scrolltextwidget")
local ScrollHtmlWidget = require("ui/widget/scrollhtmlwidget")
local TextBoxWidget = require("ui/widget/textboxwidget")
local UIManager = require("ui/uimanager")
local https = require('ssl.https')
Expand Down Expand Up @@ -227,18 +227,29 @@ function GoodreadsBook:genBookInfoGroup()
end

function GoodreadsBook:bookReview()
local css = [[
@page {
margin: 0;
font-family: 'Noto Sans';
}

body {
margin: 0;
line-height: 1.3;
text-align: justify;
}
]]

local book_meta_info_group = VerticalGroup:new{
align = "center",
padding = 0,
bordersize = 0,
ScrollTextWidget:new{
text = self.dates.description,
face = self.medium_font_face,
padding = 0,
ScrollHtmlWidget:new{
html_body = self.dates.description,
css = css,
width = self.screen_width * 0.9,
height = self.screen_height * 0.48,
dialog = self,
justified = true,
}
}
return CenterContainer:new{
Expand Down