export default function patchBreakElements(doc) {
  // This is a workaround to handle HTML converted from DraftJS that
  // `<div><span><br /></span><div>` becomes `<p><br /><br /></p>`.
  // Block with single `<br />` inside should be collapsed into `<p />`.
  var selector = 'div > span:only-child > br:only-child';
  Array.from(doc.querySelectorAll(selector)).forEach(patchBreakElement);
}
function patchBreakElement(brElement) {
  var ownerDocument = brElement.ownerDocument,
    parentElement = brElement.parentElement;
  if (!ownerDocument || !parentElement) {
    return;
  }
  var div = brElement.parentElement && brElement.parentElement.parentElement;
  if (!div) {
    return;
  }
  var pp = ownerDocument.createElement('p');
  div.parentElement && div.parentElement.replaceChild(pp, div);
}