function anonymizeTextWithin()

in src/component/selection/setDraftEditorSelection.js [50:76]


function anonymizeTextWithin(
  node: Node,
  getNodeLabels?: (n: Node) => Array<string>,
): Node {
  const labels = getNodeLabels !== undefined ? getNodeLabels(node) : [];

  if (node.nodeType === Node.TEXT_NODE) {
    const length = node.textContent.length;
    return getCorrectDocumentFromNode(node).createTextNode(
      '[text ' +
        length +
        (labels.length ? ' | ' + labels.join(', ') : '') +
        ']',
    );
  }

  const clone = node.cloneNode();
  if (clone.nodeType === 1 && labels.length) {
    ((clone: any): Element).setAttribute('data-labels', labels.join(', '));
  }
  const childNodes = node.childNodes;
  for (let ii = 0; ii < childNodes.length; ii++) {
    clone.appendChild(anonymizeTextWithin(childNodes[ii], getNodeLabels));
  }

  return clone;
}