Skip to content

Commit

Permalink
[RNMobile] Activate preformat on android (#18777)
Browse files Browse the repository at this point in the history
  • Loading branch information
marecar3 authored Dec 9, 2019
1 parent 57cb9ad commit 585c4e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 1 addition & 6 deletions packages/block-library/src/index.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* External dependencies
*/
import { Platform } from 'react-native';
/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -146,10 +142,9 @@ export const registerCoreBlocks = () => {
list,
quote,
mediaText,
preformatted,
gallery,
// eslint-disable-next-line no-undef
( ( Platform.OS === 'ios' ) || ( !! __DEV__ ) ) ? preformatted : null,
// eslint-disable-next-line no-undef
!! __DEV__ ? group : null,
spacer,
].forEach( registerBlock );
Expand Down
9 changes: 9 additions & 0 deletions packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,15 @@ export class RichText extends Component {
}

willTrimSpaces( html ) {
const {
tagName,
} = this.props;

// aztec won't trim spaces in a case of <pre> block, so we are excluding it
if ( tagName === 'pre' ) {
return false;
}

// regex for detecting spaces around block element html tags
const blockHtmlElements = '(div|br|blockquote|ul|ol|li|p|pre|h1|h2|h3|h4|h5|h6|iframe|hr)';
const leadingOrTrailingSpaces = new RegExp( `(\\s+)<\/?${ blockHtmlElements }>|<\/?${ blockHtmlElements }>(\\s+)`, 'g' );
Expand Down
6 changes: 6 additions & 0 deletions packages/rich-text/src/component/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ describe( 'RichText Native', () => {
const html = '<p><b>Hello</b> <strong>Hello</strong> WorldWorld!</p>';
expect( richText.willTrimSpaces( html ) ).toBe( false );
} );

it( 'reports false for Preformatted block', () => {
const html = '<pre>Hello World <br><br><br></pre>';
richText.props.tagName = 'pre';
expect( richText.willTrimSpaces( html ) ).toBe( false );
} );
} );
} );

0 comments on commit 585c4e9

Please sign in to comment.