|
1 | | -import { hasChildren } from 'domhandler'; |
2 | 1 | /** |
3 | 2 | * Methods for modifying the DOM structure. |
4 | 3 | * |
5 | 4 | * @module cheerio/manipulation |
6 | 5 | */ |
7 | 6 |
|
8 | | -import { Node, NodeWithChildren, Element, Text } from 'domhandler'; |
| 7 | +import { Node, NodeWithChildren, Element, Text, hasChildren } from 'domhandler'; |
9 | 8 | import { default as parse, update as updateDOM } from '../parse'; |
10 | 9 | import { html as staticHtml, text as staticText } from '../static'; |
11 | 10 | import { domEach, cloneDom, isTag, isHtml, isCheerio } from '../utils'; |
12 | | -import { DomUtils } from 'htmlparser2'; |
| 11 | +import { removeElement } from 'domutils'; |
13 | 12 | import type { Cheerio } from '../cheerio'; |
14 | 13 | import type { BasicAcceptedElems, AcceptedElems } from '../types'; |
15 | 14 |
|
@@ -279,7 +278,7 @@ function _wrap( |
279 | 278 |
|
280 | 279 | const [wrapperDom] = this._makeDomArray(wrap, i < lastIdx); |
281 | 280 |
|
282 | | - if (!wrapperDom || !DomUtils.hasChildren(wrapperDom)) continue; |
| 281 | + if (!wrapperDom || !hasChildren(wrapperDom)) continue; |
283 | 282 |
|
284 | 283 | let elInsertLocation = wrapperDom; |
285 | 284 |
|
@@ -587,7 +586,7 @@ export function after<T extends Node>( |
587 | 586 |
|
588 | 587 | return domEach(this, (el, i) => { |
589 | 588 | const { parent } = el; |
590 | | - if (!DomUtils.hasChildren(el) || !parent) { |
| 589 | + if (!hasChildren(el) || !parent) { |
591 | 590 | return; |
592 | 591 | } |
593 | 592 |
|
@@ -701,7 +700,7 @@ export function before<T extends Node>( |
701 | 700 |
|
702 | 701 | return domEach(this, (el, i) => { |
703 | 702 | const { parent } = el; |
704 | | - if (!DomUtils.hasChildren(el) || !parent) { |
| 703 | + if (!hasChildren(el) || !parent) { |
705 | 704 | return; |
706 | 705 | } |
707 | 706 |
|
@@ -807,7 +806,7 @@ export function remove<T extends Node>( |
807 | 806 | const elems = selector ? this.filter(selector) : this; |
808 | 807 |
|
809 | 808 | domEach(elems, (el) => { |
810 | | - DomUtils.removeElement(el); |
| 809 | + removeElement(el); |
811 | 810 | el.prev = el.next = el.parent = null; |
812 | 811 | }); |
813 | 812 |
|
@@ -884,7 +883,7 @@ export function replaceWith<T extends Node>( |
884 | 883 | */ |
885 | 884 | export function empty<T extends Node>(this: Cheerio<T>): Cheerio<T> { |
886 | 885 | return domEach(this, (el) => { |
887 | | - if (!DomUtils.hasChildren(el)) return; |
| 886 | + if (!hasChildren(el)) return; |
888 | 887 | el.children.forEach((child) => { |
889 | 888 | child.next = child.prev = child.parent = null; |
890 | 889 | }); |
@@ -923,15 +922,15 @@ export function html<T extends Node>( |
923 | 922 | ): Cheerio<T> | string | null { |
924 | 923 | if (str === undefined) { |
925 | 924 | const el = this[0]; |
926 | | - if (!el || !DomUtils.hasChildren(el)) return null; |
| 925 | + if (!el || !hasChildren(el)) return null; |
927 | 926 | return staticHtml(el.children, this.options); |
928 | 927 | } |
929 | 928 |
|
930 | 929 | // Keep main options unchanged |
931 | 930 | const opts = { ...this.options, context: null as NodeWithChildren | null }; |
932 | 931 |
|
933 | 932 | return domEach(this, (el) => { |
934 | | - if (!DomUtils.hasChildren(el)) return; |
| 933 | + if (!hasChildren(el)) return; |
935 | 934 | el.children.forEach((child) => { |
936 | 935 | child.next = child.prev = child.parent = null; |
937 | 936 | }); |
@@ -1000,7 +999,7 @@ export function text<T extends Node>( |
1000 | 999 |
|
1001 | 1000 | // Append text node to each selected elements |
1002 | 1001 | return domEach(this, (el) => { |
1003 | | - if (!DomUtils.hasChildren(el)) return; |
| 1002 | + if (!hasChildren(el)) return; |
1004 | 1003 | el.children.forEach((child) => { |
1005 | 1004 | child.next = child.prev = child.parent = null; |
1006 | 1005 | }); |
|
0 commit comments