diff --git a/README.md b/README.md index e05da9c4..0f35ec46 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ We've removed the compatibility shim for the magical `content` attribute. If you * Added Spanish translation. * Bug fix: Prevent fataling when editor is loaded in the frontend context. * Bug fix: Color field should also support `meta` argument. +* Bug fix: Remove trailing whitespace from shortcodes without attributes. ### 0.3 (April 27, 2015) ### * **Breaking change**: We've removed the compatibility shim for the magical `content` attribute. If you were using this to support editing inner content, you'll need to change your UI registration to use `inner_content`. diff --git a/js-tests/build/specs.js b/js-tests/build/specs.js index 074449ca..d7f8f24c 100644 --- a/js-tests/build/specs.js +++ b/js-tests/build/specs.js @@ -120,6 +120,10 @@ describe( "Shortcode Model", function() { _shortcode.get('inner_content').unset( 'value' ); expect( _shortcode.formatShortcode() ).toEqual( '[test_shortcode attr="test value"]' ); + // Test without attributes + _shortcode.get( 'attrs' ).first().unset( 'value' ); + expect( _shortcode.formatShortcode() ).toEqual( '[test_shortcode]' ); + }); }); @@ -457,7 +461,11 @@ Shortcode = Backbone.Model.extend({ content = this.get( 'inner_content' ).get( 'value' ); } - template = "[{{ shortcode }} {{ attributes }}]" + if ( attrs.length > 0 ) { + template = "[{{ shortcode }} {{ attributes }}]" + } else { + template = "[{{ shortcode }}]" + } if ( content && content.length > 0 ) { template += "{{ content }}[/{{ shortcode }}]" diff --git a/js-tests/src/shortcodeModelSpec.js b/js-tests/src/shortcodeModelSpec.js index 27d51a37..7228d659 100644 --- a/js-tests/src/shortcodeModelSpec.js +++ b/js-tests/src/shortcodeModelSpec.js @@ -64,6 +64,10 @@ describe( "Shortcode Model", function() { _shortcode.get('inner_content').unset( 'value' ); expect( _shortcode.formatShortcode() ).toEqual( '[test_shortcode attr="test value"]' ); + // Test without attributes + _shortcode.get( 'attrs' ).first().unset( 'value' ); + expect( _shortcode.formatShortcode() ).toEqual( '[test_shortcode]' ); + }); }); diff --git a/js/build/field-attachment.js b/js/build/field-attachment.js index 50321975..0468bb0b 100644 --- a/js/build/field-attachment.js +++ b/js/build/field-attachment.js @@ -310,7 +310,11 @@ Shortcode = Backbone.Model.extend({ content = this.get( 'inner_content' ).get( 'value' ); } - template = "[{{ shortcode }} {{ attributes }}]" + if ( attrs.length > 0 ) { + template = "[{{ shortcode }} {{ attributes }}]" + } else { + template = "[{{ shortcode }}]" + } if ( content && content.length > 0 ) { template += "{{ content }}[/{{ shortcode }}]" diff --git a/js/build/field-color.js b/js/build/field-color.js index bcc5db7c..0d5d663c 100644 --- a/js/build/field-color.js +++ b/js/build/field-color.js @@ -177,7 +177,11 @@ Shortcode = Backbone.Model.extend({ content = this.get( 'inner_content' ).get( 'value' ); } - template = "[{{ shortcode }} {{ attributes }}]" + if ( attrs.length > 0 ) { + template = "[{{ shortcode }} {{ attributes }}]" + } else { + template = "[{{ shortcode }}]" + } if ( content && content.length > 0 ) { template += "{{ content }}[/{{ shortcode }}]" diff --git a/js/build/shortcode-ui.js b/js/build/shortcode-ui.js index 0c134678..42f9b410 100644 --- a/js/build/shortcode-ui.js +++ b/js/build/shortcode-ui.js @@ -210,7 +210,11 @@ Shortcode = Backbone.Model.extend({ content = this.get( 'inner_content' ).get( 'value' ); } - template = "[{{ shortcode }} {{ attributes }}]" + if ( attrs.length > 0 ) { + template = "[{{ shortcode }} {{ attributes }}]" + } else { + template = "[{{ shortcode }}]" + } if ( content && content.length > 0 ) { template += "{{ content }}[/{{ shortcode }}]" diff --git a/js/src/models/shortcode.js b/js/src/models/shortcode.js index eb9cae80..52da7498 100644 --- a/js/src/models/shortcode.js +++ b/js/src/models/shortcode.js @@ -79,7 +79,11 @@ Shortcode = Backbone.Model.extend({ content = this.get( 'inner_content' ).get( 'value' ); } - template = "[{{ shortcode }} {{ attributes }}]" + if ( attrs.length > 0 ) { + template = "[{{ shortcode }} {{ attributes }}]" + } else { + template = "[{{ shortcode }}]" + } if ( content && content.length > 0 ) { template += "{{ content }}[/{{ shortcode }}]" diff --git a/readme.txt b/readme.txt index 82107831..1acbd407 100644 --- a/readme.txt +++ b/readme.txt @@ -47,6 +47,7 @@ We've removed the compatibility shim for the magical `content` attribute. If you * Added Spanish translation. * Bug fix: Prevent fataling when editor is loaded in the frontend context. * Bug fix: Color field should also support `meta` argument. +* Bug fix: Remove trailing whitespace from shortcodes without attributes. = 0.3 (April 27, 2015) = * **Breaking change**: We've removed the compatibility shim for the magical `content` attribute. If you were using this to support editing inner content, you'll need to change your UI registration to use `inner_content`.