From 1a4af7c0d057a41b4087b16a11e65b2e8cbc2b7c Mon Sep 17 00:00:00 2001 From: Gijs van Tulder Date: Wed, 4 Sep 2024 22:14:50 +0200 Subject: [PATCH] clean: Do not insert spaces between colons in pseudo-elements (::before) --- se/formatting.py | 2 +- .../clean/test-2/golden/src/epub/css/local.css | 17 +++++++++++++++++ .../clean/test-2/in/src/epub/css/local.css | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/draft_commands/clean/test-2/golden/src/epub/css/local.css create mode 100644 tests/draft_commands/clean/test-2/in/src/epub/css/local.css diff --git a/se/formatting.py b/se/formatting.py index 4799f8b5..03a82119 100644 --- a/se/formatting.py +++ b/se/formatting.py @@ -889,7 +889,7 @@ def _format_css_component_list(content: list, in_selector=False, in_paren_block= # Here we try to re-add spaces after a : if it's within a paren block. # We could do this during parsing but we would need to peek ahead to the next item in the loop which # is too much trouble right now. - output = regex.sub(r"\(([^\"\s]+?):([^\"\s]+?)", r"(\1: \2", output) + output = regex.sub(r"\(([^\"\s)]+?):([^\"\s]+?)", r"(\1: \2", output) return output.strip() diff --git a/tests/draft_commands/clean/test-2/golden/src/epub/css/local.css b/tests/draft_commands/clean/test-2/golden/src/epub/css/local.css new file mode 100644 index 00000000..f50b5c51 --- /dev/null +++ b/tests/draft_commands/clean/test-2/golden/src/epub/css/local.css @@ -0,0 +1,17 @@ +p:nth-of-type(1)::before{ + content: "test"; +} + +@media all and (prefers-color-scheme: dark){ + p{ + text-align: initial; + } +} + +#chapter-1::after{ + content: "test"; +} + +#chapter-1 tr:first-child{ + content: "test"; +} diff --git a/tests/draft_commands/clean/test-2/in/src/epub/css/local.css b/tests/draft_commands/clean/test-2/in/src/epub/css/local.css new file mode 100644 index 00000000..c378444a --- /dev/null +++ b/tests/draft_commands/clean/test-2/in/src/epub/css/local.css @@ -0,0 +1,9 @@ + + +p:nth-of-type(1)::before{content: "test";} + @media all and (prefers-color-scheme:dark){p{text-align:initial;}} + + +#chapter-1::after {content: "test";} + #chapter-1 tr:first-child{ +content: "test";}