function getTextForSelection (doc, sel) {
  if (!sel || sel.isNull()) {
    return ''
  } else if (sel.isPropertySelection()) {
    const text = doc.get(sel.start.path)
    return text.substring(sel.start.offset, sel.end.offset)
  } else if (sel.isContainerSelection()) {
    const result = []
    const nodeIds = getNodeIdsCoveredByContainerSelection(doc, sel)
    const L = nodeIds.length
    for (let i = 0; i < L; i++) {
      const id = nodeIds[i]
      const node = doc.get(id)
      if (node.isText()) {
        let text = node.getText()
        if (i === L - 1) {
          text = text.slice(0, sel.end.offset)
        }
        if (i === 0) {
          text = text.slice(sel.start.offset)
        }
        result.push(text)
      }
    }
    return result.join('\n')
  }
}
For a given selection, get the corresponding text string

  @param {Document} doc
  @param {Selection} sel
  @return {string} text enclosed by the annotation