Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RNMobile] Activate preformat on android #18777

Merged
merged 10 commits into from
Dec 9, 2019
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' ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clear way of shortcircuiting willTrimSpaces in the Preformatted block case!

Can you also add a test in https://github.com/WordPress/gutenberg/blob/master/packages/rich-text/src/component/test/index.native.js to cover that case? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, thanks!

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 );
} );
} );
} );