index.js
function createWrapperFunction(wrapperEl, range) {
    var startNode = range.startContainer
      , endNode = range.endContainer
      , startOffset = range.startOffset
      , endOffset = range.endOffset

  return function wrapNode(node) {
    var currentRange = document.createRange()
      , currentWrapper = wrapperEl.cloneNode()

    currentRange.selectNodeContents(node)

    if (node === startNode && startNode.nodeType === 3) {
      currentRange.setStart(node, startOffset)
      startNode = currentWrapper
      startOffset = 0
    }
    if (node === endNode && endNode.nodeType === 3) {
      currentRange.setEnd(node, endOffset)
      endNode = currentWrapper
      endOffset = 1
    }

    currentRange.surroundContents(currentWrapper)
    return currentWrapper
  }
}
function createWrapperFunction(wrapperEl, range) {
    var startNode = range.startContainer
      , endNode = range.endContainer
      , startOffset = range.startOffset
      , endOffset = range.endOffset

  return function wrapNode(node) {
    var currentRange = document.createRange()
      , currentWrapper = wrapperEl.cloneNode()

    currentRange.selectNodeContents(node)

    if (node === startNode && startNode.nodeType === 3) {
      currentRange.setStart(node, startOffset)
      startNode = currentWrapper
      startOffset = 0
    }
    if (node === endNode && endNode.nodeType === 3) {
      currentRange.setEnd(node, endOffset)
      endNode = currentWrapper
      endOffset = 1
    }

    currentRange.surroundContents(currentWrapper)
    return currentWrapper
  }
}
function createWrapperFunction ( wrapperEl , range ) { var startNode = range . startContainer , endNode = range . endContainer , startOffset = range . startOffset , endOffset = range . endOffset return function wrapNode ( node ) { var currentRange = document . createRange ( ) , currentWrapper = wrapperEl . cloneNode ( ) currentRange . selectNodeContents ( node ) if ( node === startNode && startNode . nodeType === 3 ) { currentRange . setStart ( node , startOffset ) startNode = currentWrapper startOffset = 0 } if ( node === endNode && endNode . nodeType === 3 ) { currentRange . setEnd ( node , endOffset ) endNode = currentWrapper endOffset = 1 } currentRange . surroundContents ( currentWrapper ) return currentWrapper } }
create a node wrapper function
create a node wrapper function