diff --git a/frontend/ui/viewhtml.lua b/frontend/ui/viewhtml.lua
index 4cc48a094..47acd0af1 100644
--- a/frontend/ui/viewhtml.lua
+++ b/frontend/ui/viewhtml.lua
@@ -92,7 +92,7 @@ function ViewHtml:_viewSelectionHTML(document, selected_text, view, with_css_fil
-- pages to get to the HTML content on the initial view.)
end
if massage_html or hide_stylesheet_elem_content then
- replace_in_html("]*>(.-)", function(s)
+ replace_in_html("]*>.-", function(s)
local pre, css_text, post = s:match("(]*>)%s*(.-)%s*()")
if hide_stylesheet_elem_content then
return pre .. "[...]" .. post
@@ -101,8 +101,8 @@ function ViewHtml:_viewSelectionHTML(document, selected_text, view, with_css_fil
end)
end
-- Make sure we won't get wrapped just after our indentation if there is no break opportunity later
- replace_in_html("\n( *)", function(s)
- return "\n" .. ("\u{00A0}"):rep(#s)
+ replace_in_html("\n *", function(s)
+ return "\n" .. ("\u{00A0}"):rep(#s - 1)
end)
local textviewer
diff --git a/frontend/util.lua b/frontend/util.lua
index f6dd4a595..656620888 100644
--- a/frontend/util.lua
+++ b/frontend/util.lua
@@ -1249,6 +1249,8 @@ function util.prettifyCSS(css_text, condensed)
css_text = css_text:gsub("\n *([^\n]+){", "\n%1{") -- remove leading spaces on a standalone one
-- Make sure { is on the same line with the selector it follows
css_text = css_text:gsub("%s*\n *{", " {")
+ -- Make sure we have a newline after our }
+ css_text = css_text:gsub("\n} *([^\n]+)", "\n}\n%1")
-- Restore all protected chars
css_text = css_text:gsub("\v", ",")
css_text = css_text:gsub("\f", ":")