mirror of
https://github.com/koreader/koreader
synced 2024-10-31 21:20:20 +00:00
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.
This commit is contained in:
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…
Reference in New Issue
Block a user