src/processor.js
function processBlockContent (block, contentState, options) {
  const entityModifiers = options.entityModifiers || {}
  let text = block.getText()

  // Cribbed from sstur’s implementation in draft-js-export-html
  // https://github.com/sstur/draft-js-export-html/blob/master/src/stateToHTML.js#L222
  let charMetaList = block.getCharacterList()
  let entityPieces = getEntityRanges(text, charMetaList)

  // Map over the block’s entities
  const entities = entityPieces.map(([entityKey, stylePieces]) => {
    let entity = entityKey ? contentState.getEntity(entityKey) : null

    // Extract the inline element
    const inline = stylePieces.map(([text, style]) => {
      return [
        'inline',
        [
          style.toJS().map((s) => s),
          text,
        ],
      ]
    })

    // Nest within an entity if there’s data
    if (entity) {
      const type = entity.getType()
      const mutability = entity.getMutability()
      let data = entity.getData()

      // Run the entity data through a modifier if one exists
      const modifier = entityModifiers[type]
      if (modifier) {
        data = modifier(data)
      }

      return [
        [
          'entity',
          [
            type,
            entityKey,
            mutability,
            data,
            inline,
          ],
        ],
      ]
    } else {
      return inline
    }
  })
  // Flatten the result
  return entities.reduce((a, b) => {
    return a.concat(b)
  }, [])
}
function processBlockContent (block, contentState, options) {
  const entityModifiers = options.entityModifiers || {}
  let text = block.getText()

  // Cribbed from sstur’s implementation in draft-js-export-html
  // https://github.com/sstur/draft-js-export-html/blob/master/src/stateToHTML.js#L222
  let charMetaList = block.getCharacterList()
  let entityPieces = getEntityRanges(text, charMetaList)

  // Map over the block’s entities
  const entities = entityPieces.map(([entityKey, stylePieces]) => {
    let entity = entityKey ? contentState.getEntity(entityKey) : null

    // Extract the inline element
    const inline = stylePieces.map(([text, style]) => {
      return [
        'inline',
        [
          style.toJS().map((s) => s),
          text,
        ],
      ]
    })

    // Nest within an entity if there’s data
    if (entity) {
      const type = entity.getType()
      const mutability = entity.getMutability()
      let data = entity.getData()

      // Run the entity data through a modifier if one exists
      const modifier = entityModifiers[type]
      if (modifier) {
        data = modifier(data)
      }

      return [
        [
          'entity',
          [
            type,
            entityKey,
            mutability,
            data,
            inline,
          ],
        ],
      ]
    } else {
      return inline
    }
  })
  // Flatten the result
  return entities.reduce((a, b) => {
    return a.concat(b)
  }, [])
}
function processBlockContent ( block , contentState , options ) { const entityModifiers = options . entityModifiers || { } let text = block . getText ( ) // Cribbed from sstur’s implementation in draft-js-export-html // https://github.com/sstur/draft-js-export-html/blob/master/src/stateToHTML.js#L222 let charMetaList = block . getCharacterList ( ) let entityPieces = getEntityRanges ( text , charMetaList ) // Map over the block’s entities const entities = entityPieces . map ( ( [ entityKey , stylePieces ] ) => { let entity = entityKey ? contentState . getEntity ( entityKey ) : null // Extract the inline element const inline = stylePieces . map ( ( [ text , style ] ) => { return [ 'inline' , [ style . toJS ( ) . map ( ( s ) => s ) , text , ] , ] } ) // Nest within an entity if there’s data if ( entity ) { const type = entity . getType ( ) const mutability = entity . getMutability ( ) let data = entity . getData ( ) // Run the entity data through a modifier if one exists const modifier = entityModifiers [ type ] if ( modifier ) { data = modifier ( data ) } return [ [ 'entity' , [ type , entityKey , mutability , data , inline , ] , ] , ] } else { return inline } } ) // Flatten the result return entities . reduce ( ( a , b ) => { return a . concat ( b ) } , [ ] ) }
Process the content of a ContentBlock into appropriate abstract syntax tree
nodes based on their type
@param  {ContentBlock} block
@param  {ContentState} contentState The draft-js ContentState object
containing this block
@param  {Object} options.entityModifier Map of functions for modifying entity
data as it’s exported
@return {Array} List of block’s child nodes
Process the content of a ContentBlock into appropriate abstract syntax tree nodes based on their type