From 2a8ab2b311949ce43a372c340e14b2910d0b7837 Mon Sep 17 00:00:00 2001 From: poire-z Date: Mon, 22 Oct 2018 18:47:01 +0200 Subject: [PATCH] View HTML: adds Prettify button to CSS viewer Quick and non-full-proof prettification, but quite good and enough to make unreadable/minified CSS files readable for Style tweaks cooking. --- .../apps/reader/modules/readerhighlight.lua | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerhighlight.lua b/frontend/apps/reader/modules/readerhighlight.lua index 017eb1960..10fb3b9fe 100644 --- a/frontend/apps/reader/modules/readerhighlight.lua +++ b/frontend/apps/reader/modules/readerhighlight.lua @@ -411,11 +411,42 @@ function ReaderHighlight:viewSelectionHTML(debug_view) text = T(_("View %1"), css_files[i]), callback = function() local css_text = self.ui.document:getDocumentFileContent(css_files[i]) - local cssviewer = TextViewer:new{ + local cssviewer + cssviewer = TextViewer:new{ title = css_files[i], text = css_text or _("Failed getting CSS content"), text_face = Font:getFace("smallinfont"), justified = false, + buttons_table = { + {{ + text = _("Prettify"), + enabled = css_text and true or false, + callback = function() + UIManager:close(cssviewer) + -- This is not perfect, but enough to make + -- some ugly CSS readable + css_text = css_text:gsub("%s*{%s*", " {\n ") + css_text = css_text:gsub(";%s*}%s*", ";\n}\n") + css_text = css_text:gsub(";%s*([^}])", ";\n %1") + css_text = css_text:gsub("%s*}%s*", "\n}\n") + css_text = css_text:gsub("%s*,%s*", " ,\n") + -- The last one is wrong inside {}, eg. with + -- "font-family: Georgia, serif" + UIManager:show(TextViewer:new{ + title = css_files[i], + text = css_text, + text_face = Font:getFace("smallinfont"), + justified = false, + }) + end, + }}, + {{ + text = _("Close"), + callback = function() + UIManager:close(cssviewer) + end, + }}, + } } UIManager:show(cssviewer) end,