PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | modules/shortcodes/js/slideshow-shortcode.js +32 -1 16.2 → 16.3 View file →
@@ -1,6 +1,37 @@
1 1 /* global jetpackSlideshowSettings */
2 2
3 +/**
4 + * Turn a gallery caption into the plain text it is meant to be.
5 + *
6 + * A caption is meant to read as text, but wptexturize() leaves HTML entities behind, so it needs
7 + * decoding before it can be set as one.
8 + *
9 + * @param {*} caption - Caption value from the gallery data.
10 + * @return {string} The decoded caption, as text.
11 + */
12 +function jetpackSlideshowCaptionText( caption ) {
13 + if ( typeof caption !== 'string' || '' === caption ) {
14 + return '';
15 + }
16 +
17 + var parsed = new DOMParser().parseFromString( caption, 'text/html' );
18 +
19 + // These land in the body when they appear mid-caption, and their source is not caption text.
20 + parsed.body
21 + .querySelectorAll( 'script, style, noscript, template' )
22 + .forEach( function ( element ) {
23 + element.remove();
24 + } );
25 +
26 + // Without a space in its place, a caption broken over two lines reads as "Ada LovelaceLondon".
27 + parsed.body.querySelectorAll( 'br' ).forEach( function ( element ) {
28 + element.replaceWith( ' ' );
29 + } );
30 +
31 + return parsed.body.textContent;
32 +}
33 +
3 34 function JetpackSlideshow( element, transition, autostart ) {
4 35 this.element = element;
5 36 this.images = [];
6 37 this.controls = {};
@@ -38,9 +69,9 @@
38 69 img.nopin = 'nopin';
39 70 var caption = document.createElement( 'div' );
40 71 caption.className = 'jetpack-slideshow-slide-caption';
41 72 caption.setAttribute( 'itemprop', 'caption description' );
42 - caption.innerHTML = imageInfo.caption;
73 + caption.textContent = jetpackSlideshowCaptionText( imageInfo.caption );
43 74 var container = document.createElement( 'div' );
44 75 container.className = 'jetpack-slideshow-slide';
45 76 container.setAttribute( 'itemprop', 'associatedMedia' );
46 77 container.setAttribute( 'itemscope', '' );