Skip to content

Commit

Permalink
[Mobile]Release 0.3.5 updates (#13768)
Browse files Browse the repository at this point in the history
* [Mobile]Remove unnecessary <strong> tags from post title (#13763)

* Add extra rootTagsToEliminate prop

* Fix lint issues

* Revert unnecessary prop

* Add code comment for the workaround fix
  • Loading branch information
pinarol authored Feb 8, 2019
1 parent 50ae68c commit 6ee1944
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/editor/src/components/post-title/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PostTitle extends Component {
return (
<RichText
tagName={ 'p' }
rootTagsToEliminate={ [ 'strong' ] }
onFocus={ this.onSelect }
onBlur={ this.props.onBlur } // always assign onBlur as a props
multiline={ false }
Expand Down
15 changes: 13 additions & 2 deletions packages/editor/src/components/rich-text/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,19 @@ export class RichText extends Component {
*/

removeRootTagsProduceByAztec( html ) {
const openingTagRegexp = RegExp( '^<' + this.props.tagName + '>', 'gim' );
const closingTagRegexp = RegExp( '</' + this.props.tagName + '>$', 'gim' );
let result = this.removeRootTag( this.props.tagName, html );
// Temporary workaround for https://github.com/WordPress/gutenberg/pull/13763
if ( this.props.rootTagsToEliminate ) {
this.props.rootTagsToEliminate.forEach( ( element ) => {
result = this.removeRootTag( element, result );
} );
}
return result;
}

removeRootTag( tag, html ) {
const openingTagRegexp = RegExp( '^<' + tag + '>', 'gim' );
const closingTagRegexp = RegExp( '</' + tag + '>$', 'gim' );
return html.replace( openingTagRegexp, '' ).replace( closingTagRegexp, '' );
}

Expand Down

0 comments on commit 6ee1944

Please sign in to comment.