<commit_before>import React, { PropTypes } from 'react';

class TextTrim extends React.Component {

	constructor( props ) {
		super( props );
		this.renderDangerously = props.dangerouslySetInnerHTML ? true : false;
		this.textTailRegex = new RegExp( ".(" + props.textTail + ")?$" );
	}

	componentDidMount() {
		this.trim();
	}

	componentDidUpdate() {
		this.trim();
	}

	trim() {
		const domProperty = this.renderDangerously ? 'innerHTML' : 'textContent';
		const element = this.refs.trimmer;
		const regex = this.textTailRegex;
		const textTail = this.props.textTail;

		let textTruncated = false;
		while ( element.scrollHeight - ( element.clientHeight || element.offsetHeight ) >= 1 ) {
			textTruncated = true;
			if ( element.contentText === textTail ) {
				break;
			}
			element[domProperty] = element[domProperty].replace( regex, textTail );
		}

		if ( !textTruncated ) {
			return;
		}

		const tailLength = textTail.length + 1;
		// If last character is trailing space, remove it.
		if ( element.textContent[element.textContent.length - tailLength] === ' ' ) {
			element[domProperty] =
				element[domProperty].substring( 0, element[domProperty].length - tailLength ) + textTail;
		}
	}

	render() {

		const style = {
			lineHeight: 'inherit',
			maxHeight: 'inherit',
			width: 'inherit',
			overflow: 'hidden'
		};

		if ( !this.renderDangerously ) {

			return (
				<div ref = 'trimmer' className = { this.props.className } style = { style } >
					{ this.props.children }
				</div>
			);
		}

		return (
			<div
				ref = 'trimmer'
				className = { this.props.className }
				style = { style }
				dangerouslySetInnerHTML = { this.props.dangerouslySetInnerHTML } />
		);
	}
}

TextTrim.propTypes = {
	className: PropTypes.string,
	textTail: PropTypes.string,
	dangerouslySetInnerHTML: PropTypes.object
};

TextTrim.defaultProps = {
	className: '',
	textTail: '...',
	dangerouslySetInnerHTML: null
};

export default TextTrim;
<commit_msg>- IE fix. IE does not inherit height properly<commit_after>import React, { PropTypes } from 'react';

class TextTrim extends React.Component {

	constructor( props ) {
		super( props );
		this.renderDangerously = props.dangerouslySetInnerHTML ? true : false;
		this.textTailRegex = new RegExp( ".(" + props.textTail + ")?$" );
	}

	componentDidMount() {
		this.trim();
	}

	componentDidUpdate() {
		this.trim();
	}

	trim() {
		const domProperty = this.renderDangerously ? 'innerHTML' : 'textContent';
		const element = this.refs.trimmer;
		const regex = this.textTailRegex;
		const textTail = this.props.textTail;

		let textTruncated = false;
		while ( element.scrollHeight - ( element.clientHeight || element.offsetHeight ) >= 1 ) {
			textTruncated = true;
			if ( element.contentText === textTail ) {
				break;
			}
			element[domProperty] = element[domProperty].replace( regex, textTail );
		}

		if ( !textTruncated ) {
			return;
		}

		const tailLength = textTail.length + 1;
		// If last character is trailing space, remove it.
		if ( element.textContent[element.textContent.length - tailLength] === ' ' ) {
			element[domProperty] =
				element[domProperty].substring( 0, element[domProperty].length - tailLength ) + textTail;
		}
	}

	render() {

		const style = {
			lineHeight: 'inherit',
			height: 'inherit',
			maxHeight: 'inherit',
			width: 'inherit',
			overflow: 'hidden'
		};

		if ( !this.renderDangerously ) {

			return (
				<div ref = 'trimmer' className = { this.props.className } style = { style } >
					{ this.props.children }
				</div>
			);
		}

		return (
			<div
				ref = 'trimmer'
				className = { this.props.className }
				style = { style }
				dangerouslySetInnerHTML = { this.props.dangerouslySetInnerHTML } />
		);
	}
}

TextTrim.propTypes = {
	className: PropTypes.string,
	textTail: PropTypes.string,
	dangerouslySetInnerHTML: PropTypes.object
};

TextTrim.defaultProps = {
	className: '',
	textTail: '...',
	dangerouslySetInnerHTML: null
};

export default TextTrim;

{'fraction_non_alphanumeric': 0.13063388768377923, 'fraction_numerical': 0.0014461315979754157, 'mean_word_length': 2.8532961931290624, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2918573', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1304, 'n_words': 270}