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.
pull/4288/head
poire-z 6 years ago
parent b3efd5a333
commit 2a8ab2b311

@ -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,

Loading…
Cancel
Save