<commit_before>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {ContentState, CompositeDecorator, Editor, EditorState, RichUtils, convertFromHTML, getDefaultKeyBinding } from 'draft-js'
import { convertToHTML } from 'draft-convert'
import 'draft-js/dist/Draft.css'
import './RichTextEditor.css'

class RichTextEditor extends Component {
	static propTypes = {
		value: PropTypes.string,
		onChange: PropTypes.func,
	}
	constructor(props) {
		super(props)
		const decorator = new CompositeDecorator([
			{
				strategy: findImageEntities,
				component: ReactImage,
			},
		])

		this.state = {
			editorState: EditorState.createEmpty(decorator),
			decorator,
			isLoaded: false,
		}
		this.focus = () => this.refs.editor.focus()
		this.onChange = (editorState) => this.setState({editorState}, this.handleOnChangeHTML(editorState))

		this.handleOnChangeHTML = this._handleOnChangeHTML.bind(this)
		this.handleKeyCommand = this._handleKeyCommand.bind(this)
		this.mapKeyToEditorCommand = this._mapKeyToEditorCommand.bind(this)
		this.toggleBlockType = this._toggleBlockType.bind(this)
		this.toggleInlineStyle = this._toggleInlineStyle.bind(this)
		this.setEditorStateFromHTML = this._setEditorStateFromHTML.bind(this)
	}

	componentDidUpdate() {
		const { value } = this.props
		if(value !== undefined && value.length > 0) {
			this.setEditorStateFromHTML(value)
		}
	}

	componentDidMount() {
		const { value } = this.props
		if(value !== undefined && value.length > 0) {
			this.setEditorStateFromHTML(value)
		}
	}

	_handleOnChangeHTML(editorState) {
		const html = convertToHTML({
			entityToHTML: (entity, originalText) => {
				if (entity.type === 'IMAGE') {
					const { src, width, height, alt } = entity.data
					return <img src={imageDataSrc(src)} width={width} height={height} alt={alt} />
				}
				return originalText
			}
		})(editorState.getCurrentContent())
		this.props.onChange(html)
	}<commit_msg>GH-501 Fix handle convert to HTML callback<commit_after>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import {ContentState, CompositeDecorator, Editor, EditorState, RichUtils, convertFromHTML, getDefaultKeyBinding } from 'draft-js'
import { convertToHTML } from 'draft-convert'
import 'draft-js/dist/Draft.css'
import './RichTextEditor.css'

class RichTextEditor extends Component {
	static propTypes = {
		value: PropTypes.string,
		onChange: PropTypes.func,
	}
	constructor(props) {
		super(props)
		const decorator = new CompositeDecorator([
			{
				strategy: findImageEntities,
				component: ReactImage,
			},
		])

		this.state = {
			editorState: EditorState.createEmpty(decorator),
			decorator,
			isLoaded: false,
		}
		this.handleOnChangeHTML = this._handleOnChangeHTML.bind(this)
		this.handleKeyCommand = this._handleKeyCommand.bind(this)
		this.mapKeyToEditorCommand = this._mapKeyToEditorCommand.bind(this)
		this.toggleBlockType = this._toggleBlockType.bind(this)
		this.toggleInlineStyle = this._toggleInlineStyle.bind(this)
		this.setEditorStateFromHTML = this._setEditorStateFromHTML.bind(this)

		this.focus = () => this.refs.editor.focus()
		this.onChange = (editorState) => this.setState({editorState}, this.handleOnChangeHTML)
	}

	componentDidUpdate() {
		const { value } = this.props
		if(value !== undefined && value.length > 0) {
			this.setEditorStateFromHTML(value)
		}
	}

	componentDidMount() {
		const { value } = this.props
		if(value !== undefined && value.length > 0) {
			this.setEditorStateFromHTML(value)
		}
	}

	_handleOnChangeHTML() {
		const { editorState } = this.state
		const html = convertToHTML({
			entityToHTML: (entity, originalText) => {
				if (entity.type === 'IMAGE') {
					const { src, width, height, alt } = entity.data
					return <img src={imageDataSrc(src)} width={width} height={height} alt={alt} />
				}
				return originalText
			}
		})(editorState.getCurrentContent())
		this.props.onChange(html)
	}
{'fraction_non_alphanumeric': 0.12436676798378926, 'fraction_numerical': 0.0017730496453900709, 'mean_word_length': 4.538569424964937, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '353645', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1248, 'n_words': 239}