<commit_before>import React, {Component, PropTypes} from 'react'
import htmlToElement from './htmlToElement'
import {
  Linking,
  StyleSheet,
  Text,
} from 'react-native'

const boldStyle = {fontWeight: '500'}
const italicStyle = {fontStyle: 'italic'}
const codeStyle = {fontFamily: 'Menlo'}

const baseStyles = StyleSheet.create({
  b: boldStyle,
  strong: boldStyle,
  i: italicStyle,
  em: italicStyle,
  pre: codeStyle,
  code: codeStyle,
  a: {
    fontWeight: '500',
    color: '#007AFF',
  },
})

class HtmlView extends Component {
  constructor() {
    super()
    this.state = {
      element: null,
    }
  }

  componentDidMount() {
    this.mounted = true
    this.startHtmlRender(this.props.value)
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.value !== nextProps.value) {
      this.startHtmlRender(nextProps.value)
    }
  }

  componentWillUnmount() {
    this.mounted = false
  }

  startHtmlRender(value) {
    if (!value) {
      this.setState({element: null})
    }

    const opts = {
      linkHandler: this.props.onLinkPress,
      styles: Object.assign({}, baseStyles, this.props.stylesheet),
      customRenderer: this.props.renderNode,
    }

    htmlToElement(value, opts, (err, element) => {
      if (err) {
        this.props.onError(err)
      }

      if (this.mounted) {
        this.setState({element})
      }
    })
  }

  render() {
    if (this.state.element) {
      return <Text children={this.state.element} />
    }
    return <Text />
  }
}

HtmlView.propTypes = {
  value: PropTypes.string,
  stylesheet: PropTypes.object,
  onLinkPress: PropTypes.func,
  onError: PropTypes.func,
  renderNode: PropTypes.func,
}

HtmlView.defaultProps = {
  onLinkPress: url => Linking.openURL(url),
  onError: console.error.bind(console),
}

export default HtmlView
<commit_msg>Rerender HTML when style is changed<commit_after>import React, {Component, PropTypes} from 'react'
import htmlToElement from './htmlToElement'
import {
  Linking,
  StyleSheet,
  Text,
} from 'react-native'

const boldStyle = {fontWeight: '500'}
const italicStyle = {fontStyle: 'italic'}
const codeStyle = {fontFamily: 'Menlo'}

const baseStyles = StyleSheet.create({
  b: boldStyle,
  strong: boldStyle,
  i: italicStyle,
  em: italicStyle,
  pre: codeStyle,
  code: codeStyle,
  a: {
    fontWeight: '500',
    color: '#007AFF',
  },
})

class HtmlView extends Component {
  constructor() {
    super()
    this.state = {
      element: null,
    }
  }

  componentDidMount() {
    this.mounted = true
    this.startHtmlRender(this.props.value)
  }

  componentWillReceiveProps(nextProps) {
    if (this.props.value !== nextProps.value || this.props.stylesheet !== nextProps.stylesheet) {
      this.startHtmlRender(nextProps.value, nextProps.stylesheet)
    }
  }

  componentWillUnmount() {
    this.mounted = false
  }

  startHtmlRender(value, style) {
    if (!value) {
      this.setState({element: null})
    }

    const opts = {
      linkHandler: this.props.onLinkPress,
      styles: Object.assign({}, baseStyles, this.props.stylesheet, style),
      customRenderer: this.props.renderNode,
    }

    htmlToElement(value, opts, (err, element) => {
      if (err) {
        this.props.onError(err)
      }

      if (this.mounted) {
        this.setState({element})
      }
    })
  }

  render() {
    if (this.state.element) {
      return <Text children={this.state.element} />
    }
    return <Text />
  }
}

HtmlView.propTypes = {
  value: PropTypes.string,
  stylesheet: PropTypes.object,
  onLinkPress: PropTypes.func,
  onError: PropTypes.func,
  renderNode: PropTypes.func,
}

HtmlView.defaultProps = {
  onLinkPress: url => Linking.openURL(url),
  onError: console.error.bind(console),
}

export default HtmlView

{'fraction_non_alphanumeric': 0.13177470775770456, 'fraction_numerical': 0.004782146652497344, 'mean_word_length': 3.0968443960826986, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2911114', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1250, 'n_words': 254}