diff --git a/lib/index.js b/lib/index.js index 770b00e..ac5317c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,7 @@ 'use strict' const postcss = require('postcss') +const safe = require('postcss-safe-parser') const mergeLonghand = require('postcss-merge-longhand') module.exports = (options = {}) => tree => { @@ -14,7 +15,7 @@ module.exports = (options = {}) => tree => { } if (node.attrs && node.attrs.style) { - const {css} = postcss().use(mergeLonghand).process(`div { ${node.attrs.style} }`) + const {css} = postcss().use(mergeLonghand).process(`div { ${node.attrs.style} }`, {parser: safe}) node.attrs.style = css.replace(/div {\s|\s}$/gm, '') } diff --git a/package-lock.json b/package-lock.json index 0407a65..deeef1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "postcss": "^8.1.10", "postcss-merge-longhand": "^6.0.0", + "postcss-safe-parser": "^7.0.0", "posthtml": "^0.16.4" }, "devDependencies": { @@ -8574,6 +8575,31 @@ "postcss": "^8.4.31" } }, + "node_modules/postcss-safe-parser": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/postcss-safe-parser/-/postcss-safe-parser-7.0.0.tgz", + "integrity": "sha512-ovehqRNVCpuFzbXoTb4qLtyzK3xn3t/CUBxOs8LsnQjQrShaB4lKiHoVqY8ANaC0hBMHq5QVWk77rwGklFUDrg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss-safe-parser" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "engines": { + "node": ">=18.0" + }, + "peerDependencies": { + "postcss": "^8.4.31" + } + }, "node_modules/postcss-selector-parser": { "version": "6.0.15", "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.0.15.tgz", @@ -17873,6 +17899,12 @@ "stylehacks": "^6.0.2" } }, + "postcss-safe-parser": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/postcss-safe-parser/-/postcss-safe-parser-7.0.0.tgz", + "integrity": "sha512-ovehqRNVCpuFzbXoTb4qLtyzK3xn3t/CUBxOs8LsnQjQrShaB4lKiHoVqY8ANaC0hBMHq5QVWk77rwGklFUDrg==", + "requires": {} + }, "postcss-selector-parser": { "version": "6.0.15", "resolved": "https://registry.npmjs.org/postcss-selector-parser/-/postcss-selector-parser-6.0.15.tgz", diff --git a/package.json b/package.json index ea6b6c4..87c7bbc 100644 --- a/package.json +++ b/package.json @@ -23,13 +23,15 @@ "postcss", "inline-styles", "inline-css", - "inline-css", + "merge-styles", + "merge-css", "longhand", "shorthand" ], "dependencies": { "postcss": "^8.1.10", "postcss-merge-longhand": "^6.0.0", + "postcss-safe-parser": "^7.0.0", "posthtml": "^0.16.4" }, "devDependencies": { diff --git a/test/expected/parser.html b/test/expected/parser.html new file mode 100644 index 0000000..d9b9367 --- /dev/null +++ b/test/expected/parser.html @@ -0,0 +1 @@ +