PluginProbe
TablePress – Tables in WordPress made easy / 3.0
TablePress – Tables in WordPress made easy v3.0
3.3.4 3.3.3 3.3.2 3.3.1 trunk 1.12 1.14 1.9.2 2.0.4 2.1.7 2.1.8 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3 2.3.1 2.3.2 2.4 2.4.1 2.4.2 2.4.3 2.4.4 All 44 releases
← All changes | blocks/table/src/transforms.js +7 -27 trunk3.0 View file →
@@ -22,42 +22,23 @@
22 22
23 23 /**
24 24 * Internal dependencies.
25 25 */
26 -import { shortcodeAttrsToString } from './common/functions';
26 +import { shortcode_attrs_to_string } from './common/functions';
27 27
28 28 /**
29 - * Converts a set of parsed Shortcode attributes to a parameters string.
30 - *
31 - * @param {Object} shortcodeAttrs The Shortcode attributes.
32 - * @return {string} The parameters string.
33 - */
34 -const convertShortcodeAttrsToParametersString = ( shortcodeAttrs ) => {
35 - // Remove the `id` attribute from the Shortcode parameters, as it is handled separately.
36 - delete shortcodeAttrs.named.id;
37 -
38 - let parameters = shortcodeAttrsToString( shortcodeAttrs );
39 -
40 - // Replace curly quotation marks around a value with normal ones.
41 - parameters = parameters.replace( /=“([^”]*)”/g, '="$1"' );
42 -
43 - // Decode HTML entities like `&`, `<`, `>`, `[`, and `]` that were encoded in the Shortcode.
44 - parameters = parameters.replaceAll( '&amp;', '&' ).replaceAll( '&lt;', '<' ).replaceAll( '&gt;', '>' ).replaceAll( '&lsqb;', '[' ).replaceAll( '&rsqb;', ']' );
45 -
46 - return parameters;
47 -};
48 -
49 -/**
50 29 * Converts a textual Shortcode to a TablePress table block.
51 30 *
52 31 * @param {string} content The Shortcode as a text string.
53 32 * @return {Object} TablePress table block.
54 33 */
55 -const convertShortcodeTextToBlock = ( content ) => {
34 +const convertShortcodeTextToBlock = function ( content ) {
56 35 let shortcodeAttrs = shortcode.next( tp.table.shortcode, content ).shortcode.attrs;
57 36 shortcodeAttrs = { named: { ...shortcodeAttrs.named }, numeric: [ ...shortcodeAttrs.numeric ] }; // Use object destructuring to get a clone of the object.
58 37 const id = shortcodeAttrs.named.id;
59 - const parameters = convertShortcodeAttrsToParametersString( shortcodeAttrs );
38 + delete shortcodeAttrs.named.id;
39 + let parameters = shortcode_attrs_to_string( shortcodeAttrs );
40 + parameters = parameters.replace( /=“([^”]*)”/g, '="$1"' ); // Replace curly quotation marks around a value with normal ones.
60 41 return createBlock( block.name, { id, parameters } );
61 42 };
62 43
63 44 const transforms = {
@@ -76,9 +57,10 @@
76 57 parameters: {
77 58 type: 'string',
78 59 shortcode: ( shortcodeAttrs ) => {
79 60 shortcodeAttrs = { named: { ...shortcodeAttrs.named }, numeric: [ ...shortcodeAttrs.numeric ] }; // Use object destructuring to get a clone of the object.
80 - return convertShortcodeAttrsToParametersString( shortcodeAttrs );
61 + delete shortcodeAttrs.named.id;
62 + return shortcode_attrs_to_string( shortcodeAttrs );
81 63 },
82 64 },
83 65 },
84 66 },
@@ -110,10 +92,8 @@
110 92 transform: ( { id, parameters } ) => {
111 93 parameters = parameters.trim();
112 94 if ( '' !== parameters ) {
113 95 parameters += ' ';
114 - // Encode characters that cause problems in Shortcodes, e.g. due to sanitization, like `&`, `<`, `>`, `[`, and `]` to HTML entities.
115 - parameters = parameters.replaceAll( '&', '&amp;' ).replaceAll( '<', '&lt;' ).replaceAll( '>', '&gt;' ).replaceAll( '[', '&lsqb;' ).replaceAll( ']', '&rsqb;' );
116 96 }
117 97 const text = `[${ tp.table.shortcode } id=${ id } ${ parameters }/]`;
118 98 return createBlock( 'core/shortcode', { text } );
119 99 },