@@ -8,64 +8,6 @@ var flattenOptions = require('./options').flatten;
88var select = require ( 'cheerio-select' ) . select ;
99var renderWithParse5 = require ( './parsers/parse5' ) . render ;
1010var renderWithHtmlparser2 = require ( './parsers/htmlparser2' ) . render ;
11- var parse = require ( './parse' ) ;
12-
13- /**
14- * Create a querying function, bound to a document created from the provided
15- * markup. Note that similar to web browser contexts, this operation may
16- * introduce `<html>`, `<head>`, and `<body>` elements; set `isDocument` to
17- * `false` to switch to fragment mode and disable this.
18- *
19- * See the README section titled "Loading" for additional usage information.
20- *
21- * @param {string } content - Markup to be loaded.
22- * @param {object } [options] - Options for the created instance.
23- * @param {boolean } [isDocument] - Allows parser to be switched to fragment mode.
24- * @returns {Cheerio } - The loaded document.
25- */
26- exports . load = function ( content , options , isDocument ) {
27- if ( content === null || content === undefined ) {
28- throw new Error ( 'cheerio.load() expects a string' ) ;
29- }
30-
31- var Cheerio = require ( './cheerio' ) ;
32-
33- options = Object . assign ( { } , defaultOptions , flattenOptions ( options ) ) ;
34-
35- if ( typeof isDocument === 'undefined' ) isDocument = true ;
36-
37- var root = parse ( content , options , isDocument ) ;
38-
39- function initialize ( selector , context , r , opts ) {
40- if ( ! ( this instanceof initialize ) ) {
41- return new initialize ( selector , context , r , opts ) ;
42- }
43- opts = Object . assign ( { } , options , opts ) ;
44- return Cheerio . call ( this , selector , context , r || root , opts ) ;
45- }
46-
47- // Ensure that selections created by the "loaded" `initialize` function are
48- // true Cheerio instances.
49- initialize . prototype = Object . create ( Cheerio . prototype ) ;
50- initialize . prototype . constructor = initialize ;
51-
52- // Mimic jQuery's prototype alias for plugin authors.
53- initialize . fn = initialize . prototype ;
54-
55- // Keep a reference to the top-level scope so we can chain methods that implicitly
56- // resolve selectors; e.g. $("<span>").(".bar"), which otherwise loses ._root
57- initialize . prototype . _originalRoot = root ;
58-
59- // Add in the static methods
60- Object . assign ( initialize , exports ) ;
61-
62- // Add in the root
63- initialize . _root = root ;
64- // store options
65- initialize . _options = options ;
66-
67- return initialize ;
68- } ;
6911
7012/**
7113 * Helper function to render a DOM.
0 commit comments