diff --git a/package-lock.json b/package-lock.json index 2b8bd839a21..12a22fccfb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -110,7 +110,7 @@ "eslint": "^10.13.0", "eslint-plugin-cypress": "^7.0.2", "identity-obj-proxy": "^3.0.0", - "jsdom": "^30.1.2", + "jsdom": "^30.1.3", "prosemirror-schema-basic": "^1.2.5", "prosemirror-test-builder": "^1.1.1", "rollup-plugin-webpack-stats": "^4.0.1", @@ -217,9 +217,9 @@ } }, "node_modules/@asamuzakjp/dom-selector": { - "version": "9.2.4", - "resolved": "https://registry.npmjs.org/@asamuzakjp/dom-selector/-/dom-selector-9.2.4.tgz", - "integrity": "sha512-YnVzxDxLaqL0t7Q4wfcgHZjg55Wm6y5EaO7Bhu3q9J7wq/8iw3PhsnWiOQhYekx4VexnbkgWpTT6n+QIV7kczw==", + "version": "10.0.4", + "resolved": "https://registry.npmjs.org/@asamuzakjp/dom-selector/-/dom-selector-10.0.4.tgz", + "integrity": "sha512-A6f1nKy99I6tyoK82U6kBHvQQZmdHmTmPzJYPY/0eaOW0r8/qPmEOwjGHs+hL/vCgOwQTupu4LT1XtXNUuDruA==", "dev": true, "license": "MIT", "dependencies": { @@ -13969,14 +13969,14 @@ } }, "node_modules/jsdom": { - "version": "30.1.2", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-30.1.2.tgz", - "integrity": "sha512-0FFE/jE1rppmVfUrJUgxqXjcwolZYIGtAgj1pTussMhNZxIxi7W/PvfWaMNroGi2B36X1IKHbexpZ9DhkoOPiQ==", + "version": "30.1.3", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-30.1.3.tgz", + "integrity": "sha512-hQMUPvRgN7KxsfIytDQji7bimuJeRQa6Qo5+iuiZQk5CafeRxLIA10/cG5YCBFNpD9RO3oqIiN4CO1Y44kxqXg==", "dev": true, "license": "MIT", "dependencies": { "@asamuzakjp/css-color": "^7.1.3", - "@asamuzakjp/dom-selector": "^9.2.4", + "@asamuzakjp/dom-selector": "^10.0.3", "@bramus/specificity": "^2.4.2", "@csstools/css-syntax-patches-for-csstree": "^1.1.15", "@exodus/bytes": "^1.16.0", @@ -13989,7 +13989,7 @@ "parse5": "^8.0.1", "saxes": "^6.0.0", "tough-cookie": "^6.0.2", - "undici": "^8.11.2", + "undici": "^8.12.1", "w3c-xmlserializer": "^6.0.0", "webidl-conversions": "^8.0.1", "whatwg-mimetype": "^5.0.0", @@ -14019,22 +14019,22 @@ } }, "node_modules/jsdom/node_modules/tldts": { - "version": "7.4.16", - "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.4.16.tgz", - "integrity": "sha512-QwBER5KMR86IIjpIiO7H/Z3IMJPsZ1A6RKPAqzTTgOyUQUSt9FdnKcqhTaJmkY6HVrgouZHZR0ncK5QxvmnQeg==", + "version": "7.4.19", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.4.19.tgz", + "integrity": "sha512-48dH6aSpQnpbzDUc4vIQZ1VjB8tkK+e8c1yx05/SZK+rkssgjEOlxDd/yU8/a4vGYQ9vRgJr9dwMq9TJ0b3X2Q==", "dev": true, "license": "MIT", "dependencies": { - "tldts-core": "^7.4.16" + "tldts-core": "^7.4.19" }, "bin": { "tldts": "bin/cli.js" } }, "node_modules/jsdom/node_modules/tldts-core": { - "version": "7.4.16", - "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.4.16.tgz", - "integrity": "sha512-MDolfaSJtlSK5Y0A1xl3277ekubZwobpBjugknDizI9O5Rm60a1m8k4ICK+MRsCDzPygT81mp3BBf5RKDlFRfA==", + "version": "7.4.19", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.4.19.tgz", + "integrity": "sha512-goNXV6Ho9TIOfpJZanTd6CKG5DyYgYAL+k+22T0SLh8l6+KHIfBUPFuePuSZv05UttIaaLmI9tb7TmGIdK5AkQ==", "dev": true, "license": "MIT" }, diff --git a/package.json b/package.json index bd9fd05e380..eb37ebc3a5f 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "eslint": "^10.13.0", "eslint-plugin-cypress": "^7.0.2", "identity-obj-proxy": "^3.0.0", - "jsdom": "^30.1.2", + "jsdom": "^30.1.3", "prosemirror-schema-basic": "^1.2.5", "prosemirror-test-builder": "^1.1.1", "rollup-plugin-webpack-stats": "^4.0.1", diff --git a/src/extensions/transformPastedHTML.ts b/src/extensions/transformPastedHTML.ts index 8c2d1e6f2c6..a47a3994686 100644 --- a/src/extensions/transformPastedHTML.ts +++ b/src/extensions/transformPastedHTML.ts @@ -58,17 +58,13 @@ function collapseWhiteSpace(textNode: Text) { const COLLAPSING_WHITE_SPACE_VALUES = ['normal', 'nowrap'] let ancestor = textNode.parentElement while (ancestor) { - // Chrome does not support getComputedStyle on detached dom - // https://lists.w3.org/Archives/Public/www-style/2018May/0031.html - // Therefore the following logic only works on Firefox - const style = getComputedStyle(ancestor) - const whiteSpace = style?.getPropertyValue('white-space') + // Only inline styles are considered, as Chrome does not compute + // styles for detached documents. + const whiteSpace = ancestor.style.getPropertyValue('white-space') if (whiteSpace) { - // Returns false if white-space has a value not listed in COLLAPSING_WHITE_SPACE_VALUES return COLLAPSING_WHITE_SPACE_VALUES.includes(whiteSpace) } - // Check for `tagName` as fallback on Chrome if (ancestor.tagName === 'PRE') { return false } diff --git a/src/tests/extensions/transformPastedHTML.spec.js b/src/tests/extensions/transformPastedHTML.spec.js index c0449278d69..fb9136d6186 100644 --- a/src/tests/extensions/transformPastedHTML.spec.js +++ b/src/tests/extensions/transformPastedHTML.spec.js @@ -60,4 +60,12 @@ describe('transformPastedHTML', () => { it('preserve newlines in deep nested code blocks', () => { expect(tr('
this\nis code\nplease preserve\n whitespace!\nThanks')).toBe('this\nis code\nplease preserve\n whitespace!\nThanks')
})
+
+ it('preserve newlines in children of tags with white-space: pre', () => {
+ expect(tr('a\nb')).toBe('a b')
+ })
})