<commit_before>import {Html} from 'slate'
import {getSpanType} from '../util/spanHelpers'

const BLOCK_TAGS = {
  p: {type: 'contentBlock', style: 'normal'}
}

const HEADER_TAGS = {
  h1: {type: 'contentBlock', style: 'h1'},
  h2: {type: 'contentBlock', style: 'h2'},
  h3: {type: 'contentBlock', style: 'h3'},
  h4: {type: 'contentBlock', style: 'h4'},
  h5: {type: 'contentBlock', style: 'h5'},
  h6: {type: 'contentBlock', style: 'h6'}
}

const MARK_TAGS = {
  b: 'strong',
  strong: 'strong',
  i: 'em',
  em: 'em',
  u: 'underline',
  s: 'strikethrough',
  code: 'code'
}

function resolveListItem(listNodeTagName) {
  let listStyle
  switch (listNodeTagName) {
    case 'ul':
      listStyle = 'bullet'
      break
    case 'ol':
      listStyle = 'number'
      break
    default:
      listStyle = 'bullet'
  }
  return listStyle
}

function createRules(blockEditor) {
  return [
    {
      deserialize(el, next) {
        const block = BLOCK_TAGS[el.tagName]
        if (!block) {
          return null
        }
        return {
          kind: 'block',
          type: block.type,
          data: {style: block.style},
          nodes: next(el.children)
        }
      }
    },
    {
      deserialize(el, next) {
        const header = HEADER_TAGS[el.tagName]
        if (!header) {
          return null
        }
        return {
          kind: 'block',
          type: header.type,
          data: {style: header.style},
          nodes: next(el.children)
        }
      }
    },
    {
      deserialize(el, next) {
        const mark = MARK_TAGS[el.tagName]
        if (!mark) {
          return null
        }
        return {
          kind: 'mark',
          type: mark,
          nodes: next(el.children)
        }
      }
    },
    {
      deserialize(el, next) {
        if (el.tagName === 'li') {
          const listItem = resolveListItem(el.parentNode.name)
          return {
            kind: 'block',
            type: 'contentBlock',
            data: {
              listItem: listItem
            },
            nodes: next(el.children)
          }
        }
        return null
      }
    },
    // {
    //   // Special case for code blocks, which need to grab the nested children.
    //   deserialize(el, next) {<commit_msg>[form-builder] Block editor: Set style on pasted listItem<commit_after>import {Html} from 'slate'
import {getSpanType} from '../util/spanHelpers'

const BLOCK_TAGS = {
  p: {type: 'contentBlock', style: 'normal'}
}

const HEADER_TAGS = {
  h1: {type: 'contentBlock', style: 'h1'},
  h2: {type: 'contentBlock', style: 'h2'},
  h3: {type: 'contentBlock', style: 'h3'},
  h4: {type: 'contentBlock', style: 'h4'},
  h5: {type: 'contentBlock', style: 'h5'},
  h6: {type: 'contentBlock', style: 'h6'}
}

const MARK_TAGS = {
  b: 'strong',
  strong: 'strong',
  i: 'em',
  em: 'em',
  u: 'underline',
  s: 'strikethrough',
  code: 'code'
}

function resolveListItem(listNodeTagName) {
  let listStyle
  switch (listNodeTagName) {
    case 'ul':
      listStyle = 'bullet'
      break
    case 'ol':
      listStyle = 'number'
      break
    default:
      listStyle = 'bullet'
  }
  return listStyle
}

function createRules(blockEditor) {
  return [
    {
      deserialize(el, next) {
        const block = BLOCK_TAGS[el.tagName]
        if (!block) {
          return null
        }
        return {
          kind: 'block',
          type: block.type,
          data: {style: block.style},
          nodes: next(el.children)
        }
      }
    },
    {
      deserialize(el, next) {
        const header = HEADER_TAGS[el.tagName]
        if (!header) {
          return null
        }
        return {
          kind: 'block',
          type: header.type,
          data: {style: header.style},
          nodes: next(el.children)
        }
      }
    },
    {
      deserialize(el, next) {
        const mark = MARK_TAGS[el.tagName]
        if (!mark) {
          return null
        }
        return {
          kind: 'mark',
          type: mark,
          nodes: next(el.children)
        }
      }
    },
    {
      deserialize(el, next) {
        if (el.tagName === 'li') {
          const listItem = resolveListItem(el.parentNode.name)
          return {
            kind: 'block',
            type: 'contentBlock',
            data: {
              listItem: listItem,
              style: 'normal'
            },
            nodes: next(el.children)
          }
        }
        return null
      }
    },
    // {
    //   // Special case for code blocks, which need to grab the nested children.
    //   deserialize(el, next) {
{'fraction_non_alphanumeric': 0.13724212812160694, 'fraction_numerical': 0.005211726384364821, 'mean_word_length': 1.7238320520402128, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1569127', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1499, 'n_words': 359}