From 9023ca2fc2cd76021123f7653112aa44e1181d6e Mon Sep 17 00:00:00 2001 From: Robert Anderson Date: Mon, 28 Oct 2019 11:23:39 +1100 Subject: [PATCH] Raw handling: Fix strikethrough formatting when copy/pasting from Google Docs in Safari (#17187) --- .../src/api/raw-handling/phrasing-content-reducer.js | 11 ++++++++++- test/integration/fixtures/google-docs-out.html | 2 +- .../fixtures/google-docs-with-comments-out.html | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js b/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js index 5c5ef223298fe6..4f3c3a2a810a99 100644 --- a/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js +++ b/packages/blocks/src/api/raw-handling/phrasing-content-reducer.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { includes } from 'lodash'; + /** * WordPress dependencies */ @@ -11,6 +16,7 @@ export default function( node, doc ) { fontWeight, fontStyle, textDecorationLine, + textDecoration, verticalAlign, } = node.style; @@ -22,7 +28,10 @@ export default function( node, doc ) { wrap( doc.createElement( 'em' ), node ); } - if ( textDecorationLine === 'line-through' ) { + // Some DOM implementations (Safari, JSDom) don't support + // style.textDecorationLine, so we check style.textDecoration as a + // fallback. + if ( textDecorationLine === 'line-through' || includes( textDecoration, 'line-through' ) ) { wrap( doc.createElement( 's' ), node ); } diff --git a/test/integration/fixtures/google-docs-out.html b/test/integration/fixtures/google-docs-out.html index 576b2cd7fda73f..54a1e07ac1349a 100644 --- a/test/integration/fixtures/google-docs-out.html +++ b/test/integration/fixtures/google-docs-out.html @@ -7,7 +7,7 @@

This is a heading

-

Formatting test: bold, italic, link, strikethrough, superscript, subscript, nested.

+

Formatting test: bold, italic, link, strikethrough, superscript, subscript, nested.

diff --git a/test/integration/fixtures/google-docs-with-comments-out.html b/test/integration/fixtures/google-docs-with-comments-out.html index 576b2cd7fda73f..54a1e07ac1349a 100644 --- a/test/integration/fixtures/google-docs-with-comments-out.html +++ b/test/integration/fixtures/google-docs-with-comments-out.html @@ -7,7 +7,7 @@

This is a heading

-

Formatting test: bold, italic, link, strikethrough, superscript, subscript, nested.

+

Formatting test: bold, italic, link, strikethrough, superscript, subscript, nested.