MCPcopy Create free account
hub / github.com/postlight/parser / paragraphize

Function paragraphize

src/utils/dom/paragraphize.js:14–38  ·  view source on GitHub ↗
(node, $, br = false)

Source from the content-addressed store, hash-verified

12// :param br: Whether or not the passed node is a br
13
14export 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}

Callers 2

brsToPsFunction · 0.85

Calls 1

$Function · 0.85

Tested by

no test coverage detected