From 4bf4578d1729b17e45e678293b0e0d9b2fa7b224 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 4 May 2018 23:44:09 +0200 Subject: [PATCH] Add HTML widget in GoodReads review (#3929) --- plugins/goodreads.koplugin/goodreadsapi.lua | 25 ++------------------ plugins/goodreads.koplugin/goodreadsbook.lua | 23 +++++++++++++----- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/plugins/goodreads.koplugin/goodreadsapi.lua b/plugins/goodreads.koplugin/goodreadsapi.lua index 7706e5392..330878028 100644 --- a/plugins/goodreads.koplugin/goodreadsapi.lua +++ b/plugins/goodreads.koplugin/goodreadsapi.lua @@ -88,28 +88,6 @@ function GoodreadsApi:getTotalResults() return self.total_result end -local function cleanHTMLTags(str_html) - local cleaner = { - { "&", "&" }, - { "—", "-" }, - { "’", "'" }, - { " ", " " }, - { "", "%1" }, - { "", "\n" }, - { "%-%-", "%-" }, - { "

", "\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.")}) @@ -132,7 +110,8 @@ local function showIdTable(data) local id = data1:match("([^<]+)"):gsub("$", "") local author = data1:match("([^<]+)") local description = data1:match("(.*)") - description = cleanHTMLTags(description) + description = string.gsub(description, "", "%1") + description = string.gsub(description, "%-%-", "%—") --change format from medium to large local image = data1:match("([^<]+)"):gsub("([0-9]+)m/", "%1l/") local day = data1:match("]+>([^<]+)") diff --git a/plugins/goodreads.koplugin/goodreadsbook.lua b/plugins/goodreads.koplugin/goodreadsbook.lua index f09413e52..fdfe63299 100644 --- a/plugins/goodreads.koplugin/goodreadsbook.lua +++ b/plugins/goodreads.koplugin/goodreadsbook.lua @@ -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') @@ -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{