(node, $, br = false)
| 12 | // :param br: Whether or not the passed node is a br |
| 13 | |
| 14 | export default function paragraphize(node, $, br = false) { |
| 15 | const $node = $(node); |
| 16 | |
| 17 | if (br) { |
| 18 | let sibling = node.nextSibling; |
| 19 | const p = $('<p></p>'); |
| 20 | |
| 21 | // while the next node is text or not a block level element |
| 22 | // append it to a new p node |
| 23 | while ( |
| 24 | sibling && |
| 25 | !(sibling.tagName && BLOCK_LEVEL_TAGS_RE.test(sibling.tagName)) |
| 26 | ) { |
| 27 | const { nextSibling } = sibling; |
| 28 | $(sibling).appendTo(p); |
| 29 | sibling = nextSibling; |
| 30 | } |
| 31 | |
| 32 | $node.replaceWith(p); |
| 33 | $node.remove(); |
| 34 | return $; |
| 35 | } |
| 36 | |
| 37 | return $; |
| 38 | } |
no test coverage detected