From 44bd80ae1bf42ce26ddc76f95b343301485bc6e5 Mon Sep 17 00:00:00 2001 From: Bart Date: Thu, 29 Oct 2020 17:35:44 +0100 Subject: [PATCH 1/9] Strip HTML from caption when saving as alt attribute --- packages/block-library/src/gallery/save.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/gallery/save.js b/packages/block-library/src/gallery/save.js index 263055c0681e9..b0845abc18d82 100644 --- a/packages/block-library/src/gallery/save.js +++ b/packages/block-library/src/gallery/save.js @@ -2,6 +2,7 @@ * WordPress dependencies */ import { RichText } from '@wordpress/block-editor'; +import { __unstableStripHTML } from '@wordpress/dom'; /** * Internal dependencies @@ -43,7 +44,11 @@ export default function save( { attributes } ) { const img = ( { Date: Thu, 29 Oct 2020 18:25:01 +0100 Subject: [PATCH 2/9] Add fixture for caption test --- .../core__gallery__image-with-caption.html | 18 +++++++++++ .../core__gallery__image-with-caption.json | 31 +++++++++++++++++++ ...e__gallery__image-with-caption.parsed.json | 25 +++++++++++++++ ...allery__image-with-caption.serialized.html | 3 ++ 4 files changed, 77 insertions(+) create mode 100644 packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html create mode 100644 packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.parsed.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.serialized.html diff --git a/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html new file mode 100644 index 0000000000000..31d0c86d59d15 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html @@ -0,0 +1,18 @@ + + + diff --git a/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.json b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.json new file mode 100644 index 0000000000000..70150767de28e --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.json @@ -0,0 +1,31 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/gallery", + "isValid": true, + "attributes": { + "images": [ + { + "url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==", + "alt": "", + "caption": "Caption with a link" + }, + { + "url": "data:image/jpeg;base64,/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=", + "alt": "", + "caption": "Caption without a link" + } + ], + "ids": [ + null, + null + ], + "caption": "", + "imageCrop": true, + "linkTo": "none", + "sizeSlug": "large" + }, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.parsed.json b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.parsed.json new file mode 100644 index 0000000000000..58bb78328f48e --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.parsed.json @@ -0,0 +1,25 @@ +[ + { + "blockName": "core/gallery", + "attrs": { + "ids": [ + null, + null + ] + }, + "innerBlocks": [], + "innerHTML": "\n\n", + "innerContent": [ + "\n\n" + ] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.serialized.html b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.serialized.html new file mode 100644 index 0000000000000..9148ad41cfa2f --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.serialized.html @@ -0,0 +1,3 @@ + + + From 599038193b69c401a93cb2be7de518fbfcfef421 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 29 Oct 2020 19:16:04 +0100 Subject: [PATCH 3/9] Fix tures --- .../fixtures/blocks/core__gallery__image-with-caption.html | 4 ++-- .../fixtures/blocks/core__gallery__image-with-caption.json | 6 +++--- .../blocks/core__gallery__image-with-caption.parsed.json | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html index 31d0c86d59d15..f20ee4f773ff8 100644 --- a/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html +++ b/packages/e2e-tests/fixtures/blocks/core__gallery__image-with-caption.html @@ -3,13 +3,13 @@