<commit_before>import EditorJS from '@editorjs/editorjs'
import Embed from '@editorjs/embed'
import Header from '@editorjs/header'
import List from '@editorjs/list'
import Paragraph from '@editorjs/paragraph'

class BlockEditor {
  static create ($element) {
    $element.hide()
    let editorId = $element.id + '-block-editor'
    $element.after('<div id="' + editorId + '"></div>')

    const editor = new EditorJS({
      holder: editorId,
      data: JSON.parse($element.text()),
      onChange: () => {
        editor.save().then((outputData) => {
          $element.val(JSON.stringify(outputData))
        }).catch((error) => {
          console.debug('Saving failed: ', error)
        })
      },
      tools: {
        paragraph: {
          class: Paragraph,
          inlineToolbar: true
        },
        header: {
          class: Header,
          shortcut: 'CMD+SHIFT+H'
        },
        list: {
          class: List,
          inlineToolbar: true
        },
        embed: {
          class: Embed,<commit_msg>Validate the data before passing it to the editor<commit_after>import EditorJS from '@editorjs/editorjs'
import Embed from '@editorjs/embed'
import Header from '@editorjs/header'
import List from '@editorjs/list'
import Paragraph from '@editorjs/paragraph'

class BlockEditor {
  static create ($element) {
    $element.hide()
    let editorId = $element.id + '-block-editor'
    $element.after('<div id="' + editorId + '"></div>')

    let data = {}
    try {
      data = JSON.parse($element.text())
    } catch (e) {
      // ignore the current content since we can't decode it
    }

    const editor = new EditorJS({
      holder: editorId,
      data: data,
      onChange: () => {
        editor.save().then((outputData) => {
          $element.val(JSON.stringify(outputData))
        }).catch((error) => {
          console.debug('Saving failed: ', error)
        })
      },
      tools: {
        paragraph: {
          class: Paragraph,
          inlineToolbar: true
        },
        header: {
          class: Header,
          shortcut: 'CMD+SHIFT+H'
        },
        list: {
          class: List,
          inlineToolbar: true
        },
        embed: {
          class: Embed,
{'fraction_non_alphanumeric': 0.13701707097933513, 'fraction_numerical': 0.0, 'mean_word_length': 2.0674931129476586, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '2960559', 'n_tokens_mistral': 637, 'n_tokens_neox': 637, 'n_words': 159}