Skip to content

Commit 70c2087

Browse files
authored
Merge pull request #120 from KevinBatdorf/remove-unecessary-escape
Remove unecessary escape
2 parents a2fea1f + ebf351c commit 70c2087

9 files changed

Lines changed: 7817 additions & 9084 deletions

File tree

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"quote-props": ["error", "as-needed"],
4949
"no-multiple-empty-lines": ["error", { "max": 1 }],
5050
"@typescript-eslint/no-var-requires": "off",
51+
"@typescript-eslint/no-require-imports": "off",
5152
"lines-around-comment": [
5253
"error",
5354
{

cypress/e2e/block.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ context('Pattern Css', () => {
310310
.invoke('text')
311311
.should(
312312
'contain',
313-
'background-image:url(https://foo.com/bar.jpg?</style><script>alert\\(1\\)</script>)',
313+
'background-image:url(https://foo.com/bar.jpg?</style><script>alert\\(1\\)</script>)',
314314
);
315315
});
316316
});

package-lock.json

Lines changed: 7771 additions & 9049 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
2121
"@types/wordpress__block-editor": "^11.5.15",
2222
"@types/wordpress__blocks": "^12.5.14",
23-
"@types/wordpress__edit-post": "^7.5.7",
24-
"@types/wordpress__editor": "^13.6.8",
25-
"@types/wordpress__plugins": "^3.0.3",
26-
"@typescript-eslint/eslint-plugin": "^7.16.1",
27-
"@typescript-eslint/parser": "^7.16.1",
28-
"@wordpress/block-editor": "^13.3.0",
29-
"@wordpress/env": "^10.3.0",
30-
"@wordpress/scripts": "^28.3.0",
31-
"@wordpress/url": "^4.3.0",
32-
"autoprefixer": "^10.4.19",
33-
"cypress": "^13.13.1",
23+
"@types/wordpress__edit-post": "^8.4.0",
24+
"@types/wordpress__editor": "^14.3.0",
25+
"@types/wordpress__plugins": "^6.0.0",
26+
"@typescript-eslint/eslint-plugin": "^8.6.0",
27+
"@typescript-eslint/parser": "^8.6.0",
28+
"@wordpress/block-editor": "^14.3.0",
29+
"@wordpress/env": "^10.8.0",
30+
"@wordpress/scripts": "^30.0.2",
31+
"@wordpress/url": "^4.8.0",
32+
"autoprefixer": "^10.4.20",
33+
"cypress": "^13.14.2",
3434
"cypress-wait-until": "^3.0.2",
3535
"eslint": "^8.57.0",
3636
"eslint-config-prettier": "^9.1.0",
@@ -45,23 +45,23 @@
4545
"postcss-safe-important": "^2.0.1",
4646
"prettier": "^3.3.3",
4747
"replace-in-file": "^8.1.0",
48-
"tailwindcss": "^3.4.6",
49-
"typescript": "^5.5.3"
48+
"tailwindcss": "^3.4.12",
49+
"typescript": "^5.6.2"
5050
},
5151
"dependencies": {
52-
"@wordpress/block-editor": "^13.3.0",
53-
"@wordpress/blocks": "^13.3.0",
54-
"@wordpress/edit-post": "^8.3.0",
55-
"@wordpress/editor": "^14.3.0",
56-
"@wordpress/element": "^6.3.0",
57-
"@wordpress/i18n": "^5.3.0",
58-
"@wordpress/plugins": "^7.3.0",
52+
"@wordpress/block-editor": "^14.3.0",
53+
"@wordpress/blocks": "^13.8.0",
54+
"@wordpress/edit-post": "^8.8.3",
55+
"@wordpress/editor": "^14.8.3",
56+
"@wordpress/element": "^6.8.0",
57+
"@wordpress/i18n": "^5.8.0",
58+
"@wordpress/plugins": "^7.8.0",
5959
"browserlist": "^1.0.1",
60-
"lightningcss": "1.25.1",
61-
"lightningcss-wasm": "1.25.1",
60+
"lightningcss": "1.27.0",
61+
"lightningcss-wasm": "1.27.0",
6262
"react-simple-code-editor": "^0.14.1",
6363
"shiki": "^0.14.7",
6464
"swr": "^2.2.5",
65-
"zustand": "^4.5.4"
65+
"zustand": "^4.5.5"
6666
}
6767
}

pattern-css.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Description: Lightening Fast, Safe, In-editor CSS Optimization and Minification Tool
55
* Requires at least: 6.0
66
* Requires PHP: 7.0
7-
* Version: 1.2.5
7+
* Version: 1.2.6
88
* Author: Kevin Batdorf
99
* Author URI: https://twitter.com/kevinbatdorf
1010
* License: GPL-2.0-or-later

postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = ({ mode }) => ({
88
(css) =>
99
css.walkRules((rule) => {
1010
// Removes top level TW styles like *::before {}
11-
rule.selector.startsWith('*') && rule.remove();
11+
if (rule.selector.startsWith('*')) rule.remove();
1212
}),
1313
// See: https://github.com/WordPress/gutenberg/blob/trunk/packages/postcss-plugins-preset/lib/index.js
1414
require('autoprefixer')({ grid: true }),

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Contributors: kbat82
33
Tags: css, styles, inline, margin, pattern
44
Tested up to: 6.6
5-
Stable tag: 1.2.5
5+
Stable tag: 1.2.6
66
License: GPL-2.0-or-later
77
License URI: https://www.gnu.org/licenses/gpl-2.0.html
88

@@ -131,6 +131,9 @@ Add this to functions.php:
131131

132132
== Changelog ==
133133

134+
= 1.2.6 - 2024-09-20 =
135+
- Removes an unecessary html escape that mangled some css.
136+
134137
= 1.2.5 - 2024-07-28 =
135138
- Fixed a small bug where a block may not have attributes when we access them.
136139

src/components/BlockControl.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import {
1616
useRef,
1717
} from '@wordpress/element';
1818
import { useSelect } from '@wordpress/data';
19-
import { escapeHTML } from '@wordpress/escape-html';
2019
import { sprintf, __ } from '@wordpress/i18n';
2120
import { Warning as CssWarning, Rule } from 'lightningcss-wasm';
2221
import { CodeEditor } from './CodeEditor';
2322
import { focusAtEndOfLine2 } from '../lib/dom';
2423
import { EditorControls } from './EditorControls';
2524
import { store as coreStore } from '@wordpress/editor';
2625
import { addToClassList } from '../lib/classes';
26+
import { escapeCSS } from '../lib/formatting';
2727

2828
export const BlockControl = (
2929
// eslint-disable-next-line
@@ -54,14 +54,13 @@ export const BlockControl = (
5454
const defaultCssExample = '[block] {\n \n}';
5555

5656
const handleChange = useCallback(
57-
(value?: string) => {
58-
if (value === undefined) {
57+
(css?: string) => {
58+
if (css === undefined) {
5959
setCss(undefined);
6060
return;
6161
}
62-
const css = escapeHTML(value);
6362
setWarnings([]);
64-
setCss(css);
63+
setCss(escapeCSS(css));
6564

6665
if (!window.patternCss?.transform) return;
6766

@@ -197,9 +196,11 @@ export const BlockControl = (
197196
: document.createElement('style');
198197
style.id = id;
199198
style.innerHTML = compiled;
200-
frame?.document?.head
201-
? frame.document.head.appendChild(style)
202-
: parent.appendChild(style);
199+
if (frame?.document?.head) {
200+
frame.document.head.appendChild(style);
201+
} else {
202+
parent.appendChild(style);
203+
}
203204
}, [compiled, pcssClassId]);
204205

205206
return (

src/lib/formatting.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const escapeCSS = (url: string) =>
2+
url
3+
.replace(/<\s*script\s*>/gi, '&lt;script&gt;')
4+
.replace(/<\s*\/\s*script\s*>/gi, '&lt;/script&gt;')
5+
.replace(/<\s*style\s*>/gi, '&lt;style&gt;')
6+
.replace(/<\s*\/\s*style\s*>/gi, '&lt;/style&gt;');

0 commit comments

Comments
 (0)