Initial import from local backup (Documents-Playground/pakerpale)
This commit is contained in:
652
node_modules/cheerio/History.md
generated
vendored
Normal file
652
node_modules/cheerio/History.md
generated
vendored
Normal file
@@ -0,0 +1,652 @@
|
||||
1.0.0-rc.3 / 2019-04-06
|
||||
==================
|
||||
|
||||
This release corrects a test expectation that was fixed by one of the project's
|
||||
dependencies.
|
||||
|
||||
1.0.0-rc.2 / 2017-07-02
|
||||
==================
|
||||
|
||||
This release changes Cheerio's default parser to [the Parse5 HTML
|
||||
parser](https://github.com/inikulin/parse5). Parse5 is an excellent project
|
||||
that rigorously conforms to the HTML standard. It does not support XML, so
|
||||
Cheerio continues to use [`htmlparser2`](https://github.com/fb55/htmlparser2/)
|
||||
when working with XML documents.
|
||||
|
||||
This switch addresses many long-standing bugs in Cheerio, but some users may
|
||||
experience slower behavior in performance-critical applications. In addition,
|
||||
`htmlparser2` is more forgiving of invalid markup which can be useful when
|
||||
input sourced from a third party and cannot be corrected. For these reasons,
|
||||
the `load` method also accepts a DOM structure as produced by the `htmlparser2`
|
||||
library. See the project's "readme" file for more details on this usage
|
||||
pattern.
|
||||
|
||||
### Migrating from version 0.x
|
||||
|
||||
`cheerio.load( html[, options ] )`` This method continues to produce
|
||||
jQuery-like functions, bound to the provided input text. In prior releases, the
|
||||
provided string was interpreted as a document fragment. This meant that in a
|
||||
statement such as:
|
||||
|
||||
var $ = cheerio.load('<p>Hello, <b>world</b>!</p>');
|
||||
|
||||
The resulting `$` function would operate on a tree whose root element was a
|
||||
paragraph tag.
|
||||
|
||||
With this release of Cheerio, strings provided to the `load` method are
|
||||
interpreted as documents. The same example will produce a `$` function that
|
||||
operates on a full HTML document, including an `<html>` document element with
|
||||
nested `<head>` and `<body>` tags. This mimics web browser behavior much more
|
||||
closely, but may require alterations to existing code. To work with fragments,
|
||||
first load an empty document, and then use the resulting `$` to parse the
|
||||
input:
|
||||
|
||||
var $ = cheerio.load('');
|
||||
var $fragment = $('<p>Hello, <b>world</b>!</p>');
|
||||
|
||||
* Update History.md (and include migration guide) (Mike Pennisi)
|
||||
* Rename `useHtmlParser2` option (Mike Pennisi)
|
||||
* Remove documentation for `xmlMode` option (Mike Pennisi)
|
||||
* Document advanced usage with htmlparser2 (Mike Pennisi)
|
||||
* Correct errors in Readme.md (Mike Pennisi)
|
||||
* Improve release process (Mike Pennisi)
|
||||
* 1.0.0-rc.1 (Mike Pennisi)
|
||||
* Update unit test (Mike Pennisi)
|
||||
* Normalize code style (Mike Pennisi)
|
||||
* Added support for nested wrapping. (Diane Looney)
|
||||
* Add nested wrapping test (Toni Helenius)
|
||||
* Added $.merge following the specification at https://api.jquery.com/jquery.merge/ Added test cases for $.merge (Diane Looney)
|
||||
* Clarify project scope in README file (Mike Pennisi)
|
||||
* .text() ignores script and style tags (#1018) (Haleem Assal)
|
||||
* Test suite housekeeping (#1016) (DianeLooney)
|
||||
* experiment with a job board (Matthew)
|
||||
* Change options format (inikulin)
|
||||
* Add test for #997 (inikulin)
|
||||
* Update .filter function docs. (Konstantin)
|
||||
* Standardise readme on ES6 variable declarations (Dekatron)
|
||||
* Use documents via $.load (inikulin)
|
||||
* Use parse5 as a default parser (closes #863) (inikulin)
|
||||
* Fix small typo in Readme (Darren Scerri)
|
||||
* Report test failures in CI (Mike Pennisi)
|
||||
* serializeArray should not ignore input elements without value attributes (Ricardo Gladwell)
|
||||
* Disallow variable shadowing (Mike Pennisi)
|
||||
* Update hasClass method (sufisaid)
|
||||
* Added MIT License fixes #902 (Prasanth Vaaheeswaran)
|
||||
* chore(package): update dependencies (greenkeeper[bot])
|
||||
* Use modular lodash package (#913) (Billy Janitsch)
|
||||
|
||||
0.22.0 / 2016-08-23
|
||||
==================
|
||||
|
||||
* Return undefined in .prop if given an invalid element or tag (#880)
|
||||
* Merge pull request #884 from cheeriojs/readme-cleanup
|
||||
* readme updates
|
||||
* Merge pull request #881 from piamancini/patch-1
|
||||
* Added backers and sponsors from OpenCollective
|
||||
* Use jQuery from the jquery module in benchmarks (#871)
|
||||
* Document, test, and extend static `$.text` method (#855)
|
||||
* Fix typo on calling _.extend (#861)
|
||||
* Update versions (#870)
|
||||
* Use individual lodash functions (#864)
|
||||
* Added `.serialize()` support. Fixes #69 (#827)
|
||||
* Update Readme.md (#857)
|
||||
* add extension for JSON require call
|
||||
* remove gittask badge
|
||||
* Merge pull request #672 from underdogio/dev/checkbox.radio.values.sqwished
|
||||
* Added default value for checkboxes/radios
|
||||
|
||||
0.20.0 / 2016-02-01
|
||||
==================
|
||||
|
||||
* Add coveralls badge, remove link to old report (Felix Böhm)
|
||||
* Update lodash dependeny to 4.1.0 (leif.hanack)
|
||||
* Fix PR #726 adding 'appendTo()' and 'prependTo()' (Delgan)
|
||||
* Added appendTo and prependTo with tests #641 (digihaven)
|
||||
* Fix #780 by changing options context in '.find()' (Felix Böhm)
|
||||
* Add an unit test checking the query of child (Delgan)
|
||||
* fix #667: attr({foo: null}) removes attribute foo, like attr('foo', null) (Ray Waldin)
|
||||
* Include reference to dedicated "Loading" section (Mike Pennisi)
|
||||
* Added load method to $ (alanev)
|
||||
* update css-select to 1.2.0 (Felix Böhm)
|
||||
* Fixing Grammatical Error (Dan Corman)
|
||||
* Test against node v0.12 --> v4.2 (Jason Kurian)
|
||||
* Correct output in example (Felix Böhm)
|
||||
* Fix npm files filter (Bogdan Chadkin)
|
||||
* Enable setting data on all elements in selection (Mike Pennisi)
|
||||
* Reinstate `$.fn.toArray` (Mike Pennisi)
|
||||
* update css-select to 1.1.0 (Thomas Shafer)
|
||||
* Complete implementation of `wrap` (Mike Pennisi)
|
||||
* Correct name of unit test (Mike Pennisi)
|
||||
* Correct grammar in test titles (Mike Pennisi)
|
||||
* Normalize whitespace (Mike Pennisi)
|
||||
* Insert omitted assertion (Mike Pennisi)
|
||||
* Update invocation of `children` (Mike Pennisi)
|
||||
* Begin implementation of `wrap` method (Dandlezzz)
|
||||
* Update Readme.md (Sven Slootweg)
|
||||
* fix document's mistake in Readme.md (exoticknight)
|
||||
* Add tests for setting text and html as non-strings (Ryc O'Chet)
|
||||
* Fix for passing non-string values to .html or .text (Ryc O'Chet)
|
||||
* use a selector to filter form elements (fb55)
|
||||
* fix README.md typo (Yutian Li)
|
||||
* README: fix spelling (Chris Rebert)
|
||||
* Added support for options without a `value` attribute. Fixes #633 (Todd Wolfson)
|
||||
* responding to pull request feedback - remove item() method and related tests (Ray Waldin)
|
||||
* add length property and item method to object returned by prop('style'), plus tests (Ray Waldin)
|
||||
* Added .prop method to readme (Artem Burtsev)
|
||||
* Added .prop method (Artem Burtsev)
|
||||
* Added Gitter badge (The Gitter Badger)
|
||||
|
||||
0.19.0 / 2015-03-21
|
||||
==================
|
||||
|
||||
* fixed allignment (fb55)
|
||||
* added test case for malformed json in data attributes (fb55)
|
||||
* fix: handle some extreme cases like `data-custom="{{templatevar}}"`. There is possibility error while parsing json . (Harish.K)
|
||||
* Add missing optional selector doc for {prev,next}{All,Until} (Jérémie Astori)
|
||||
* update to dom-serializer@0.1.0 (Felix Böhm)
|
||||
* Document `Cheerio#serialzeArray` (Mike Pennisi)
|
||||
* Fixed up `serializeArray()` and added multiple support (Todd Wolfson)
|
||||
* Implement serializeArray() (Jarno Leppänen)
|
||||
* recognize options in $.xml() (fb55)
|
||||
* lib/static.js: text(): rm errant space before ++ (Chris Rebert)
|
||||
* Do not expose internal `children` array (Mike Pennisi)
|
||||
* Change lodash dependencies to ^3.1.0 (Samy Pessé)
|
||||
* Update lodash@3.1.0 (Samy Pessé)
|
||||
* Updates Readme.md: .not(function (index, elem)) (Patrick Ward)
|
||||
* update to css-select@1.0.0 (fb55)
|
||||
* Allow failures in Node.js v0.11 (Mike Pennisi)
|
||||
* Added: Gittask badge (Matthew Mueller)
|
||||
* Isolate prototypes of functions created via `load` (Mike Pennisi)
|
||||
* Updates Readme.md: adds JS syntax highlighting (frankcash)
|
||||
* #608 -- Add support for insertBefore/insertAfter syntax. Supports target types of: $, [$], selector (both single and multiple results) (Ben Cochran)
|
||||
* Clone input nodes when inserting over a set (Mike Pennisi)
|
||||
* Move unit test files (Mike Pennisi)
|
||||
* remove unnecessarily tricky code (David Chambers)
|
||||
* pass options to $.html in toString (fb55)
|
||||
* add license info to package.json (Chris Rebert)
|
||||
* xyz@~0.5.0 (David Chambers)
|
||||
* Remove unofficial signature of `children` (Mike Pennisi)
|
||||
* Fix bug in `css` method (Mike Pennisi)
|
||||
* Correct bug in implementation of `Cheerio#val` (Mike Pennisi)
|
||||
|
||||
0.18.0 / 2014-11-06
|
||||
==================
|
||||
|
||||
* bump htmlparser2 dependency to ~3.8.1 (Chris Rebert)
|
||||
* Correct unit test titles (Mike Pennisi)
|
||||
* Correct behavior of `after` and `before` (Mike Pennisi)
|
||||
* implement jQuery's .has() (Chris Rebert)
|
||||
* Update repository url (haqii)
|
||||
* attr() should return undefined or name for booleans (Raoul Millais)
|
||||
* Update Readme.md (Ryan Breen)
|
||||
* Implement `Cheerio#not` (Mike Pennisi)
|
||||
* Clone nodes according to original parsing options (Mike Pennisi)
|
||||
* fix lint error (David Chambers)
|
||||
* Add explicit tests for DOM level 1 API (Mike Pennisi)
|
||||
* Expose DOM level 1 API for Node-like objects (Mike Pennisi)
|
||||
* Correct error in documentation (Mike Pennisi)
|
||||
* Return a fully-qualified Function from `$.load` (Mike Pennisi)
|
||||
* Update tests to avoid duck typing (Mike Pennisi)
|
||||
* Alter "loaded" functions to produce true instances (Mike Pennisi)
|
||||
* Organize tests for `cheerio.load` (Mike Pennisi)
|
||||
* Complete `$.prototype.find` (Mike Pennisi)
|
||||
* Use JSHint's `extends` option (Mike Pennisi)
|
||||
* Remove aliases for exported methods (Mike Pennisi)
|
||||
* Disallow unused variables (Mike Pennisi)
|
||||
* Remove unused internal variables (Mike Pennisi)
|
||||
* Remove unused variables from unit tests (Mike Pennisi)
|
||||
* Remove unused API method references (Mike Pennisi)
|
||||
* Move tests for `contains` method (Mike Pennisi)
|
||||
* xyz@0.4.0 (David Chambers)
|
||||
* Created a wiki for companies using cheerio in production (Matthew Mueller)
|
||||
* Implement `$.prototype.index` (Mike Pennisi)
|
||||
* Implement `$.prototype.addBack` (Mike Pennisi)
|
||||
* Added double quotes to radio attribute name to account for characters such as brackets (akant10)
|
||||
* Update History.md (Gabriel Falkenberg)
|
||||
* add 0.17.0 changelog (David Chambers)
|
||||
* exit prepublish script if tag not found (David Chambers)
|
||||
* alphabetize devDependencies (fb55)
|
||||
* ignore coverage dir (fb55)
|
||||
* submit coverage to coveralls (fb55)
|
||||
* replace jscoverage with istanbul (fb55)
|
||||
|
||||
0.17.0 / 2014-06-10
|
||||
==================
|
||||
|
||||
* Fix bug in internal `uniqueSplice` function (Mike Pennisi)
|
||||
* accept buffer argument to cheerio.load (David Chambers)
|
||||
* Respect options on the element level (Alex Indigo)
|
||||
* Change state definition to more readable (Artem Burtsev)
|
||||
* added test (0xBADC0FFEE)
|
||||
* add class only if doesn't exist (Artem Burtsev)
|
||||
* Made it less insane. (Alex Indigo)
|
||||
* Implement `Cheerio#add` (Mike Pennisi)
|
||||
* Use "loaded" instance of Cheerio in unit tests (Mike Pennisi)
|
||||
* Be more strict with object check. (Alex Indigo)
|
||||
* Added options argument to .html() static method. (Alex Indigo)
|
||||
* Fixed encoding mishaps. Adjusted tests. (Alex Indigo)
|
||||
* use dom-serializer module (fb55)
|
||||
* don't test on 0.8, don't ignore 0.11 (Felix Böhm)
|
||||
* parse: rm unused variables (coderaiser)
|
||||
* cheerio: rm unused variable (coderaiser)
|
||||
* Fixed test (Avi Kohn)
|
||||
* Added test (Avi Kohn)
|
||||
* Changed == to === (Avi Kohn)
|
||||
* Fixed a bug in removing type="hidden" attr (Avi Kohn)
|
||||
* sorted (Alexey Raspopov)
|
||||
* add `muted` attr to booleanAttributes (Alexey Raspopov)
|
||||
* fixed context of `this` in .html (Felix Böhm)
|
||||
* append new elements for each element in selection (fb55)
|
||||
|
||||
0.16.0 / 2014-05-08
|
||||
==================
|
||||
|
||||
* fix `make bench` (David Chambers)
|
||||
* makefile: add release-* targets (David Chambers)
|
||||
* alphabetize dependencies (David Chambers)
|
||||
* Rewrite `data` internals with caching behavior (Mike Pennisi)
|
||||
* Fence .val example as js (Kevin Sawicki)
|
||||
* Fixed typos. Deleted trailing whitespace from test/render.js (Nattaphoom Ch)
|
||||
* Fix manipulation APIs with removed elements (kpdecker)
|
||||
* Perform manual string parsing for hasClass (kpdecker)
|
||||
* Fix existing element removal (kpdecker)
|
||||
* update render tests (Felix Böhm)
|
||||
* fixed cheerio path (Felix Böhm)
|
||||
* use `entities.escape` for attribute values (Felix Böhm)
|
||||
* bump entities version (Felix Böhm)
|
||||
* remove lowerCaseTags option from readme (Felix Böhm)
|
||||
* added test case for .html in xmlMode (fb55)
|
||||
* render xml in `html()` when `xmlMode: true` (fb55)
|
||||
* use a map for booleanAttributes (fb55)
|
||||
* update singleTags, use utils.isTag (fb55)
|
||||
* update travis badge URL (Felix Böhm)
|
||||
* use typeof instead of _.isString and _.isNumber (fb55)
|
||||
* use Array.isArray instead of _.isArray (fb55)
|
||||
* replace _.isFunction with typeof (fb55)
|
||||
* removed unnecessary error message (fb55)
|
||||
* decode entities in htmlparser2 (fb55)
|
||||
* pass options object to CSSselect (fb55)
|
||||
|
||||
0.15.0 / 2014-04-08
|
||||
==================
|
||||
|
||||
* Update callbacks to pass element per docs (@kpdecker)
|
||||
* preserve options (@fb55)
|
||||
* Use SVG travis badge (@t3chnoboy)
|
||||
* only use static requires (@fb55)
|
||||
* Optimize manipulation methods (@kpdecker)
|
||||
* Optimize add and remove class cases (@kpdecker)
|
||||
* accept dom of DomHandler to cheerio.load (@nleush)
|
||||
* added parentsUntil method (@finspin)
|
||||
* Add performance optimization and bug fix `empty` method (@kpdecker)
|
||||
|
||||
0.14.0 / 2014-04-01
|
||||
==================
|
||||
|
||||
* call encodeXML and directly expose decodeHTML (@fb55)
|
||||
* use latest htmlparser2 and entities versions (@fb55)
|
||||
* Deprecate `$.fn.toArray` (@jugglinmike)
|
||||
* Implement `$.fn.get` (@jugglinmike)
|
||||
* .replaceWith now replaces all selected elements. (@xavi-)
|
||||
* Correct arguments for 'replaceWith' callback (@jugglinmike)
|
||||
* switch to lodash (@fb55)
|
||||
* update to entities@0.5.0 (@fb55)
|
||||
* Fix attr when $ collection contains text modules (@kpdecker)
|
||||
* Update to latest version of expect.js (@jugglinmike)
|
||||
* Remove nodes from their previous structures (@jugglinmike)
|
||||
* Update render.js (@stevenvachon)
|
||||
* CDATA test (@stevenvachon)
|
||||
* only ever one child index for cdata (@stevenvachon)
|
||||
* don't loop through cdata children array (@stevenvachon)
|
||||
* proper rendering of CDATA (@stevenvachon)
|
||||
* Add cheerio-only bench option (@kpdecker)
|
||||
* Avoid delete operations (@kpdecker)
|
||||
* Add independent html benchmark (@kpdecker)
|
||||
* Cache tag check in render (@kpdecker)
|
||||
* Simplify attribute rendering step (@kpdecker)
|
||||
* Add html rendering bench case (@kpdecker)
|
||||
* Remove unnecessary check from removeAttr (@kpdecker)
|
||||
* Remove unnecessary encoding step for attrs (@kpdecker)
|
||||
* Add test for removeAttr+attr on boolean attributes (@kpdecker)
|
||||
* Add single element benchmark case (@kpdecker)
|
||||
* Optimize filter with selector (@kpdecker)
|
||||
* Fix passing context as dom node (@alfred-nsh)
|
||||
* Fix bug in `nextUntil` (@jugglinmike)
|
||||
* Fix bug in `nextAll` (@jugglinmike)
|
||||
* Implement `selector` argument of `next` method (@jugglinmike)
|
||||
* Fix bug in `prevUntil` (@jugglinmike)
|
||||
* Implement `selector` argument of `prev` method (@jugglinmike)
|
||||
* Fix bug in `prevAll` (@jugglinmike)
|
||||
* Fix bug in `siblings` (@jugglinmike)
|
||||
* Avoid unnecessary indexOf from toggleClass (@kpdecker)
|
||||
* Use strict equality rather than falsy check in eq (@kpdecker)
|
||||
* Add benchmark coverage for all $ APIs (@kpdecker)
|
||||
* Optimize filter Cheerio intermediate creation (@kpdecker)
|
||||
* Optimize siblings cheerio instance creation (@kpdecker)
|
||||
* Optimize identity cases for first/last/eq (@kpdecker)
|
||||
* Use domEach for traversal (@kpdecker)
|
||||
* Inline children lookup in find (@kpdecker)
|
||||
* Use domEach in data accessor (@kpdecker)
|
||||
* Avoid cheerio creation in add/remove/toggleClass (@kpdecker)
|
||||
* Implement getAttr local helper (@kpdecker)
|
||||
|
||||
0.13.1 / 2014-01-07
|
||||
==================
|
||||
|
||||
* Fix select with context in Cheerio function (@jugglinmike)
|
||||
* Remove unecessary DOM maintenance logic (@jugglinmike)
|
||||
* Deprecate support for node 0.6
|
||||
|
||||
0.13.0 / 2013-12-30
|
||||
==================
|
||||
|
||||
* Remove "root" node (@jugglinmike)
|
||||
* Fix bug in `prevAll`, `prev`, `nextAll`, `next`, `prevUntil`, `nextUntil` (@jugglinmike)
|
||||
* Fix `replaceWith` method (@jugglinmike)
|
||||
* added nextUntil() and prevUntil() (@finspin)
|
||||
* Remove internal `connect` function (@jugglinmike)
|
||||
* Rename `Cheerio#make` to document private status (@jugginmike)
|
||||
* Remove extraneous call to `_.uniq` (@jugglinmike)
|
||||
* Use CSSselect library directly (@jugglinmike)
|
||||
* Run CI against Node v0.11 as an allowed failure (@jugginmike)
|
||||
* Correct bug in `Cheerio#parents` (@jugglinmike)
|
||||
* Implement `$.fn.end` (@jugginmike)
|
||||
* Ignore colons inside of url(.*) when parsing css (@Meekohi)
|
||||
* Introduce rudimentary benchmark suite (@jugglinmike)
|
||||
* Update HtmlParser2 version (@jugglinmike)
|
||||
* Correct inconsistency in `$.fn.map` (@jugglinmike)
|
||||
* fixed traversing tests (@finspin)
|
||||
* Simplify `make` method (@jugglinmike)
|
||||
* Avoid shadowing instance methods from arrays (@jugglinmike)
|
||||
|
||||
0.12.4 / 2013-11-12
|
||||
==================
|
||||
|
||||
* Coerce JSON values returned by `data` (@jugglinmike)
|
||||
* issue #284: when rendering HTML, use original data attributes (@Trott)
|
||||
* Introduce JSHint for automated code linting (@jugglinmike)
|
||||
* Prevent `find` from returning duplicate elements (@jugglinmike)
|
||||
* Implement function signature of `replaceWith` (@jugglinmike)
|
||||
* Implement function signature of `before` (@jugglinmike)
|
||||
* Implement function signature of `after` (@jugglinmike)
|
||||
* Implement function signature of `append`/`prepend` (@jugglinmike)
|
||||
* Extend iteration methods to accept nodes (@jugglinmike)
|
||||
* Improve `removeClass` (@jugglinmike)
|
||||
* Complete function signature of `addClass` (@jugglinmike)
|
||||
* Fix bug in `removeClass` (@jugglinmike)
|
||||
* Improve contributing.md (@jugglinmike)
|
||||
* Fix and document .css() (@jugglinmike)
|
||||
|
||||
0.12.3 / 2013-10-04
|
||||
===================
|
||||
|
||||
* Add .toggleClass() function (@cyberthom)
|
||||
* Add contributing guidelines (@jugglinmike)
|
||||
* Fix bug in `siblings` (@jugglinmike)
|
||||
* Correct the implementation `filter` and `is` (@jugglinmike)
|
||||
* add .data() function (@andi-neck)
|
||||
* add .css() (@yields)
|
||||
* Implements contents() (@jlep)
|
||||
|
||||
0.12.2 / 2013-09-04
|
||||
==================
|
||||
|
||||
* Correct implementation of `$.fn.text` (@jugglinmike)
|
||||
* Refactor Cheerio array creation (@jugglinmike)
|
||||
* Extend manipulation methods to accept Arrays (@jugglinmike)
|
||||
* support .attr(attributeName, function(index, attr)) (@xiaohwan)
|
||||
|
||||
0.12.1 / 2013-07-30
|
||||
==================
|
||||
|
||||
* Correct behavior of `Cheerio#parents` (@jugglinmike)
|
||||
* Double quotes inside attributes kills HTML (@khoomeister)
|
||||
* Making next({}) and prev({}) return empty object (@absentTelegraph)
|
||||
* Implement $.parseHTML (@jugglinmike)
|
||||
* Correct bug in jQuery.fn.closest (@jugglinmike)
|
||||
* Correct behavior of $.fn.val on 'option' elements (@jugglinmike)
|
||||
|
||||
0.12.0 / 2013-06-09
|
||||
===================
|
||||
|
||||
* Breaking Change: Changed context from parent to the actual passed one (@swissmanu)
|
||||
* Fixed: jquery checkbox val behavior (@jhubble)
|
||||
* Added: output xml with $.xml() (@Maciek416)
|
||||
* Bumped: htmlparser2 to 3.1.1
|
||||
* Fixed: bug in attr(key, val) on empty objects (@farhadi)
|
||||
* Added: prevAll, nextAll (@lessmind)
|
||||
* Fixed: Safety check in parents and closest (@zero21xxx)
|
||||
* Added: .is(sel) (@zero21xxx)
|
||||
|
||||
0.11.0 / 2013-04-22
|
||||
==================
|
||||
|
||||
* Added: .closest() (@jeremy-dentel)
|
||||
* Added: .parents() (@zero21xxx)
|
||||
* Added: .val() (@rschmukler & @leahciMic)
|
||||
* Added: Travis support for node 0.10.0 (@jeremy-dentel)
|
||||
* Fixed: .find() if no selector (@davidchambers)
|
||||
* Fixed: Propagate syntax errors caused by invalid selectors (@davidchambers)
|
||||
|
||||
0.10.8 / 2013-03-11
|
||||
==================
|
||||
|
||||
* Add slice method (SBoudrias)
|
||||
|
||||
0.10.7 / 2013-02-10
|
||||
==================
|
||||
|
||||
* Code & doc cleanup (davidchambers)
|
||||
* Fixed bug in filter (jugglinmike)
|
||||
|
||||
0.10.6 / 2013-01-29
|
||||
==================
|
||||
|
||||
* Added `$.contains(...)` (jugglinmike)
|
||||
* formatting cleanup (davidchambers)
|
||||
* Bug fix for `.children()` (jugglinmike & davidchambers)
|
||||
* Remove global `render` bug (wvl)
|
||||
|
||||
0.10.5 / 2012-12-18
|
||||
===================
|
||||
|
||||
* Fixed botched publish from 0.10.4 - changes should now be present
|
||||
|
||||
0.10.4 / 2012-12-16
|
||||
==================
|
||||
|
||||
* $.find should query descendants only (@jugglinmike)
|
||||
* Tighter underscore dependency
|
||||
|
||||
0.10.3 / 2012-11-18
|
||||
===================
|
||||
|
||||
* fixed outer html bug
|
||||
* Updated documentation for $(...).html() and $.html()
|
||||
|
||||
0.10.2 / 2012-11-17
|
||||
===================
|
||||
|
||||
* Added a toString() method (@bensheldon)
|
||||
* use `_.each` and `_.map` to simplify cheerio namesakes (@davidchambers)
|
||||
* Added filter() with tests and updated readme (@bensheldon & @davidchambers)
|
||||
* Added spaces between attributes rewritten by removeClass (@jos3000)
|
||||
* updated docs to remove reference to size method (@ironchefpython)
|
||||
* removed HTML tidy/pretty print from cheerio
|
||||
|
||||
0.10.1 / 2012-10-04
|
||||
===================
|
||||
|
||||
* Fixed regression, filtering with a context (#106)
|
||||
|
||||
0.10.0 / 2012-09-24
|
||||
===================
|
||||
|
||||
* Greatly simplified and reorganized the library, reducing the loc by 30%
|
||||
* Now supports mocha's test-coverage
|
||||
* Deprecated self-closing tags (HTML5 doesn't require them)
|
||||
* Fixed error thrown in removeClass(...) @robashton
|
||||
|
||||
0.9.2 / 2012-08-10
|
||||
==================
|
||||
|
||||
* added $(...).map(fn)
|
||||
* manipulation: refactor `makeCheerioArray`
|
||||
* make .removeClass() remove *all* occurrences (#64)
|
||||
|
||||
0.9.1 / 2012-08-03
|
||||
==================
|
||||
|
||||
* fixed bug causing options not to make it to the parser
|
||||
|
||||
0.9.0 / 2012-07-24
|
||||
==================
|
||||
|
||||
* Added node 8.x support
|
||||
* Removed node 4.x support
|
||||
* Add html(dom) support (@wvl)
|
||||
* fixed xss vulnerabilities on .attr(), .text(), & .html() (@benatkin, @FB55)
|
||||
* Rewrote tests into javascript, removing coffeescript dependency (@davidchambers)
|
||||
* Tons of cleanup (@davidchambers)
|
||||
|
||||
0.8.3 / 2012-06-12
|
||||
==================
|
||||
|
||||
* Fixed minor package regression (closes #60)
|
||||
|
||||
0.8.2 / 2012-06-11
|
||||
==================
|
||||
|
||||
* Now fails gracefully in cases that involve special chars, which is inline with jQuery (closes #59)
|
||||
* text() now decode special entities (closes #52)
|
||||
* updated travis.yml to test node 4.x
|
||||
|
||||
0.8.1 / 2012-06-02
|
||||
==================
|
||||
|
||||
* fixed regression where if you created an element, it would update the root
|
||||
* compatible with node 4.x (again)
|
||||
|
||||
0.8.0 / 2012-05-27
|
||||
==================
|
||||
|
||||
* Updated CSS parser to use FB55/CSSselect. Cheerio now supports most CSS3 psuedo selectors thanks to @FB55.
|
||||
* ignoreWhitespace now on by default again. See #55 for context.
|
||||
* Changed $(':root') to $.root(), cleaned up $.clone()
|
||||
* Support for .eq(i) thanks to @alexbardas
|
||||
* Removed support for node 0.4.x
|
||||
* Fixed memory leak where package.json was continually loaded
|
||||
* Tons more tests
|
||||
|
||||
0.7.0 / 2012-04-08
|
||||
==================
|
||||
|
||||
* Now testing with node v0.7.7
|
||||
* Added travis-ci integration
|
||||
* Replaced should.js with expect.js. Browser testing to come
|
||||
* Fixed spacing between attributes and their values
|
||||
* Added HTML tidy/pretty print
|
||||
* Exposed node-htmlparser2 parsing options
|
||||
* Revert .replaceWith(...) to be consistent with jQuery
|
||||
|
||||
0.6.2 / 2012-02-12
|
||||
==================
|
||||
|
||||
* Fixed .replaceWith(...) regression
|
||||
|
||||
0.6.1 / 2012-02-12
|
||||
==================
|
||||
|
||||
* Added .first(), .last(), and .clone() commands.
|
||||
* Option to parse using whitespace added to `.load`.
|
||||
* Many bug fixes to make cheerio more aligned with jQuery.
|
||||
* Added $(':root') to select the highest level element.
|
||||
|
||||
Many thanks to the contributors that made this release happen: @ironchefpython and @siddMahen
|
||||
|
||||
0.6.0 / 2012-02-07
|
||||
==================
|
||||
|
||||
* *Important:* `$(...).html()` now returns inner HTML, which is in line with the jQuery spec
|
||||
* `$.html()` returns the full HTML string. `$.html([cheerioObject])` will return the outer(selected element's tag) and inner HTML of that object
|
||||
* Fixed bug that prevented HTML strings with depth (eg. `append('<ul><li><li></ul>')`) from getting `parent`, `next`, `prev` attributes.
|
||||
* Halted [htmlparser2](https://github.com/FB55/node-htmlparser) at v2.2.2 until single attributes bug gets fixed.
|
||||
|
||||
0.5.1 / 2012-02-05
|
||||
==================
|
||||
|
||||
* Fixed minor regression: $(...).text(fn) would fail
|
||||
|
||||
0.5.1 / 2012-02-05
|
||||
==================
|
||||
|
||||
* Fixed regression: HTML pages with comments would fail
|
||||
|
||||
0.5.0 / 2012-02-04
|
||||
==================
|
||||
|
||||
* Transitioned from Coffeescript back to Javascript
|
||||
* Parser now ignores whitespace
|
||||
* Fixed issue with double slashes on self-enclosing tags
|
||||
* Added boolean attributes to html rendering
|
||||
|
||||
0.4.2 / 2012-01-16
|
||||
==================
|
||||
|
||||
* Multiple selectors support: $('.apple, .orange'). Thanks @siddMahen!
|
||||
* Update package.json to always use latest cheerio-soupselect
|
||||
* Fix memory leak in index.js
|
||||
|
||||
0.4.1 / 2011-12-19
|
||||
==================
|
||||
* Minor packaging changes to allow `make test` to work from npm installation
|
||||
|
||||
0.4.0 / 2011-12-19
|
||||
==================
|
||||
|
||||
* Rewrote all unit tests as cheerio transitioned from vows -> mocha
|
||||
* Internally, renderer.render -> render(...), parser.parse -> parse(...)
|
||||
* Append, prepend, html, before, after all work with only text (no tags)
|
||||
* Bugfix: Attributes can now be removed from script and style tags
|
||||
* Added yield as a single tag
|
||||
* Cheerio now compatible with node >=0.4.7
|
||||
|
||||
0.3.2 / 2011-12-1
|
||||
=================
|
||||
|
||||
* Fixed $(...).text(...) to work with "root" element
|
||||
|
||||
0.3.1 / 2011-11-25
|
||||
==================
|
||||
|
||||
* Now relying on cheerio-soupselect instead of node-soupselect
|
||||
* Removed all lingering htmlparser dependencies
|
||||
* parser now returns parent "root" element. Root now never needs to be updated when there is multiple roots. This fixes ongoing issues with before(...), after(...) and other manipulation functions
|
||||
* Added jQuery's $(...).replaceWith(...)
|
||||
|
||||
0.3.0 / 2011-11-19
|
||||
==================
|
||||
|
||||
* Now using htmlparser2 for parsing (2x speed increase, cleaner, actively developed)
|
||||
* Added benchmark directory for future speed tests
|
||||
* $('...').dom() was funky, so it was removed in favor of $('...').get(). $.dom() still works the same.
|
||||
* $.root now correctly static across all instances of $
|
||||
* Added a screencast
|
||||
|
||||
0.2.2 / 2011-11-9
|
||||
=================
|
||||
|
||||
* Traversing will select `<script>` and `<style>` tags (Closes Issue: #8)
|
||||
* .text(string) now working with empty elements (Closes Issue: #7)
|
||||
* Fixed before(...) & after(...) again if there is no parent (Closes Issue: #2)
|
||||
|
||||
0.2.1 / 2011-11-5
|
||||
=================
|
||||
|
||||
* Fixed before(...) & after(...) if there is no parent (Closes Issue: #2)
|
||||
* Comments now rendered correctly (Closes Issue: #5)
|
||||
|
||||
< 0.2.0 / 2011-10-31
|
||||
====================
|
||||
|
||||
* Initial release (untracked development)
|
||||
21
node_modules/cheerio/LICENSE
generated
vendored
Normal file
21
node_modules/cheerio/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Matt Mueller
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
1041
node_modules/cheerio/Readme.md
generated
vendored
Normal file
1041
node_modules/cheerio/Readme.md
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
node_modules/cheerio/index.js
generated
vendored
Normal file
11
node_modules/cheerio/index.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Export cheerio (with )
|
||||
*/
|
||||
|
||||
exports = module.exports = require('./lib/cheerio');
|
||||
|
||||
/*
|
||||
Export the version
|
||||
*/
|
||||
|
||||
exports.version = require('./package.json').version;
|
||||
492
node_modules/cheerio/lib/api/attributes.js
generated
vendored
Normal file
492
node_modules/cheerio/lib/api/attributes.js
generated
vendored
Normal file
@@ -0,0 +1,492 @@
|
||||
var $ = require('../static'),
|
||||
utils = require('../utils'),
|
||||
isTag = utils.isTag,
|
||||
domEach = utils.domEach,
|
||||
hasOwn = Object.prototype.hasOwnProperty,
|
||||
camelCase = utils.camelCase,
|
||||
cssCase = utils.cssCase,
|
||||
rspace = /\s+/,
|
||||
dataAttrPrefix = 'data-',
|
||||
_ = {
|
||||
forEach: require('lodash/forEach'),
|
||||
extend: require('lodash/assignIn'),
|
||||
some: require('lodash/some')
|
||||
},
|
||||
|
||||
// Lookup table for coercing string data-* attributes to their corresponding
|
||||
// JavaScript primitives
|
||||
primitives = {
|
||||
null: null,
|
||||
true: true,
|
||||
false: false
|
||||
},
|
||||
|
||||
// Attributes that are booleans
|
||||
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
|
||||
// Matches strings that look like JSON objects or arrays
|
||||
rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/;
|
||||
|
||||
|
||||
var getAttr = function(elem, name) {
|
||||
if (!elem || !isTag(elem)) return;
|
||||
|
||||
if (!elem.attribs) {
|
||||
elem.attribs = {};
|
||||
}
|
||||
|
||||
// Return the entire attribs object if no attribute specified
|
||||
if (!name) {
|
||||
return elem.attribs;
|
||||
}
|
||||
|
||||
if (hasOwn.call(elem.attribs, name)) {
|
||||
// Get the (decoded) attribute
|
||||
return rboolean.test(name) ? name : elem.attribs[name];
|
||||
}
|
||||
|
||||
// Mimic the DOM and return text content as value for `option's`
|
||||
if (elem.name === 'option' && name === 'value') {
|
||||
return $.text(elem.children);
|
||||
}
|
||||
|
||||
// Mimic DOM with default value for radios/checkboxes
|
||||
if (elem.name === 'input' &&
|
||||
(elem.attribs.type === 'radio' || elem.attribs.type === 'checkbox') &&
|
||||
name === 'value') {
|
||||
return 'on';
|
||||
}
|
||||
};
|
||||
|
||||
var setAttr = function(el, name, value) {
|
||||
|
||||
if (value === null) {
|
||||
removeAttribute(el, name);
|
||||
} else {
|
||||
el.attribs[name] = value+'';
|
||||
}
|
||||
};
|
||||
|
||||
exports.attr = function(name, value) {
|
||||
// Set the value (with attr map support)
|
||||
if (typeof name === 'object' || value !== undefined) {
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
setAttr(el, name, value.call(el, i, el.attribs[name]));
|
||||
});
|
||||
}
|
||||
return domEach(this, function(i, el) {
|
||||
if (!isTag(el)) return;
|
||||
|
||||
if (typeof name === 'object') {
|
||||
_.forEach(name, function(objValue, objName) {
|
||||
setAttr(el, objName, objValue);
|
||||
});
|
||||
} else {
|
||||
setAttr(el, name, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return getAttr(this[0], name);
|
||||
};
|
||||
|
||||
var getProp = function (el, name) {
|
||||
if (!el || !isTag(el)) return;
|
||||
|
||||
return hasOwn.call(el, name)
|
||||
? el[name]
|
||||
: rboolean.test(name)
|
||||
? getAttr(el, name) !== undefined
|
||||
: getAttr(el, name);
|
||||
};
|
||||
|
||||
var setProp = function (el, name, value) {
|
||||
el[name] = rboolean.test(name) ? !!value : value;
|
||||
};
|
||||
|
||||
exports.prop = function (name, value) {
|
||||
var i = 0,
|
||||
property;
|
||||
|
||||
if (typeof name === 'string' && value === undefined) {
|
||||
|
||||
switch (name) {
|
||||
case 'style':
|
||||
property = this.css();
|
||||
|
||||
_.forEach(property, function (v, p) {
|
||||
property[i++] = p;
|
||||
});
|
||||
|
||||
property.length = i;
|
||||
|
||||
break;
|
||||
case 'tagName':
|
||||
case 'nodeName':
|
||||
property = this[0].name.toUpperCase();
|
||||
break;
|
||||
default:
|
||||
property = getProp(this[0], name);
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
if (typeof name === 'object' || value !== undefined) {
|
||||
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(j, el) {
|
||||
setProp(el, name, value.call(el, j, getProp(el, name)));
|
||||
});
|
||||
}
|
||||
|
||||
return domEach(this, function(__, el) {
|
||||
if (!isTag(el)) return;
|
||||
|
||||
if (typeof name === 'object') {
|
||||
|
||||
_.forEach(name, function(val, key) {
|
||||
setProp(el, key, val);
|
||||
});
|
||||
|
||||
} else {
|
||||
setProp(el, name, value);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
var setData = function(el, name, value) {
|
||||
if (!el.data) {
|
||||
el.data = {};
|
||||
}
|
||||
|
||||
if (typeof name === 'object') return _.extend(el.data, name);
|
||||
if (typeof name === 'string' && value !== undefined) {
|
||||
el.data[name] = value;
|
||||
}
|
||||
};
|
||||
|
||||
// Read the specified attribute from the equivalent HTML5 `data-*` attribute,
|
||||
// and (if present) cache the value in the node's internal data store. If no
|
||||
// attribute name is specified, read *all* HTML5 `data-*` attributes in this
|
||||
// manner.
|
||||
var readData = function(el, name) {
|
||||
var readAll = arguments.length === 1;
|
||||
var domNames, domName, jsNames, jsName, value, idx, length;
|
||||
|
||||
if (readAll) {
|
||||
domNames = Object.keys(el.attribs).filter(function(attrName) {
|
||||
return attrName.slice(0, dataAttrPrefix.length) === dataAttrPrefix;
|
||||
});
|
||||
jsNames = domNames.map(function(_domName) {
|
||||
return camelCase(_domName.slice(dataAttrPrefix.length));
|
||||
});
|
||||
} else {
|
||||
domNames = [dataAttrPrefix + cssCase(name)];
|
||||
jsNames = [name];
|
||||
}
|
||||
|
||||
for (idx = 0, length = domNames.length; idx < length; ++idx) {
|
||||
domName = domNames[idx];
|
||||
jsName = jsNames[idx];
|
||||
if (hasOwn.call(el.attribs, domName)) {
|
||||
value = el.attribs[domName];
|
||||
|
||||
if (hasOwn.call(primitives, value)) {
|
||||
value = primitives[value];
|
||||
} else if (value === String(Number(value))) {
|
||||
value = Number(value);
|
||||
} else if (rbrace.test(value)) {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch(e){ }
|
||||
}
|
||||
|
||||
el.data[jsName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return readAll ? el.data : value;
|
||||
};
|
||||
|
||||
exports.data = function(name, value) {
|
||||
var elem = this[0];
|
||||
|
||||
if (!elem || !isTag(elem)) return;
|
||||
|
||||
if (!elem.data) {
|
||||
elem.data = {};
|
||||
}
|
||||
|
||||
// Return the entire data object if no data specified
|
||||
if (!name) {
|
||||
return readData(elem);
|
||||
}
|
||||
|
||||
// Set the value (with attr map support)
|
||||
if (typeof name === 'object' || value !== undefined) {
|
||||
domEach(this, function(i, el) {
|
||||
setData(el, name, value);
|
||||
});
|
||||
return this;
|
||||
} else if (hasOwn.call(elem.data, name)) {
|
||||
return elem.data[name];
|
||||
}
|
||||
|
||||
return readData(elem, name);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the value of an element
|
||||
*/
|
||||
|
||||
exports.val = function(value) {
|
||||
var querying = arguments.length === 0,
|
||||
element = this[0];
|
||||
|
||||
if(!element) return;
|
||||
|
||||
switch (element.name) {
|
||||
case 'textarea':
|
||||
return this.text(value);
|
||||
case 'input':
|
||||
switch (this.attr('type')) {
|
||||
case 'radio':
|
||||
if (querying) {
|
||||
return this.attr('value');
|
||||
} else {
|
||||
this.attr('value', value);
|
||||
return this;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return this.attr('value', value);
|
||||
}
|
||||
return;
|
||||
case 'select':
|
||||
var option = this.find('option:selected'),
|
||||
returnValue;
|
||||
if (option === undefined) return undefined;
|
||||
if (!querying) {
|
||||
if (!hasOwn.call(this.attr(), 'multiple') && typeof value == 'object') {
|
||||
return this;
|
||||
}
|
||||
if (typeof value != 'object') {
|
||||
value = [value];
|
||||
}
|
||||
this.find('option').removeAttr('selected');
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
this.find('option[value="' + value[i] + '"]').attr('selected', '');
|
||||
}
|
||||
return this;
|
||||
}
|
||||
returnValue = option.attr('value');
|
||||
if (hasOwn.call(this.attr(), 'multiple')) {
|
||||
returnValue = [];
|
||||
domEach(option, function(__, el) {
|
||||
returnValue.push(getAttr(el, 'value'));
|
||||
});
|
||||
}
|
||||
return returnValue;
|
||||
case 'option':
|
||||
if (!querying) {
|
||||
this.attr('value', value);
|
||||
return this;
|
||||
}
|
||||
return this.attr('value');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove an attribute
|
||||
*/
|
||||
|
||||
var removeAttribute = function(elem, name) {
|
||||
if (!elem.attribs || !hasOwn.call(elem.attribs, name))
|
||||
return;
|
||||
|
||||
delete elem.attribs[name];
|
||||
};
|
||||
|
||||
|
||||
exports.removeAttr = function(name) {
|
||||
domEach(this, function(i, elem) {
|
||||
removeAttribute(elem, name);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.hasClass = function(className) {
|
||||
return _.some(this, function(elem) {
|
||||
var attrs = elem.attribs,
|
||||
clazz = attrs && attrs['class'],
|
||||
idx = -1,
|
||||
end;
|
||||
|
||||
if (clazz && className.length) {
|
||||
while ((idx = clazz.indexOf(className, idx+1)) > -1) {
|
||||
end = idx + className.length;
|
||||
|
||||
if ((idx === 0 || rspace.test(clazz[idx-1]))
|
||||
&& (end === clazz.length || rspace.test(clazz[end]))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.addClass = function(value) {
|
||||
// Support functions
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
var className = el.attribs['class'] || '';
|
||||
exports.addClass.call([el], value.call(el, i, className));
|
||||
});
|
||||
}
|
||||
|
||||
// Return if no value or not a string or function
|
||||
if (!value || typeof value !== 'string') return this;
|
||||
|
||||
var classNames = value.split(rspace),
|
||||
numElements = this.length;
|
||||
|
||||
|
||||
for (var i = 0; i < numElements; i++) {
|
||||
// If selected element isn't a tag, move on
|
||||
if (!isTag(this[i])) continue;
|
||||
|
||||
// If we don't already have classes
|
||||
var className = getAttr(this[i], 'class'),
|
||||
numClasses,
|
||||
setClass;
|
||||
|
||||
if (!className) {
|
||||
setAttr(this[i], 'class', classNames.join(' ').trim());
|
||||
} else {
|
||||
setClass = ' ' + className + ' ';
|
||||
numClasses = classNames.length;
|
||||
|
||||
// Check if class already exists
|
||||
for (var j = 0; j < numClasses; j++) {
|
||||
var appendClass = classNames[j] + ' ';
|
||||
if (setClass.indexOf(' ' + appendClass) < 0)
|
||||
setClass += appendClass;
|
||||
}
|
||||
|
||||
setAttr(this[i], 'class', setClass.trim());
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
var splitClass = function(className) {
|
||||
return className ? className.trim().split(rspace) : [];
|
||||
};
|
||||
|
||||
exports.removeClass = function(value) {
|
||||
var classes,
|
||||
numClasses,
|
||||
removeAll;
|
||||
|
||||
// Handle if value is a function
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
exports.removeClass.call(
|
||||
[el], value.call(el, i, el.attribs['class'] || '')
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
classes = splitClass(value);
|
||||
numClasses = classes.length;
|
||||
removeAll = arguments.length === 0;
|
||||
|
||||
return domEach(this, function(i, el) {
|
||||
if (!isTag(el)) return;
|
||||
|
||||
if (removeAll) {
|
||||
// Short circuit the remove all case as this is the nice one
|
||||
el.attribs.class = '';
|
||||
} else {
|
||||
var elClasses = splitClass(el.attribs.class),
|
||||
index,
|
||||
changed;
|
||||
|
||||
for (var j = 0; j < numClasses; j++) {
|
||||
index = elClasses.indexOf(classes[j]);
|
||||
|
||||
if (index >= 0) {
|
||||
elClasses.splice(index, 1);
|
||||
changed = true;
|
||||
|
||||
// We have to do another pass to ensure that there are not duplicate
|
||||
// classes listed
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
el.attribs.class = elClasses.join(' ');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
exports.toggleClass = function(value, stateVal) {
|
||||
// Support functions
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
exports.toggleClass.call(
|
||||
[el],
|
||||
value.call(el, i, el.attribs['class'] || '', stateVal),
|
||||
stateVal
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Return if no value or not a string or function
|
||||
if (!value || typeof value !== 'string') return this;
|
||||
|
||||
var classNames = value.split(rspace),
|
||||
numClasses = classNames.length,
|
||||
state = typeof stateVal === 'boolean' ? stateVal ? 1 : -1 : 0,
|
||||
numElements = this.length,
|
||||
elementClasses,
|
||||
index;
|
||||
|
||||
for (var i = 0; i < numElements; i++) {
|
||||
// If selected element isn't a tag, move on
|
||||
if (!isTag(this[i])) continue;
|
||||
|
||||
elementClasses = splitClass(this[i].attribs.class);
|
||||
|
||||
// Check if class already exists
|
||||
for (var j = 0; j < numClasses; j++) {
|
||||
// Check if the class name is currently defined
|
||||
index = elementClasses.indexOf(classNames[j]);
|
||||
|
||||
// Add if stateValue === true or we are toggling and there is no value
|
||||
if (state >= 0 && index < 0) {
|
||||
elementClasses.push(classNames[j]);
|
||||
} else if (state <= 0 && index >= 0) {
|
||||
// Otherwise remove but only if the item exists
|
||||
elementClasses.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
this[i].attribs.class = elementClasses.join(' ');
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.is = function (selector) {
|
||||
if (selector) {
|
||||
return this.filter(selector).length > 0;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
121
node_modules/cheerio/lib/api/css.js
generated
vendored
Normal file
121
node_modules/cheerio/lib/api/css.js
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
var domEach = require('../utils').domEach,
|
||||
_ = {
|
||||
pick: require('lodash/pick'),
|
||||
};
|
||||
|
||||
var toString = Object.prototype.toString;
|
||||
|
||||
/**
|
||||
* Set / Get css.
|
||||
*
|
||||
* @param {String|Object} prop
|
||||
* @param {String} val
|
||||
* @return {self}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
exports.css = function(prop, val) {
|
||||
if (arguments.length === 2 ||
|
||||
// When `prop` is a "plain" object
|
||||
(toString.call(prop) === '[object Object]')) {
|
||||
return domEach(this, function(idx, el) {
|
||||
setCss(el, prop, val, idx);
|
||||
});
|
||||
} else {
|
||||
return getCss(this[0], prop);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set styles of all elements.
|
||||
*
|
||||
* @param {String|Object} prop
|
||||
* @param {String} val
|
||||
* @param {Number} idx - optional index within the selection
|
||||
* @return {self}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function setCss(el, prop, val, idx) {
|
||||
if ('string' == typeof prop) {
|
||||
var styles = getCss(el);
|
||||
if (typeof val === 'function') {
|
||||
val = val.call(el, idx, styles[prop]);
|
||||
}
|
||||
|
||||
if (val === '') {
|
||||
delete styles[prop];
|
||||
} else if (val != null) {
|
||||
styles[prop] = val;
|
||||
}
|
||||
|
||||
el.attribs.style = stringify(styles);
|
||||
} else if ('object' == typeof prop) {
|
||||
Object.keys(prop).forEach(function(k){
|
||||
setCss(el, k, prop[k]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get parsed styles of the first element.
|
||||
*
|
||||
* @param {String} prop
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function getCss(el, prop) {
|
||||
var styles = parse(el.attribs.style);
|
||||
if (typeof prop === 'string') {
|
||||
return styles[prop];
|
||||
} else if (Array.isArray(prop)) {
|
||||
return _.pick(styles, prop);
|
||||
} else {
|
||||
return styles;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify `obj` to styles.
|
||||
*
|
||||
* @param {Object} obj
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function stringify(obj) {
|
||||
return Object.keys(obj || {})
|
||||
.reduce(function(str, prop){
|
||||
return str += ''
|
||||
+ (str ? ' ' : '')
|
||||
+ prop
|
||||
+ ': '
|
||||
+ obj[prop]
|
||||
+ ';';
|
||||
}, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse `styles`.
|
||||
*
|
||||
* @param {String} styles
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function parse(styles) {
|
||||
styles = (styles || '').trim();
|
||||
|
||||
if (!styles) return {};
|
||||
|
||||
return styles
|
||||
.split(';')
|
||||
.reduce(function(obj, str){
|
||||
var n = str.indexOf(':');
|
||||
// skip if there is no :, or if it is the first/last character
|
||||
if (n < 1 || n === str.length-1) return obj;
|
||||
obj[str.slice(0,n).trim()] = str.slice(n+1).trim();
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
65
node_modules/cheerio/lib/api/forms.js
generated
vendored
Normal file
65
node_modules/cheerio/lib/api/forms.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
// https://github.com/jquery/jquery/blob/2.1.3/src/manipulation/var/rcheckableType.js
|
||||
// https://github.com/jquery/jquery/blob/2.1.3/src/serialize.js
|
||||
var submittableSelector = 'input,select,textarea,keygen',
|
||||
r20 = /%20/g,
|
||||
rCRLF = /\r?\n/g,
|
||||
_ = {
|
||||
map: require('lodash/map')
|
||||
};
|
||||
|
||||
exports.serialize = function() {
|
||||
// Convert form elements into name/value objects
|
||||
var arr = this.serializeArray();
|
||||
|
||||
// Serialize each element into a key/value string
|
||||
var retArr = _.map(arr, function(data) {
|
||||
return encodeURIComponent(data.name) + '=' + encodeURIComponent(data.value);
|
||||
});
|
||||
|
||||
// Return the resulting serialization
|
||||
return retArr.join('&').replace(r20, '+');
|
||||
};
|
||||
|
||||
exports.serializeArray = function() {
|
||||
// Resolve all form elements from either forms or collections of form elements
|
||||
var Cheerio = this.constructor;
|
||||
return this.map(function() {
|
||||
var elem = this;
|
||||
var $elem = Cheerio(elem);
|
||||
if (elem.name === 'form') {
|
||||
return $elem.find(submittableSelector).toArray();
|
||||
} else {
|
||||
return $elem.filter(submittableSelector).toArray();
|
||||
}
|
||||
}).filter(
|
||||
// Verify elements have a name (`attr.name`) and are not disabled (`:disabled`)
|
||||
'[name!=""]:not(:disabled)'
|
||||
// and cannot be clicked (`[type=submit]`) or are used in `x-www-form-urlencoded` (`[type=file]`)
|
||||
+ ':not(:submit, :button, :image, :reset, :file)'
|
||||
// and are either checked/don't have a checkable state
|
||||
+ ':matches([checked], :not(:checkbox, :radio))'
|
||||
// Convert each of the elements to its value(s)
|
||||
).map(function(i, elem) {
|
||||
var $elem = Cheerio(elem);
|
||||
var name = $elem.attr('name');
|
||||
var value = $elem.val();
|
||||
|
||||
// If there is no value set (e.g. `undefined`, `null`), then default value to empty
|
||||
if (value == null) {
|
||||
value = '';
|
||||
}
|
||||
|
||||
// If we have an array of values (e.g. `<select multiple>`), return an array of key/value pairs
|
||||
if (Array.isArray(value)) {
|
||||
return _.map(value, function(val) {
|
||||
// We trim replace any line endings (e.g. `\r` or `\r\n` with `\r\n`) to guarantee consistency across platforms
|
||||
// These can occur inside of `<textarea>'s`
|
||||
return {name: name, value: val.replace( rCRLF, '\r\n' )};
|
||||
});
|
||||
// Otherwise (e.g. `<input type="text">`, return only one key/value pair
|
||||
} else {
|
||||
return {name: name, value: value.replace( rCRLF, '\r\n' )};
|
||||
}
|
||||
// Convert our result to an array
|
||||
}).get();
|
||||
};
|
||||
442
node_modules/cheerio/lib/api/manipulation.js
generated
vendored
Normal file
442
node_modules/cheerio/lib/api/manipulation.js
generated
vendored
Normal file
@@ -0,0 +1,442 @@
|
||||
var parse = require('../parse'),
|
||||
$ = require('../static'),
|
||||
updateDOM = parse.update,
|
||||
evaluate = parse.evaluate,
|
||||
utils = require('../utils'),
|
||||
domEach = utils.domEach,
|
||||
cloneDom = utils.cloneDom,
|
||||
isHtml = utils.isHtml,
|
||||
slice = Array.prototype.slice,
|
||||
_ = {
|
||||
flatten: require('lodash/flatten'),
|
||||
bind: require('lodash/bind'),
|
||||
forEach: require('lodash/forEach')
|
||||
};
|
||||
|
||||
// Create an array of nodes, recursing into arrays and parsing strings if
|
||||
// necessary
|
||||
exports._makeDomArray = function makeDomArray(elem, clone) {
|
||||
if (elem == null) {
|
||||
return [];
|
||||
} else if (elem.cheerio) {
|
||||
return clone ? cloneDom(elem.get(), elem.options) : elem.get();
|
||||
} else if (Array.isArray(elem)) {
|
||||
return _.flatten(elem.map(function(el) {
|
||||
return this._makeDomArray(el, clone);
|
||||
}, this));
|
||||
} else if (typeof elem === 'string') {
|
||||
return evaluate(elem, this.options, false);
|
||||
} else {
|
||||
return clone ? cloneDom([elem]) : [elem];
|
||||
}
|
||||
};
|
||||
|
||||
var _insert = function(concatenator) {
|
||||
return function() {
|
||||
var elems = slice.call(arguments),
|
||||
lastIdx = this.length - 1;
|
||||
|
||||
return domEach(this, function(i, el) {
|
||||
var dom, domSrc;
|
||||
|
||||
if (typeof elems[0] === 'function') {
|
||||
domSrc = elems[0].call(el, i, $.html(el.children));
|
||||
} else {
|
||||
domSrc = elems;
|
||||
}
|
||||
|
||||
dom = this._makeDomArray(domSrc, i < lastIdx);
|
||||
concatenator(dom, el.children, el);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/*
|
||||
* Modify an array in-place, removing some number of elements and adding new
|
||||
* elements directly following them.
|
||||
*
|
||||
* @param {Array} array Target array to splice.
|
||||
* @param {Number} spliceIdx Index at which to begin changing the array.
|
||||
* @param {Number} spliceCount Number of elements to remove from the array.
|
||||
* @param {Array} newElems Elements to insert into the array.
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
var uniqueSplice = function(array, spliceIdx, spliceCount, newElems, parent) {
|
||||
var spliceArgs = [spliceIdx, spliceCount].concat(newElems),
|
||||
prev = array[spliceIdx - 1] || null,
|
||||
next = array[spliceIdx] || null;
|
||||
var idx, len, prevIdx, node, oldParent;
|
||||
|
||||
// Before splicing in new elements, ensure they do not already appear in the
|
||||
// current array.
|
||||
for (idx = 0, len = newElems.length; idx < len; ++idx) {
|
||||
node = newElems[idx];
|
||||
oldParent = node.parent || node.root;
|
||||
prevIdx = oldParent && oldParent.children.indexOf(newElems[idx]);
|
||||
|
||||
if (oldParent && prevIdx > -1) {
|
||||
oldParent.children.splice(prevIdx, 1);
|
||||
if (parent === oldParent && spliceIdx > prevIdx) {
|
||||
spliceArgs[0]--;
|
||||
}
|
||||
}
|
||||
|
||||
node.root = null;
|
||||
node.parent = parent;
|
||||
|
||||
if (node.prev) {
|
||||
node.prev.next = node.next || null;
|
||||
}
|
||||
|
||||
if (node.next) {
|
||||
node.next.prev = node.prev || null;
|
||||
}
|
||||
|
||||
node.prev = newElems[idx - 1] || prev;
|
||||
node.next = newElems[idx + 1] || next;
|
||||
}
|
||||
|
||||
if (prev) {
|
||||
prev.next = newElems[0];
|
||||
}
|
||||
if (next) {
|
||||
next.prev = newElems[newElems.length - 1];
|
||||
}
|
||||
return array.splice.apply(array, spliceArgs);
|
||||
};
|
||||
|
||||
exports.appendTo = function(target) {
|
||||
if (!target.cheerio) {
|
||||
target = this.constructor.call(this.constructor, target, null, this._originalRoot);
|
||||
}
|
||||
|
||||
target.append(this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.prependTo = function(target) {
|
||||
if (!target.cheerio) {
|
||||
target = this.constructor.call(this.constructor, target, null, this._originalRoot);
|
||||
}
|
||||
|
||||
target.prepend(this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.append = _insert(function(dom, children, parent) {
|
||||
uniqueSplice(children, children.length, 0, dom, parent);
|
||||
});
|
||||
|
||||
exports.prepend = _insert(function(dom, children, parent) {
|
||||
uniqueSplice(children, 0, 0, dom, parent);
|
||||
});
|
||||
|
||||
exports.wrap = function(wrapper) {
|
||||
var wrapperFn = typeof wrapper === 'function' && wrapper,
|
||||
lastIdx = this.length - 1;
|
||||
|
||||
_.forEach(this, _.bind(function(el, i) {
|
||||
var parent = el.parent || el.root,
|
||||
siblings = parent.children,
|
||||
wrapperDom, elInsertLocation, j, index;
|
||||
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wrapperFn) {
|
||||
wrapper = wrapperFn.call(el, i);
|
||||
}
|
||||
|
||||
if (typeof wrapper === 'string' && !isHtml(wrapper)) {
|
||||
wrapper = this.parents().last().find(wrapper).clone();
|
||||
}
|
||||
|
||||
wrapperDom = this._makeDomArray(wrapper, i < lastIdx).slice(0, 1);
|
||||
elInsertLocation = wrapperDom[0];
|
||||
// Find the deepest child. Only consider the first tag child of each node
|
||||
// (ignore text); stop if no children are found.
|
||||
j = 0;
|
||||
|
||||
while (elInsertLocation && elInsertLocation.children) {
|
||||
if (j >= elInsertLocation.children.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (elInsertLocation.children[j].type === 'tag') {
|
||||
elInsertLocation = elInsertLocation.children[j];
|
||||
j=0;
|
||||
} else {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
index = siblings.indexOf(el);
|
||||
|
||||
updateDOM([el], elInsertLocation);
|
||||
// The previous operation removed the current element from the `siblings`
|
||||
// array, so the `dom` array can be inserted without removing any
|
||||
// additional elements.
|
||||
uniqueSplice(siblings, index, 0, wrapperDom, parent);
|
||||
}, this));
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.after = function() {
|
||||
var elems = slice.call(arguments),
|
||||
lastIdx = this.length - 1;
|
||||
|
||||
domEach(this, function(i, el) {
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
index = siblings.indexOf(el),
|
||||
domSrc, dom;
|
||||
|
||||
// If not found, move on
|
||||
if (index < 0) return;
|
||||
|
||||
if (typeof elems[0] === 'function') {
|
||||
domSrc = elems[0].call(el, i, $.html(el.children));
|
||||
} else {
|
||||
domSrc = elems;
|
||||
}
|
||||
dom = this._makeDomArray(domSrc, i < lastIdx);
|
||||
|
||||
// Add element after `this` element
|
||||
uniqueSplice(siblings, index + 1, 0, dom, parent);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.insertAfter = function(target) {
|
||||
var clones = [],
|
||||
self = this;
|
||||
if (typeof target === 'string') {
|
||||
target = this.constructor.call(this.constructor, target, null, this._originalRoot);
|
||||
}
|
||||
target = this._makeDomArray(target);
|
||||
self.remove();
|
||||
domEach(target, function(i, el) {
|
||||
var clonedSelf = self._makeDomArray(self.clone());
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
index = siblings.indexOf(el);
|
||||
|
||||
// If not found, move on
|
||||
if (index < 0) return;
|
||||
|
||||
// Add cloned `this` element(s) after target element
|
||||
uniqueSplice(siblings, index + 1, 0, clonedSelf, parent);
|
||||
clones.push(clonedSelf);
|
||||
});
|
||||
return this.constructor.call(this.constructor, this._makeDomArray(clones));
|
||||
};
|
||||
|
||||
exports.before = function() {
|
||||
var elems = slice.call(arguments),
|
||||
lastIdx = this.length - 1;
|
||||
|
||||
domEach(this, function(i, el) {
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
index = siblings.indexOf(el),
|
||||
domSrc, dom;
|
||||
|
||||
// If not found, move on
|
||||
if (index < 0) return;
|
||||
|
||||
if (typeof elems[0] === 'function') {
|
||||
domSrc = elems[0].call(el, i, $.html(el.children));
|
||||
} else {
|
||||
domSrc = elems;
|
||||
}
|
||||
|
||||
dom = this._makeDomArray(domSrc, i < lastIdx);
|
||||
|
||||
// Add element before `el` element
|
||||
uniqueSplice(siblings, index, 0, dom, parent);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.insertBefore = function(target) {
|
||||
var clones = [],
|
||||
self = this;
|
||||
if (typeof target === 'string') {
|
||||
target = this.constructor.call(this.constructor, target, null, this._originalRoot);
|
||||
}
|
||||
target = this._makeDomArray(target);
|
||||
self.remove();
|
||||
domEach(target, function(i, el) {
|
||||
var clonedSelf = self._makeDomArray(self.clone());
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
index = siblings.indexOf(el);
|
||||
|
||||
// If not found, move on
|
||||
if (index < 0) return;
|
||||
|
||||
// Add cloned `this` element(s) after target element
|
||||
uniqueSplice(siblings, index, 0, clonedSelf, parent);
|
||||
clones.push(clonedSelf);
|
||||
});
|
||||
return this.constructor.call(this.constructor, this._makeDomArray(clones));
|
||||
};
|
||||
|
||||
/*
|
||||
remove([selector])
|
||||
*/
|
||||
exports.remove = function(selector) {
|
||||
var elems = this;
|
||||
|
||||
// Filter if we have selector
|
||||
if (selector)
|
||||
elems = elems.filter(selector);
|
||||
|
||||
domEach(elems, function(i, el) {
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
index = siblings.indexOf(el);
|
||||
|
||||
if (index < 0) return;
|
||||
|
||||
siblings.splice(index, 1);
|
||||
if (el.prev) {
|
||||
el.prev.next = el.next;
|
||||
}
|
||||
if (el.next) {
|
||||
el.next.prev = el.prev;
|
||||
}
|
||||
el.prev = el.next = el.parent = el.root = null;
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.replaceWith = function(content) {
|
||||
var self = this;
|
||||
|
||||
domEach(this, function(i, el) {
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
dom = self._makeDomArray(typeof content === 'function' ? content.call(el, i, el) : content),
|
||||
index;
|
||||
|
||||
// In the case that `dom` contains nodes that already exist in other
|
||||
// structures, ensure those nodes are properly removed.
|
||||
updateDOM(dom, null);
|
||||
|
||||
index = siblings.indexOf(el);
|
||||
|
||||
// Completely remove old element
|
||||
uniqueSplice(siblings, index, 1, dom, parent);
|
||||
el.parent = el.prev = el.next = el.root = null;
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.empty = function() {
|
||||
domEach(this, function(i, el) {
|
||||
_.forEach(el.children, function(child) {
|
||||
child.next = child.prev = child.parent = null;
|
||||
});
|
||||
|
||||
el.children.length = 0;
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set/Get the HTML
|
||||
*/
|
||||
exports.html = function(str) {
|
||||
if (str === undefined) {
|
||||
if (!this[0] || !this[0].children) return null;
|
||||
return $.html(this[0].children, this.options);
|
||||
}
|
||||
|
||||
var opts = this.options;
|
||||
|
||||
domEach(this, function(i, el) {
|
||||
_.forEach(el.children, function(child) {
|
||||
child.next = child.prev = child.parent = null;
|
||||
});
|
||||
|
||||
var content = str.cheerio ? str.clone().get() : evaluate('' + str, opts, false);
|
||||
|
||||
updateDOM(content, el);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.toString = function() {
|
||||
return $.html(this, this.options);
|
||||
};
|
||||
|
||||
exports.text = function(str) {
|
||||
// If `str` is undefined, act as a "getter"
|
||||
if (str === undefined) {
|
||||
return $.text(this);
|
||||
} else if (typeof str === 'function') {
|
||||
// Function support
|
||||
return domEach(this, function(i, el) {
|
||||
var $el = [el];
|
||||
return exports.text.call($el, str.call(el, i, $.text($el)));
|
||||
});
|
||||
}
|
||||
|
||||
// Append text node to each selected elements
|
||||
domEach(this, function(i, el) {
|
||||
_.forEach(el.children, function(child) {
|
||||
child.next = child.prev = child.parent = null;
|
||||
});
|
||||
|
||||
var elem = {
|
||||
data: '' + str,
|
||||
type: 'text',
|
||||
parent: el,
|
||||
prev: null,
|
||||
next: null,
|
||||
children: []
|
||||
};
|
||||
|
||||
updateDOM(elem, el);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.clone = function() {
|
||||
return this._make(cloneDom(this.get(), this.options));
|
||||
};
|
||||
429
node_modules/cheerio/lib/api/traversing.js
generated
vendored
Normal file
429
node_modules/cheerio/lib/api/traversing.js
generated
vendored
Normal file
@@ -0,0 +1,429 @@
|
||||
var select = require('css-select'),
|
||||
utils = require('../utils'),
|
||||
domEach = utils.domEach,
|
||||
uniqueSort = require('htmlparser2').DomUtils.uniqueSort,
|
||||
isTag = utils.isTag,
|
||||
_ = {
|
||||
bind: require('lodash/bind'),
|
||||
forEach: require('lodash/forEach'),
|
||||
reject: require('lodash/reject'),
|
||||
filter: require('lodash/filter'),
|
||||
reduce: require('lodash/reduce')
|
||||
};
|
||||
|
||||
exports.find = function(selectorOrHaystack) {
|
||||
var elems = _.reduce(this, function(memo, elem) {
|
||||
return memo.concat(_.filter(elem.children, isTag));
|
||||
}, []);
|
||||
var contains = this.constructor.contains;
|
||||
var haystack;
|
||||
|
||||
if (selectorOrHaystack && typeof selectorOrHaystack !== 'string') {
|
||||
if (selectorOrHaystack.cheerio) {
|
||||
haystack = selectorOrHaystack.get();
|
||||
} else {
|
||||
haystack = [selectorOrHaystack];
|
||||
}
|
||||
|
||||
return this._make(haystack.filter(function(elem) {
|
||||
var idx, len;
|
||||
for (idx = 0, len = this.length; idx < len; ++idx) {
|
||||
if (contains(this[idx], elem)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}, this));
|
||||
}
|
||||
|
||||
var options = {__proto__: this.options, context: this.toArray()};
|
||||
|
||||
return this._make(select(selectorOrHaystack, elems, options));
|
||||
};
|
||||
|
||||
// Get the parent of each element in the current set of matched elements,
|
||||
// optionally filtered by a selector.
|
||||
exports.parent = function(selector) {
|
||||
var set = [];
|
||||
|
||||
domEach(this, function(idx, elem) {
|
||||
var parentElem = elem.parent;
|
||||
if (parentElem && set.indexOf(parentElem) < 0) {
|
||||
set.push(parentElem);
|
||||
}
|
||||
});
|
||||
|
||||
if (arguments.length) {
|
||||
set = exports.filter.call(set, selector, this);
|
||||
}
|
||||
|
||||
return this._make(set);
|
||||
};
|
||||
|
||||
exports.parents = function(selector) {
|
||||
var parentNodes = [];
|
||||
|
||||
// When multiple DOM elements are in the original set, the resulting set will
|
||||
// be in *reverse* order of the original elements as well, with duplicates
|
||||
// removed.
|
||||
this.get().reverse().forEach(function(elem) {
|
||||
traverseParents(this, elem.parent, selector, Infinity)
|
||||
.forEach(function(node) {
|
||||
if (parentNodes.indexOf(node) === -1) {
|
||||
parentNodes.push(node);
|
||||
}
|
||||
}
|
||||
);
|
||||
}, this);
|
||||
|
||||
return this._make(parentNodes);
|
||||
};
|
||||
|
||||
exports.parentsUntil = function(selector, filter) {
|
||||
var parentNodes = [], untilNode, untilNodes;
|
||||
|
||||
if (typeof selector === 'string') {
|
||||
untilNode = select(selector, this.parents().toArray(), this.options)[0];
|
||||
} else if (selector && selector.cheerio) {
|
||||
untilNodes = selector.toArray();
|
||||
} else if (selector) {
|
||||
untilNode = selector;
|
||||
}
|
||||
|
||||
// When multiple DOM elements are in the original set, the resulting set will
|
||||
// be in *reverse* order of the original elements as well, with duplicates
|
||||
// removed.
|
||||
|
||||
this.toArray().reverse().forEach(function(elem) {
|
||||
while ((elem = elem.parent)) {
|
||||
if ((untilNode && elem !== untilNode) ||
|
||||
(untilNodes && untilNodes.indexOf(elem) === -1) ||
|
||||
(!untilNode && !untilNodes)) {
|
||||
if (isTag(elem) && parentNodes.indexOf(elem) === -1) { parentNodes.push(elem); }
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
return this._make(filter ? select(filter, parentNodes, this.options) : parentNodes);
|
||||
};
|
||||
|
||||
// For each element in the set, get the first element that matches the selector
|
||||
// by testing the element itself and traversing up through its ancestors in the
|
||||
// DOM tree.
|
||||
exports.closest = function(selector) {
|
||||
var set = [];
|
||||
|
||||
if (!selector) {
|
||||
return this._make(set);
|
||||
}
|
||||
|
||||
domEach(this, function(idx, elem) {
|
||||
var closestElem = traverseParents(this, elem, selector, 1)[0];
|
||||
|
||||
// Do not add duplicate elements to the set
|
||||
if (closestElem && set.indexOf(closestElem) < 0) {
|
||||
set.push(closestElem);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
return this._make(set);
|
||||
};
|
||||
|
||||
exports.next = function(selector) {
|
||||
if (!this[0]) { return this; }
|
||||
var elems = [];
|
||||
|
||||
_.forEach(this, function(elem) {
|
||||
while ((elem = elem.next)) {
|
||||
if (isTag(elem)) {
|
||||
elems.push(elem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return selector ?
|
||||
exports.filter.call(elems, selector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
exports.nextAll = function(selector) {
|
||||
if (!this[0]) { return this; }
|
||||
var elems = [];
|
||||
|
||||
_.forEach(this, function(elem) {
|
||||
while ((elem = elem.next)) {
|
||||
if (isTag(elem) && elems.indexOf(elem) === -1) {
|
||||
elems.push(elem);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return selector ?
|
||||
exports.filter.call(elems, selector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
exports.nextUntil = function(selector, filterSelector) {
|
||||
if (!this[0]) { return this; }
|
||||
var elems = [], untilNode, untilNodes;
|
||||
|
||||
if (typeof selector === 'string') {
|
||||
untilNode = select(selector, this.nextAll().get(), this.options)[0];
|
||||
} else if (selector && selector.cheerio) {
|
||||
untilNodes = selector.get();
|
||||
} else if (selector) {
|
||||
untilNode = selector;
|
||||
}
|
||||
|
||||
_.forEach(this, function(elem) {
|
||||
while ((elem = elem.next)) {
|
||||
if ((untilNode && elem !== untilNode) ||
|
||||
(untilNodes && untilNodes.indexOf(elem) === -1) ||
|
||||
(!untilNode && !untilNodes)) {
|
||||
if (isTag(elem) && elems.indexOf(elem) === -1) {
|
||||
elems.push(elem);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return filterSelector ?
|
||||
exports.filter.call(elems, filterSelector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
exports.prev = function(selector) {
|
||||
if (!this[0]) { return this; }
|
||||
var elems = [];
|
||||
|
||||
_.forEach(this, function(elem) {
|
||||
while ((elem = elem.prev)) {
|
||||
if (isTag(elem)) {
|
||||
elems.push(elem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return selector ?
|
||||
exports.filter.call(elems, selector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
exports.prevAll = function(selector) {
|
||||
if (!this[0]) { return this; }
|
||||
var elems = [];
|
||||
|
||||
_.forEach(this, function(elem) {
|
||||
while ((elem = elem.prev)) {
|
||||
if (isTag(elem) && elems.indexOf(elem) === -1) {
|
||||
elems.push(elem);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return selector ?
|
||||
exports.filter.call(elems, selector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
exports.prevUntil = function(selector, filterSelector) {
|
||||
if (!this[0]) { return this; }
|
||||
var elems = [], untilNode, untilNodes;
|
||||
|
||||
if (typeof selector === 'string') {
|
||||
untilNode = select(selector, this.prevAll().get(), this.options)[0];
|
||||
} else if (selector && selector.cheerio) {
|
||||
untilNodes = selector.get();
|
||||
} else if (selector) {
|
||||
untilNode = selector;
|
||||
}
|
||||
|
||||
_.forEach(this, function(elem) {
|
||||
while ((elem = elem.prev)) {
|
||||
if ((untilNode && elem !== untilNode) ||
|
||||
(untilNodes && untilNodes.indexOf(elem) === -1) ||
|
||||
(!untilNode && !untilNodes)) {
|
||||
if (isTag(elem) && elems.indexOf(elem) === -1) {
|
||||
elems.push(elem);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return filterSelector ?
|
||||
exports.filter.call(elems, filterSelector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
exports.siblings = function(selector) {
|
||||
var parent = this.parent();
|
||||
|
||||
var elems = _.filter(
|
||||
parent ? parent.children() : this.siblingsAndMe(),
|
||||
_.bind(function(elem) { return isTag(elem) && !this.is(elem); }, this)
|
||||
);
|
||||
|
||||
if (selector !== undefined) {
|
||||
return exports.filter.call(elems, selector, this);
|
||||
} else {
|
||||
return this._make(elems);
|
||||
}
|
||||
};
|
||||
|
||||
exports.children = function(selector) {
|
||||
|
||||
var elems = _.reduce(this, function(memo, elem) {
|
||||
return memo.concat(_.filter(elem.children, isTag));
|
||||
}, []);
|
||||
|
||||
if (selector === undefined) return this._make(elems);
|
||||
|
||||
return exports.filter.call(elems, selector, this);
|
||||
};
|
||||
|
||||
exports.contents = function() {
|
||||
return this._make(_.reduce(this, function(all, elem) {
|
||||
all.push.apply(all, elem.children);
|
||||
return all;
|
||||
}, []));
|
||||
};
|
||||
|
||||
exports.each = function(fn) {
|
||||
var i = 0, len = this.length;
|
||||
while (i < len && fn.call(this[i], i, this[i]) !== false) ++i;
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.map = function(fn) {
|
||||
return this._make(_.reduce(this, function(memo, el, i) {
|
||||
var val = fn.call(el, i, el);
|
||||
return val == null ? memo : memo.concat(val);
|
||||
}, []));
|
||||
};
|
||||
|
||||
var makeFilterMethod = function(filterFn) {
|
||||
return function(match, container) {
|
||||
var testFn;
|
||||
container = container || this;
|
||||
|
||||
if (typeof match === 'string') {
|
||||
testFn = select.compile(match, container.options);
|
||||
} else if (typeof match === 'function') {
|
||||
testFn = function(el, i) {
|
||||
return match.call(el, i, el);
|
||||
};
|
||||
} else if (match.cheerio) {
|
||||
testFn = match.is.bind(match);
|
||||
} else {
|
||||
testFn = function(el) {
|
||||
return match === el;
|
||||
};
|
||||
}
|
||||
|
||||
return container._make(filterFn(this, testFn));
|
||||
};
|
||||
};
|
||||
|
||||
exports.filter = makeFilterMethod(_.filter);
|
||||
exports.not = makeFilterMethod(_.reject);
|
||||
|
||||
exports.has = function(selectorOrHaystack) {
|
||||
var that = this;
|
||||
return exports.filter.call(this, function() {
|
||||
return that._make(this).find(selectorOrHaystack).length > 0;
|
||||
});
|
||||
};
|
||||
|
||||
exports.first = function() {
|
||||
return this.length > 1 ? this._make(this[0]) : this;
|
||||
};
|
||||
|
||||
exports.last = function() {
|
||||
return this.length > 1 ? this._make(this[this.length - 1]) : this;
|
||||
};
|
||||
|
||||
// Reduce the set of matched elements to the one at the specified index.
|
||||
exports.eq = function(i) {
|
||||
i = +i;
|
||||
|
||||
// Use the first identity optimization if possible
|
||||
if (i === 0 && this.length <= 1) return this;
|
||||
|
||||
if (i < 0) i = this.length + i;
|
||||
return this[i] ? this._make(this[i]) : this._make([]);
|
||||
};
|
||||
|
||||
// Retrieve the DOM elements matched by the jQuery object.
|
||||
exports.get = function(i) {
|
||||
if (i == null) {
|
||||
return Array.prototype.slice.call(this);
|
||||
} else {
|
||||
return this[i < 0 ? (this.length + i) : i];
|
||||
}
|
||||
};
|
||||
|
||||
// Search for a given element from among the matched elements.
|
||||
exports.index = function(selectorOrNeedle) {
|
||||
var $haystack, needle;
|
||||
|
||||
if (arguments.length === 0) {
|
||||
$haystack = this.parent().children();
|
||||
needle = this[0];
|
||||
} else if (typeof selectorOrNeedle === 'string') {
|
||||
$haystack = this._make(selectorOrNeedle);
|
||||
needle = this[0];
|
||||
} else {
|
||||
$haystack = this;
|
||||
needle = selectorOrNeedle.cheerio ? selectorOrNeedle[0] : selectorOrNeedle;
|
||||
}
|
||||
|
||||
return $haystack.get().indexOf(needle);
|
||||
};
|
||||
|
||||
exports.slice = function() {
|
||||
return this._make([].slice.apply(this, arguments));
|
||||
};
|
||||
|
||||
function traverseParents(self, elem, selector, limit) {
|
||||
var elems = [];
|
||||
while (elem && elems.length < limit) {
|
||||
if (!selector || exports.filter.call([elem], selector, self).length) {
|
||||
elems.push(elem);
|
||||
}
|
||||
elem = elem.parent;
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
|
||||
// End the most recent filtering operation in the current chain and return the
|
||||
// set of matched elements to its previous state.
|
||||
exports.end = function() {
|
||||
return this.prevObject || this._make([]);
|
||||
};
|
||||
|
||||
exports.add = function(other, context) {
|
||||
var selection = this._make(other, context);
|
||||
var contents = uniqueSort(selection.get().concat(this.get()));
|
||||
|
||||
for (var i = 0; i < contents.length; ++i) {
|
||||
selection[i] = contents[i];
|
||||
}
|
||||
selection.length = contents.length;
|
||||
|
||||
return selection;
|
||||
};
|
||||
|
||||
// Add the previous set of elements on the stack to the current set, optionally
|
||||
// filtered by a selector.
|
||||
exports.addBack = function(selector) {
|
||||
return this.add(
|
||||
arguments.length ? this.prevObject.filter(selector) : this.prevObject
|
||||
);
|
||||
};
|
||||
139
node_modules/cheerio/lib/cheerio.js
generated
vendored
Normal file
139
node_modules/cheerio/lib/cheerio.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
Module dependencies
|
||||
*/
|
||||
|
||||
var parse = require('./parse'),
|
||||
defaultOptions = require('./options').default,
|
||||
flattenOptions = require('./options').flatten,
|
||||
isHtml = require('./utils').isHtml,
|
||||
_ = {
|
||||
extend: require('lodash/assignIn'),
|
||||
bind: require('lodash/bind'),
|
||||
forEach: require('lodash/forEach'),
|
||||
defaults: require('lodash/defaults')
|
||||
};
|
||||
|
||||
/*
|
||||
* The API
|
||||
*/
|
||||
|
||||
var api = [
|
||||
require('./api/attributes'),
|
||||
require('./api/traversing'),
|
||||
require('./api/manipulation'),
|
||||
require('./api/css'),
|
||||
require('./api/forms')
|
||||
];
|
||||
|
||||
/*
|
||||
* Instance of cheerio
|
||||
*/
|
||||
|
||||
var Cheerio = module.exports = function(selector, context, root, options) {
|
||||
if (!(this instanceof Cheerio)) return new Cheerio(selector, context, root, options);
|
||||
|
||||
this.options = _.defaults(flattenOptions(options), this.options, defaultOptions);
|
||||
|
||||
// $(), $(null), $(undefined), $(false)
|
||||
if (!selector) return this;
|
||||
|
||||
if (root) {
|
||||
if (typeof root === 'string') root = parse(root, this.options, false);
|
||||
this._root = Cheerio.call(this, root);
|
||||
}
|
||||
|
||||
// $($)
|
||||
if (selector.cheerio) return selector;
|
||||
|
||||
// $(dom)
|
||||
if (isNode(selector))
|
||||
selector = [selector];
|
||||
|
||||
// $([dom])
|
||||
if (Array.isArray(selector)) {
|
||||
_.forEach(selector, _.bind(function(elem, idx) {
|
||||
this[idx] = elem;
|
||||
}, this));
|
||||
this.length = selector.length;
|
||||
return this;
|
||||
}
|
||||
|
||||
// $(<html>)
|
||||
if (typeof selector === 'string' && isHtml(selector)) {
|
||||
return Cheerio.call(this, parse(selector, this.options, false).children);
|
||||
}
|
||||
|
||||
// If we don't have a context, maybe we have a root, from loading
|
||||
if (!context) {
|
||||
context = this._root;
|
||||
} else if (typeof context === 'string') {
|
||||
if (isHtml(context)) {
|
||||
// $('li', '<ul>...</ul>')
|
||||
context = parse(context, this.options, false);
|
||||
context = Cheerio.call(this, context);
|
||||
} else {
|
||||
// $('li', 'ul')
|
||||
selector = [context, selector].join(' ');
|
||||
context = this._root;
|
||||
}
|
||||
// $('li', node), $('li', [nodes])
|
||||
} else if (!context.cheerio) {
|
||||
context = Cheerio.call(this, context);
|
||||
}
|
||||
|
||||
// If we still don't have a context, return
|
||||
if (!context) return this;
|
||||
|
||||
// #id, .class, tag
|
||||
return context.find(selector);
|
||||
};
|
||||
|
||||
/**
|
||||
* Mix in `static`
|
||||
*/
|
||||
|
||||
_.extend(Cheerio, require('./static'));
|
||||
|
||||
/*
|
||||
* Set a signature of the object
|
||||
*/
|
||||
|
||||
Cheerio.prototype.cheerio = '[cheerio object]';
|
||||
|
||||
/*
|
||||
* Make cheerio an array-like object
|
||||
*/
|
||||
|
||||
Cheerio.prototype.length = 0;
|
||||
Cheerio.prototype.splice = Array.prototype.splice;
|
||||
|
||||
/*
|
||||
* Make a cheerio object
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Cheerio.prototype._make = function(dom, context) {
|
||||
var cheerio = new this.constructor(dom, context, this._root, this.options);
|
||||
cheerio.prevObject = this;
|
||||
return cheerio;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn a cheerio object into an array
|
||||
*/
|
||||
|
||||
Cheerio.prototype.toArray = function() {
|
||||
return this.get();
|
||||
};
|
||||
|
||||
/**
|
||||
* Plug in the API
|
||||
*/
|
||||
api.forEach(function(mod) {
|
||||
_.extend(Cheerio.prototype, mod);
|
||||
});
|
||||
|
||||
var isNode = function(obj) {
|
||||
return obj.name || obj.type === 'text' || obj.type === 'comment';
|
||||
};
|
||||
16
node_modules/cheerio/lib/options.js
generated
vendored
Normal file
16
node_modules/cheerio/lib/options.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var assign = require('lodash/assign');
|
||||
|
||||
/*
|
||||
* Cheerio default options
|
||||
*/
|
||||
|
||||
exports.default = {
|
||||
withDomLvl1: true,
|
||||
normalizeWhitespace: false,
|
||||
xml: false,
|
||||
decodeEntities: true
|
||||
};
|
||||
|
||||
exports.flatten = function(options) {
|
||||
return options && options.xml ? assign({xmlMode: true}, options.xml) : options;
|
||||
};
|
||||
100
node_modules/cheerio/lib/parse.js
generated
vendored
Normal file
100
node_modules/cheerio/lib/parse.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Module Dependencies
|
||||
*/
|
||||
var htmlparser = require('htmlparser2'),
|
||||
parse5 = require('parse5');
|
||||
|
||||
/*
|
||||
Parser
|
||||
*/
|
||||
exports = module.exports = function(content, options, isDocument) {
|
||||
var dom = exports.evaluate(content, options, isDocument),
|
||||
// Generic root element
|
||||
root = exports.evaluate('<root></root>', options, false)[0];
|
||||
|
||||
root.type = 'root';
|
||||
root.parent = null;
|
||||
|
||||
// Update the dom using the root
|
||||
exports.update(dom, root);
|
||||
|
||||
return root;
|
||||
};
|
||||
|
||||
function parseWithParse5 (content, isDocument) {
|
||||
var parse = isDocument ? parse5.parse : parse5.parseFragment,
|
||||
root = parse(content, { treeAdapter: parse5.treeAdapters.htmlparser2 });
|
||||
|
||||
return root.children;
|
||||
}
|
||||
|
||||
exports.evaluate = function(content, options, isDocument) {
|
||||
// options = options || $.fn.options;
|
||||
|
||||
var dom;
|
||||
|
||||
if (Buffer.isBuffer(content))
|
||||
content = content.toString();
|
||||
|
||||
if (typeof content === 'string') {
|
||||
var useHtmlParser2 = options.xmlMode || options._useHtmlParser2;
|
||||
|
||||
dom = useHtmlParser2 ? htmlparser.parseDOM(content, options) : parseWithParse5(content, isDocument);
|
||||
} else {
|
||||
dom = content;
|
||||
}
|
||||
|
||||
return dom;
|
||||
};
|
||||
|
||||
/*
|
||||
Update the dom structure, for one changed layer
|
||||
*/
|
||||
exports.update = function(arr, parent) {
|
||||
// normalize
|
||||
if (!Array.isArray(arr)) arr = [arr];
|
||||
|
||||
// Update parent
|
||||
if (parent) {
|
||||
parent.children = arr;
|
||||
} else {
|
||||
parent = null;
|
||||
}
|
||||
|
||||
// Update neighbors
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var node = arr[i];
|
||||
|
||||
// Cleanly remove existing nodes from their previous structures.
|
||||
var oldParent = node.parent || node.root,
|
||||
oldSiblings = oldParent && oldParent.children;
|
||||
if (oldSiblings && oldSiblings !== arr) {
|
||||
oldSiblings.splice(oldSiblings.indexOf(node), 1);
|
||||
if (node.prev) {
|
||||
node.prev.next = node.next;
|
||||
}
|
||||
if (node.next) {
|
||||
node.next.prev = node.prev;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
node.prev = arr[i - 1] || null;
|
||||
node.next = arr[i + 1] || null;
|
||||
} else {
|
||||
node.prev = node.next = null;
|
||||
}
|
||||
|
||||
if (parent && parent.type === 'root') {
|
||||
node.root = parent;
|
||||
node.parent = null;
|
||||
} else {
|
||||
node.root = null;
|
||||
node.parent = parent;
|
||||
}
|
||||
}
|
||||
|
||||
return parent;
|
||||
};
|
||||
|
||||
// module.exports = $.extend(exports);
|
||||
234
node_modules/cheerio/lib/static.js
generated
vendored
Normal file
234
node_modules/cheerio/lib/static.js
generated
vendored
Normal file
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
var serialize = require('dom-serializer'),
|
||||
defaultOptions = require('./options').default,
|
||||
flattenOptions = require('./options').flatten,
|
||||
select = require('css-select'),
|
||||
parse = require('./parse'),
|
||||
_ = {
|
||||
merge: require('lodash/merge'),
|
||||
defaults: require('lodash/defaults')
|
||||
};
|
||||
|
||||
/**
|
||||
* $.load(str)
|
||||
*/
|
||||
|
||||
exports.load = function(content, options, isDocument) {
|
||||
var Cheerio = require('./cheerio');
|
||||
|
||||
options = _.defaults(flattenOptions(options || {}), defaultOptions);
|
||||
|
||||
if (isDocument === void 0)
|
||||
isDocument = true;
|
||||
|
||||
var root = parse(content, options, isDocument);
|
||||
|
||||
var initialize = function(selector, context, r, opts) {
|
||||
if (!(this instanceof initialize)) {
|
||||
return new initialize(selector, context, r, opts);
|
||||
}
|
||||
opts = _.defaults(opts || {}, options);
|
||||
return Cheerio.call(this, selector, context, r || root, opts);
|
||||
};
|
||||
|
||||
// Ensure that selections created by the "loaded" `initialize` function are
|
||||
// true Cheerio instances.
|
||||
initialize.prototype = Object.create(Cheerio.prototype);
|
||||
initialize.prototype.constructor = initialize;
|
||||
|
||||
// Mimic jQuery's prototype alias for plugin authors.
|
||||
initialize.fn = initialize.prototype;
|
||||
|
||||
// Keep a reference to the top-level scope so we can chain methods that implicitly
|
||||
// resolve selectors; e.g. $("<span>").(".bar"), which otherwise loses ._root
|
||||
initialize.prototype._originalRoot = root;
|
||||
|
||||
// Add in the static methods
|
||||
_.merge(initialize, exports);
|
||||
|
||||
// Add in the root
|
||||
initialize._root = root;
|
||||
// store options
|
||||
initialize._options = options;
|
||||
|
||||
return initialize;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helper function
|
||||
*/
|
||||
|
||||
function render(that, dom, options) {
|
||||
if (!dom) {
|
||||
if (that._root && that._root.children) {
|
||||
dom = that._root.children;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} else if (typeof dom === 'string') {
|
||||
dom = select(dom, that._root, options);
|
||||
}
|
||||
|
||||
return serialize(dom, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* $.html([selector | dom], [options])
|
||||
*/
|
||||
|
||||
exports.html = function(dom, options) {
|
||||
// be flexible about parameters, sometimes we call html(),
|
||||
// with options as only parameter
|
||||
// check dom argument for dom element specific properties
|
||||
// assume there is no 'length' or 'type' properties in the options object
|
||||
if (Object.prototype.toString.call(dom) === '[object Object]' && !options && !('length' in dom) && !('type' in dom))
|
||||
{
|
||||
options = dom;
|
||||
dom = undefined;
|
||||
}
|
||||
|
||||
// sometimes $.html() used without preloading html
|
||||
// so fallback non existing options to the default ones
|
||||
options = _.defaults(flattenOptions(options || {}), this._options, defaultOptions);
|
||||
|
||||
return render(this, dom, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* $.xml([selector | dom])
|
||||
*/
|
||||
|
||||
exports.xml = function(dom) {
|
||||
var options = _.defaults({xml: true}, this._options);
|
||||
|
||||
return render(this, dom, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* $.text(dom)
|
||||
*/
|
||||
|
||||
exports.text = function(elems) {
|
||||
if (!elems) {
|
||||
elems = this.root();
|
||||
}
|
||||
|
||||
var ret = '',
|
||||
len = elems.length,
|
||||
elem;
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
elem = elems[i];
|
||||
if (elem.type === 'text') ret += elem.data;
|
||||
else if (elem.children && elem.type !== 'comment' && elem.tagName !== 'script' && elem.tagName !== 'style') {
|
||||
ret += exports.text(elem.children);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* $.parseHTML(data [, context ] [, keepScripts ])
|
||||
* Parses a string into an array of DOM nodes. The `context` argument has no
|
||||
* meaning for Cheerio, but it is maintained for API compatibility with jQuery.
|
||||
*/
|
||||
exports.parseHTML = function(data, context, keepScripts) {
|
||||
var parsed;
|
||||
|
||||
if (!data || typeof data !== 'string') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (typeof context === 'boolean') {
|
||||
keepScripts = context;
|
||||
}
|
||||
|
||||
parsed = this.load(data, defaultOptions, false);
|
||||
if (!keepScripts) {
|
||||
parsed('script').remove();
|
||||
}
|
||||
|
||||
// The `children` array is used by Cheerio internally to group elements that
|
||||
// share the same parents. When nodes created through `parseHTML` are
|
||||
// inserted into previously-existing DOM structures, they will be removed
|
||||
// from the `children` array. The results of `parseHTML` should remain
|
||||
// constant across these operations, so a shallow copy should be returned.
|
||||
return parsed.root()[0].children.slice();
|
||||
};
|
||||
|
||||
/**
|
||||
* $.root()
|
||||
*/
|
||||
exports.root = function() {
|
||||
return this(this._root);
|
||||
};
|
||||
|
||||
/**
|
||||
* $.contains()
|
||||
*/
|
||||
exports.contains = function(container, contained) {
|
||||
|
||||
// According to the jQuery API, an element does not "contain" itself
|
||||
if (contained === container) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Step up the descendants, stopping when the root element is reached
|
||||
// (signaled by `.parent` returning a reference to the same object)
|
||||
while (contained && contained !== contained.parent) {
|
||||
contained = contained.parent;
|
||||
if (contained === container) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* $.merge()
|
||||
*/
|
||||
|
||||
exports.merge = function(arr1, arr2) {
|
||||
if(!(isArrayLike(arr1) && isArrayLike(arr2))){
|
||||
return;
|
||||
}
|
||||
var newLength = arr1.length + arr2.length;
|
||||
var i = 0;
|
||||
while(i < arr2.length){
|
||||
arr1[i + arr1.length] = arr2[i];
|
||||
i++;
|
||||
}
|
||||
arr1.length = newLength;
|
||||
return arr1;
|
||||
};
|
||||
|
||||
function isArrayLike(item){
|
||||
if(Array.isArray(item)){
|
||||
return true;
|
||||
}
|
||||
if(typeof item !== 'object'){
|
||||
return false;
|
||||
}
|
||||
if(!item.hasOwnProperty('length')){
|
||||
return false;
|
||||
}
|
||||
if(typeof item.length !== 'number') {
|
||||
return false;
|
||||
}
|
||||
if(item.length < 0){
|
||||
return false;
|
||||
}
|
||||
var i = 0;
|
||||
while(i < item.length){
|
||||
if(!(i in item)){
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
86
node_modules/cheerio/lib/utils.js
generated
vendored
Normal file
86
node_modules/cheerio/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
var parse = require('./parse'),
|
||||
render = require('dom-serializer'),
|
||||
assign = require('lodash/assign');
|
||||
|
||||
/**
|
||||
* HTML Tags
|
||||
*/
|
||||
|
||||
var tags = { tag: true, script: true, style: true };
|
||||
|
||||
/**
|
||||
* Check if the DOM element is a tag
|
||||
*
|
||||
* isTag(type) includes <script> and <style> tags
|
||||
*/
|
||||
|
||||
exports.isTag = function(type) {
|
||||
if (type.type) type = type.type;
|
||||
return tags[type] || false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a string to camel case notation.
|
||||
* @param {String} str String to be converted.
|
||||
* @return {String} String in camel case notation.
|
||||
*/
|
||||
|
||||
exports.camelCase = function(str) {
|
||||
return str.replace(/[_.-](\w|$)/g, function(_, x) {
|
||||
return x.toUpperCase();
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a string from camel case to "CSS case", where word boundaries are
|
||||
* described by hyphens ("-") and all characters are lower-case.
|
||||
* @param {String} str String to be converted.
|
||||
* @return {string} String in "CSS case".
|
||||
*/
|
||||
exports.cssCase = function(str) {
|
||||
return str.replace(/[A-Z]/g, '-$&').toLowerCase();
|
||||
};
|
||||
|
||||
/**
|
||||
* Iterate over each DOM element without creating intermediary Cheerio instances.
|
||||
*
|
||||
* This is indented for use internally to avoid otherwise unnecessary memory pressure introduced
|
||||
* by _make.
|
||||
*/
|
||||
|
||||
exports.domEach = function(cheerio, fn) {
|
||||
var i = 0, len = cheerio.length;
|
||||
while (i < len && fn.call(cheerio, i, cheerio[i]) !== false) ++i;
|
||||
return cheerio;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a deep copy of the given DOM structure by first rendering it to a
|
||||
* string and then parsing the resultant markup.
|
||||
*
|
||||
* @argument {Object} dom - The htmlparser2-compliant DOM structure
|
||||
* @argument {Object} options - The parsing/rendering options
|
||||
*/
|
||||
exports.cloneDom = function(dom, options) {
|
||||
options = assign({}, options, { _useHtmlParser2: true });
|
||||
|
||||
return parse(render(dom, options), options, false).children;
|
||||
};
|
||||
|
||||
/*
|
||||
* A simple way to check for HTML strings or ID strings
|
||||
*/
|
||||
|
||||
var quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/;
|
||||
|
||||
/*
|
||||
* Check if string is HTML
|
||||
*/
|
||||
exports.isHtml = function(str) {
|
||||
// Faster than running regex, if str starts with `<` and ends with `>`, assume it's HTML
|
||||
if (str.charAt(0) === '<' && str.charAt(str.length - 1) === '>' && str.length >= 3) return true;
|
||||
|
||||
// Run the regex
|
||||
var match = quickExpr.exec(str);
|
||||
return !!(match && match[1]);
|
||||
};
|
||||
19
node_modules/cheerio/node_modules/parse5/LICENSE
generated
vendored
Normal file
19
node_modules/cheerio/node_modules/parse5/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2013-2016 Ivan Nikulin (ifaaan@gmail.com, https://github.com/inikulin)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
40
node_modules/cheerio/node_modules/parse5/README.md
generated
vendored
Normal file
40
node_modules/cheerio/node_modules/parse5/README.md
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<p align="center">
|
||||
<a href="https://github.com/inikulin/parse5">
|
||||
<img src="https://raw.github.com/inikulin/parse5/master/media/logo.png" alt="parse5" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<i>HTML parsing/serialization toolset for Node.js. <a href="https://html.spec.whatwg.org/multipage/">WHATWG HTML Living Standard (aka HTML5)</a>-compliant.</i>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/inikulin/parse5"><img alt="Build Status" src="https://api.travis-ci.org/inikulin/parse5.svg"></a>
|
||||
<a href="https://www.npmjs.com/package/parse5"><img alt="NPM Version" src="https://img.shields.io/npm/v/parse5.svg"></a>
|
||||
<a href="https://npmjs.org/package/parse5"><img alt="Downloads" src="http://img.shields.io/npm/dm/parse5.svg"></a>
|
||||
<a href="https://npmjs.org/package/parse5"><img alt="Downloads total" src="http://img.shields.io/npm/dt/parse5.svg"></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<b><i>parse5</i></b> provides nearly everything you may need when dealing with HTML. It's the fastest spec-compliant HTML parser
|
||||
for Node to date. It parses HTML the way the latest version of your browser does. It has proven itself reliable in such projects
|
||||
as <a href="https://github.com/tmpvar/jsdom">jsdom</a>, <a href="https://github.com/angular/angular">Angular2</a>, <a href="https://www.polymer-project.org">Polymer</a> and many more.
|
||||
</p>
|
||||
|
||||
----
|
||||
|
||||
<p align="center">
|
||||
<a href="http://inikulin.github.io/parse5">Documentation</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="http://inikulin.github.io/parse5#version-history">Version history</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="http://astexplorer.net/#/1CHlCXc4n4">Online playground</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/inikulin/parse5/issues">Issue tracker</a>
|
||||
</p>
|
||||
156
node_modules/cheerio/node_modules/parse5/lib/common/doctype.js
generated
vendored
Normal file
156
node_modules/cheerio/node_modules/parse5/lib/common/doctype.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
'use strict';
|
||||
|
||||
var DOCUMENT_MODE = require('./html').DOCUMENT_MODE;
|
||||
|
||||
//Const
|
||||
var VALID_DOCTYPE_NAME = 'html',
|
||||
QUIRKS_MODE_SYSTEM_ID = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd',
|
||||
QUIRKS_MODE_PUBLIC_ID_PREFIXES = [
|
||||
'+//silmaril//dtd html pro v0r11 19970101//en',
|
||||
'-//advasoft ltd//dtd html 3.0 aswedit + extensions//en',
|
||||
'-//as//dtd html 3.0 aswedit + extensions//en',
|
||||
'-//ietf//dtd html 2.0 level 1//en',
|
||||
'-//ietf//dtd html 2.0 level 2//en',
|
||||
'-//ietf//dtd html 2.0 strict level 1//en',
|
||||
'-//ietf//dtd html 2.0 strict level 2//en',
|
||||
'-//ietf//dtd html 2.0 strict//en',
|
||||
'-//ietf//dtd html 2.0//en',
|
||||
'-//ietf//dtd html 2.1e//en',
|
||||
'-//ietf//dtd html 3.0//en',
|
||||
'-//ietf//dtd html 3.0//en//',
|
||||
'-//ietf//dtd html 3.2 final//en',
|
||||
'-//ietf//dtd html 3.2//en',
|
||||
'-//ietf//dtd html 3//en',
|
||||
'-//ietf//dtd html level 0//en',
|
||||
'-//ietf//dtd html level 0//en//2.0',
|
||||
'-//ietf//dtd html level 1//en',
|
||||
'-//ietf//dtd html level 1//en//2.0',
|
||||
'-//ietf//dtd html level 2//en',
|
||||
'-//ietf//dtd html level 2//en//2.0',
|
||||
'-//ietf//dtd html level 3//en',
|
||||
'-//ietf//dtd html level 3//en//3.0',
|
||||
'-//ietf//dtd html strict level 0//en',
|
||||
'-//ietf//dtd html strict level 0//en//2.0',
|
||||
'-//ietf//dtd html strict level 1//en',
|
||||
'-//ietf//dtd html strict level 1//en//2.0',
|
||||
'-//ietf//dtd html strict level 2//en',
|
||||
'-//ietf//dtd html strict level 2//en//2.0',
|
||||
'-//ietf//dtd html strict level 3//en',
|
||||
'-//ietf//dtd html strict level 3//en//3.0',
|
||||
'-//ietf//dtd html strict//en',
|
||||
'-//ietf//dtd html strict//en//2.0',
|
||||
'-//ietf//dtd html strict//en//3.0',
|
||||
'-//ietf//dtd html//en',
|
||||
'-//ietf//dtd html//en//2.0',
|
||||
'-//ietf//dtd html//en//3.0',
|
||||
'-//metrius//dtd metrius presentational//en',
|
||||
'-//microsoft//dtd internet explorer 2.0 html strict//en',
|
||||
'-//microsoft//dtd internet explorer 2.0 html//en',
|
||||
'-//microsoft//dtd internet explorer 2.0 tables//en',
|
||||
'-//microsoft//dtd internet explorer 3.0 html strict//en',
|
||||
'-//microsoft//dtd internet explorer 3.0 html//en',
|
||||
'-//microsoft//dtd internet explorer 3.0 tables//en',
|
||||
'-//netscape comm. corp.//dtd html//en',
|
||||
'-//netscape comm. corp.//dtd strict html//en',
|
||||
'-//o\'reilly and associates//dtd html 2.0//en',
|
||||
'-//o\'reilly and associates//dtd html extended 1.0//en',
|
||||
'-//spyglass//dtd html 2.0 extended//en',
|
||||
'-//sq//dtd html 2.0 hotmetal + extensions//en',
|
||||
'-//sun microsystems corp.//dtd hotjava html//en',
|
||||
'-//sun microsystems corp.//dtd hotjava strict html//en',
|
||||
'-//w3c//dtd html 3 1995-03-24//en',
|
||||
'-//w3c//dtd html 3.2 draft//en',
|
||||
'-//w3c//dtd html 3.2 final//en',
|
||||
'-//w3c//dtd html 3.2//en',
|
||||
'-//w3c//dtd html 3.2s draft//en',
|
||||
'-//w3c//dtd html 4.0 frameset//en',
|
||||
'-//w3c//dtd html 4.0 transitional//en',
|
||||
'-//w3c//dtd html experimental 19960712//en',
|
||||
'-//w3c//dtd html experimental 970421//en',
|
||||
'-//w3c//dtd w3 html//en',
|
||||
'-//w3o//dtd w3 html 3.0//en',
|
||||
'-//w3o//dtd w3 html 3.0//en//',
|
||||
'-//webtechs//dtd mozilla html 2.0//en',
|
||||
'-//webtechs//dtd mozilla html//en'
|
||||
],
|
||||
QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES = QUIRKS_MODE_PUBLIC_ID_PREFIXES.concat([
|
||||
'-//w3c//dtd html 4.01 frameset//',
|
||||
'-//w3c//dtd html 4.01 transitional//'
|
||||
]),
|
||||
QUIRKS_MODE_PUBLIC_IDS = [
|
||||
'-//w3o//dtd w3 html strict 3.0//en//',
|
||||
'-/w3c/dtd html 4.0 transitional/en',
|
||||
'html'
|
||||
],
|
||||
LIMITED_QUIRKS_PUBLIC_ID_PREFIXES = [
|
||||
'-//W3C//DTD XHTML 1.0 Frameset//',
|
||||
'-//W3C//DTD XHTML 1.0 Transitional//'
|
||||
],
|
||||
LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES = LIMITED_QUIRKS_PUBLIC_ID_PREFIXES.concat([
|
||||
'-//W3C//DTD HTML 4.01 Frameset//',
|
||||
'-//W3C//DTD HTML 4.01 Transitional//'
|
||||
]);
|
||||
|
||||
|
||||
//Utils
|
||||
function enquoteDoctypeId(id) {
|
||||
var quote = id.indexOf('"') !== -1 ? '\'' : '"';
|
||||
|
||||
return quote + id + quote;
|
||||
}
|
||||
|
||||
function hasPrefix(publicId, prefixes) {
|
||||
for (var i = 0; i < prefixes.length; i++) {
|
||||
if (publicId.indexOf(prefixes[i]) === 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//API
|
||||
exports.getDocumentMode = function (name, publicId, systemId) {
|
||||
if (name !== VALID_DOCTYPE_NAME)
|
||||
return DOCUMENT_MODE.QUIRKS;
|
||||
|
||||
if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID)
|
||||
return DOCUMENT_MODE.QUIRKS;
|
||||
|
||||
if (publicId !== null) {
|
||||
publicId = publicId.toLowerCase();
|
||||
|
||||
if (QUIRKS_MODE_PUBLIC_IDS.indexOf(publicId) > -1)
|
||||
return DOCUMENT_MODE.QUIRKS;
|
||||
|
||||
var prefixes = systemId === null ? QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES : QUIRKS_MODE_PUBLIC_ID_PREFIXES;
|
||||
|
||||
if (hasPrefix(publicId, prefixes))
|
||||
return DOCUMENT_MODE.QUIRKS;
|
||||
|
||||
prefixes = systemId === null ? LIMITED_QUIRKS_PUBLIC_ID_PREFIXES : LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES;
|
||||
|
||||
if (hasPrefix(publicId, prefixes))
|
||||
return DOCUMENT_MODE.LIMITED_QUIRKS;
|
||||
}
|
||||
|
||||
return DOCUMENT_MODE.NO_QUIRKS;
|
||||
};
|
||||
|
||||
exports.serializeContent = function (name, publicId, systemId) {
|
||||
var str = '!DOCTYPE ';
|
||||
|
||||
if (name)
|
||||
str += name;
|
||||
|
||||
if (publicId !== null)
|
||||
str += ' PUBLIC ' + enquoteDoctypeId(publicId);
|
||||
|
||||
else if (systemId !== null)
|
||||
str += ' SYSTEM';
|
||||
|
||||
if (systemId !== null)
|
||||
str += ' ' + enquoteDoctypeId(systemId);
|
||||
|
||||
return str;
|
||||
};
|
||||
260
node_modules/cheerio/node_modules/parse5/lib/common/foreign_content.js
generated
vendored
Normal file
260
node_modules/cheerio/node_modules/parse5/lib/common/foreign_content.js
generated
vendored
Normal file
@@ -0,0 +1,260 @@
|
||||
'use strict';
|
||||
|
||||
var Tokenizer = require('../tokenizer'),
|
||||
HTML = require('./html');
|
||||
|
||||
//Aliases
|
||||
var $ = HTML.TAG_NAMES,
|
||||
NS = HTML.NAMESPACES,
|
||||
ATTRS = HTML.ATTRS;
|
||||
|
||||
|
||||
//MIME types
|
||||
var MIME_TYPES = {
|
||||
TEXT_HTML: 'text/html',
|
||||
APPLICATION_XML: 'application/xhtml+xml'
|
||||
};
|
||||
|
||||
//Attributes
|
||||
var DEFINITION_URL_ATTR = 'definitionurl',
|
||||
ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL',
|
||||
SVG_ATTRS_ADJUSTMENT_MAP = {
|
||||
'attributename': 'attributeName',
|
||||
'attributetype': 'attributeType',
|
||||
'basefrequency': 'baseFrequency',
|
||||
'baseprofile': 'baseProfile',
|
||||
'calcmode': 'calcMode',
|
||||
'clippathunits': 'clipPathUnits',
|
||||
'diffuseconstant': 'diffuseConstant',
|
||||
'edgemode': 'edgeMode',
|
||||
'filterunits': 'filterUnits',
|
||||
'glyphref': 'glyphRef',
|
||||
'gradienttransform': 'gradientTransform',
|
||||
'gradientunits': 'gradientUnits',
|
||||
'kernelmatrix': 'kernelMatrix',
|
||||
'kernelunitlength': 'kernelUnitLength',
|
||||
'keypoints': 'keyPoints',
|
||||
'keysplines': 'keySplines',
|
||||
'keytimes': 'keyTimes',
|
||||
'lengthadjust': 'lengthAdjust',
|
||||
'limitingconeangle': 'limitingConeAngle',
|
||||
'markerheight': 'markerHeight',
|
||||
'markerunits': 'markerUnits',
|
||||
'markerwidth': 'markerWidth',
|
||||
'maskcontentunits': 'maskContentUnits',
|
||||
'maskunits': 'maskUnits',
|
||||
'numoctaves': 'numOctaves',
|
||||
'pathlength': 'pathLength',
|
||||
'patterncontentunits': 'patternContentUnits',
|
||||
'patterntransform': 'patternTransform',
|
||||
'patternunits': 'patternUnits',
|
||||
'pointsatx': 'pointsAtX',
|
||||
'pointsaty': 'pointsAtY',
|
||||
'pointsatz': 'pointsAtZ',
|
||||
'preservealpha': 'preserveAlpha',
|
||||
'preserveaspectratio': 'preserveAspectRatio',
|
||||
'primitiveunits': 'primitiveUnits',
|
||||
'refx': 'refX',
|
||||
'refy': 'refY',
|
||||
'repeatcount': 'repeatCount',
|
||||
'repeatdur': 'repeatDur',
|
||||
'requiredextensions': 'requiredExtensions',
|
||||
'requiredfeatures': 'requiredFeatures',
|
||||
'specularconstant': 'specularConstant',
|
||||
'specularexponent': 'specularExponent',
|
||||
'spreadmethod': 'spreadMethod',
|
||||
'startoffset': 'startOffset',
|
||||
'stddeviation': 'stdDeviation',
|
||||
'stitchtiles': 'stitchTiles',
|
||||
'surfacescale': 'surfaceScale',
|
||||
'systemlanguage': 'systemLanguage',
|
||||
'tablevalues': 'tableValues',
|
||||
'targetx': 'targetX',
|
||||
'targety': 'targetY',
|
||||
'textlength': 'textLength',
|
||||
'viewbox': 'viewBox',
|
||||
'viewtarget': 'viewTarget',
|
||||
'xchannelselector': 'xChannelSelector',
|
||||
'ychannelselector': 'yChannelSelector',
|
||||
'zoomandpan': 'zoomAndPan'
|
||||
},
|
||||
XML_ATTRS_ADJUSTMENT_MAP = {
|
||||
'xlink:actuate': {prefix: 'xlink', name: 'actuate', namespace: NS.XLINK},
|
||||
'xlink:arcrole': {prefix: 'xlink', name: 'arcrole', namespace: NS.XLINK},
|
||||
'xlink:href': {prefix: 'xlink', name: 'href', namespace: NS.XLINK},
|
||||
'xlink:role': {prefix: 'xlink', name: 'role', namespace: NS.XLINK},
|
||||
'xlink:show': {prefix: 'xlink', name: 'show', namespace: NS.XLINK},
|
||||
'xlink:title': {prefix: 'xlink', name: 'title', namespace: NS.XLINK},
|
||||
'xlink:type': {prefix: 'xlink', name: 'type', namespace: NS.XLINK},
|
||||
'xml:base': {prefix: 'xml', name: 'base', namespace: NS.XML},
|
||||
'xml:lang': {prefix: 'xml', name: 'lang', namespace: NS.XML},
|
||||
'xml:space': {prefix: 'xml', name: 'space', namespace: NS.XML},
|
||||
'xmlns': {prefix: '', name: 'xmlns', namespace: NS.XMLNS},
|
||||
'xmlns:xlink': {prefix: 'xmlns', name: 'xlink', namespace: NS.XMLNS}
|
||||
|
||||
};
|
||||
|
||||
//SVG tag names adjustment map
|
||||
var SVG_TAG_NAMES_ADJUSTMENT_MAP = exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = {
|
||||
'altglyph': 'altGlyph',
|
||||
'altglyphdef': 'altGlyphDef',
|
||||
'altglyphitem': 'altGlyphItem',
|
||||
'animatecolor': 'animateColor',
|
||||
'animatemotion': 'animateMotion',
|
||||
'animatetransform': 'animateTransform',
|
||||
'clippath': 'clipPath',
|
||||
'feblend': 'feBlend',
|
||||
'fecolormatrix': 'feColorMatrix',
|
||||
'fecomponenttransfer': 'feComponentTransfer',
|
||||
'fecomposite': 'feComposite',
|
||||
'feconvolvematrix': 'feConvolveMatrix',
|
||||
'fediffuselighting': 'feDiffuseLighting',
|
||||
'fedisplacementmap': 'feDisplacementMap',
|
||||
'fedistantlight': 'feDistantLight',
|
||||
'feflood': 'feFlood',
|
||||
'fefunca': 'feFuncA',
|
||||
'fefuncb': 'feFuncB',
|
||||
'fefuncg': 'feFuncG',
|
||||
'fefuncr': 'feFuncR',
|
||||
'fegaussianblur': 'feGaussianBlur',
|
||||
'feimage': 'feImage',
|
||||
'femerge': 'feMerge',
|
||||
'femergenode': 'feMergeNode',
|
||||
'femorphology': 'feMorphology',
|
||||
'feoffset': 'feOffset',
|
||||
'fepointlight': 'fePointLight',
|
||||
'fespecularlighting': 'feSpecularLighting',
|
||||
'fespotlight': 'feSpotLight',
|
||||
'fetile': 'feTile',
|
||||
'feturbulence': 'feTurbulence',
|
||||
'foreignobject': 'foreignObject',
|
||||
'glyphref': 'glyphRef',
|
||||
'lineargradient': 'linearGradient',
|
||||
'radialgradient': 'radialGradient',
|
||||
'textpath': 'textPath'
|
||||
};
|
||||
|
||||
//Tags that causes exit from foreign content
|
||||
var EXITS_FOREIGN_CONTENT = Object.create(null);
|
||||
|
||||
EXITS_FOREIGN_CONTENT[$.B] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.BIG] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.BLOCKQUOTE] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.BODY] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.BR] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.CENTER] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.CODE] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.DD] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.DIV] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.DL] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.DT] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.EM] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.EMBED] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.H1] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.H2] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.H3] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.H4] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.H5] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.H6] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.HEAD] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.HR] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.I] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.IMG] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.LI] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.LISTING] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.MENU] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.META] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.NOBR] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.OL] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.P] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.PRE] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.RUBY] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.S] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.SMALL] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.SPAN] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.STRONG] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.STRIKE] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.SUB] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.SUP] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.TABLE] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.TT] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.U] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.UL] = true;
|
||||
EXITS_FOREIGN_CONTENT[$.VAR] = true;
|
||||
|
||||
//Check exit from foreign content
|
||||
exports.causesExit = function (startTagToken) {
|
||||
var tn = startTagToken.tagName;
|
||||
var isFontWithAttrs = tn === $.FONT && (Tokenizer.getTokenAttr(startTagToken, ATTRS.COLOR) !== null ||
|
||||
Tokenizer.getTokenAttr(startTagToken, ATTRS.SIZE) !== null ||
|
||||
Tokenizer.getTokenAttr(startTagToken, ATTRS.FACE) !== null);
|
||||
|
||||
return isFontWithAttrs ? true : EXITS_FOREIGN_CONTENT[tn];
|
||||
};
|
||||
|
||||
//Token adjustments
|
||||
exports.adjustTokenMathMLAttrs = function (token) {
|
||||
for (var i = 0; i < token.attrs.length; i++) {
|
||||
if (token.attrs[i].name === DEFINITION_URL_ATTR) {
|
||||
token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.adjustTokenSVGAttrs = function (token) {
|
||||
for (var i = 0; i < token.attrs.length; i++) {
|
||||
var adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
|
||||
|
||||
if (adjustedAttrName)
|
||||
token.attrs[i].name = adjustedAttrName;
|
||||
}
|
||||
};
|
||||
|
||||
exports.adjustTokenXMLAttrs = function (token) {
|
||||
for (var i = 0; i < token.attrs.length; i++) {
|
||||
var adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP[token.attrs[i].name];
|
||||
|
||||
if (adjustedAttrEntry) {
|
||||
token.attrs[i].prefix = adjustedAttrEntry.prefix;
|
||||
token.attrs[i].name = adjustedAttrEntry.name;
|
||||
token.attrs[i].namespace = adjustedAttrEntry.namespace;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.adjustTokenSVGTagName = function (token) {
|
||||
var adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP[token.tagName];
|
||||
|
||||
if (adjustedTagName)
|
||||
token.tagName = adjustedTagName;
|
||||
};
|
||||
|
||||
//Integration points
|
||||
function isMathMLTextIntegrationPoint(tn, ns) {
|
||||
return ns === NS.MATHML && (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS || tn === $.MTEXT);
|
||||
}
|
||||
|
||||
function isHtmlIntegrationPoint(tn, ns, attrs) {
|
||||
if (ns === NS.MATHML && tn === $.ANNOTATION_XML) {
|
||||
for (var i = 0; i < attrs.length; i++) {
|
||||
if (attrs[i].name === ATTRS.ENCODING) {
|
||||
var value = attrs[i].value.toLowerCase();
|
||||
|
||||
return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ns === NS.SVG && (tn === $.FOREIGN_OBJECT || tn === $.DESC || tn === $.TITLE);
|
||||
}
|
||||
|
||||
exports.isIntegrationPoint = function (tn, ns, attrs, foreignNS) {
|
||||
if ((!foreignNS || foreignNS === NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs))
|
||||
return true;
|
||||
|
||||
if ((!foreignNS || foreignNS === NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
};
|
||||
272
node_modules/cheerio/node_modules/parse5/lib/common/html.js
generated
vendored
Normal file
272
node_modules/cheerio/node_modules/parse5/lib/common/html.js
generated
vendored
Normal file
@@ -0,0 +1,272 @@
|
||||
'use strict';
|
||||
|
||||
var NS = exports.NAMESPACES = {
|
||||
HTML: 'http://www.w3.org/1999/xhtml',
|
||||
MATHML: 'http://www.w3.org/1998/Math/MathML',
|
||||
SVG: 'http://www.w3.org/2000/svg',
|
||||
XLINK: 'http://www.w3.org/1999/xlink',
|
||||
XML: 'http://www.w3.org/XML/1998/namespace',
|
||||
XMLNS: 'http://www.w3.org/2000/xmlns/'
|
||||
};
|
||||
|
||||
exports.ATTRS = {
|
||||
TYPE: 'type',
|
||||
ACTION: 'action',
|
||||
ENCODING: 'encoding',
|
||||
PROMPT: 'prompt',
|
||||
NAME: 'name',
|
||||
COLOR: 'color',
|
||||
FACE: 'face',
|
||||
SIZE: 'size'
|
||||
};
|
||||
|
||||
exports.DOCUMENT_MODE = {
|
||||
NO_QUIRKS: 'no-quirks',
|
||||
QUIRKS: 'quirks',
|
||||
LIMITED_QUIRKS: 'limited-quirks'
|
||||
};
|
||||
|
||||
var $ = exports.TAG_NAMES = {
|
||||
A: 'a',
|
||||
ADDRESS: 'address',
|
||||
ANNOTATION_XML: 'annotation-xml',
|
||||
APPLET: 'applet',
|
||||
AREA: 'area',
|
||||
ARTICLE: 'article',
|
||||
ASIDE: 'aside',
|
||||
|
||||
B: 'b',
|
||||
BASE: 'base',
|
||||
BASEFONT: 'basefont',
|
||||
BGSOUND: 'bgsound',
|
||||
BIG: 'big',
|
||||
BLOCKQUOTE: 'blockquote',
|
||||
BODY: 'body',
|
||||
BR: 'br',
|
||||
BUTTON: 'button',
|
||||
|
||||
CAPTION: 'caption',
|
||||
CENTER: 'center',
|
||||
CODE: 'code',
|
||||
COL: 'col',
|
||||
COLGROUP: 'colgroup',
|
||||
|
||||
DD: 'dd',
|
||||
DESC: 'desc',
|
||||
DETAILS: 'details',
|
||||
DIALOG: 'dialog',
|
||||
DIR: 'dir',
|
||||
DIV: 'div',
|
||||
DL: 'dl',
|
||||
DT: 'dt',
|
||||
|
||||
EM: 'em',
|
||||
EMBED: 'embed',
|
||||
|
||||
FIELDSET: 'fieldset',
|
||||
FIGCAPTION: 'figcaption',
|
||||
FIGURE: 'figure',
|
||||
FONT: 'font',
|
||||
FOOTER: 'footer',
|
||||
FOREIGN_OBJECT: 'foreignObject',
|
||||
FORM: 'form',
|
||||
FRAME: 'frame',
|
||||
FRAMESET: 'frameset',
|
||||
|
||||
H1: 'h1',
|
||||
H2: 'h2',
|
||||
H3: 'h3',
|
||||
H4: 'h4',
|
||||
H5: 'h5',
|
||||
H6: 'h6',
|
||||
HEAD: 'head',
|
||||
HEADER: 'header',
|
||||
HGROUP: 'hgroup',
|
||||
HR: 'hr',
|
||||
HTML: 'html',
|
||||
|
||||
I: 'i',
|
||||
IMG: 'img',
|
||||
IMAGE: 'image',
|
||||
INPUT: 'input',
|
||||
IFRAME: 'iframe',
|
||||
|
||||
KEYGEN: 'keygen',
|
||||
|
||||
LABEL: 'label',
|
||||
LI: 'li',
|
||||
LINK: 'link',
|
||||
LISTING: 'listing',
|
||||
|
||||
MAIN: 'main',
|
||||
MALIGNMARK: 'malignmark',
|
||||
MARQUEE: 'marquee',
|
||||
MATH: 'math',
|
||||
MENU: 'menu',
|
||||
MENUITEM: 'menuitem',
|
||||
META: 'meta',
|
||||
MGLYPH: 'mglyph',
|
||||
MI: 'mi',
|
||||
MO: 'mo',
|
||||
MN: 'mn',
|
||||
MS: 'ms',
|
||||
MTEXT: 'mtext',
|
||||
|
||||
NAV: 'nav',
|
||||
NOBR: 'nobr',
|
||||
NOFRAMES: 'noframes',
|
||||
NOEMBED: 'noembed',
|
||||
NOSCRIPT: 'noscript',
|
||||
|
||||
OBJECT: 'object',
|
||||
OL: 'ol',
|
||||
OPTGROUP: 'optgroup',
|
||||
OPTION: 'option',
|
||||
|
||||
P: 'p',
|
||||
PARAM: 'param',
|
||||
PLAINTEXT: 'plaintext',
|
||||
PRE: 'pre',
|
||||
|
||||
RB: 'rb',
|
||||
RP: 'rp',
|
||||
RT: 'rt',
|
||||
RTC: 'rtc',
|
||||
RUBY: 'ruby',
|
||||
|
||||
S: 's',
|
||||
SCRIPT: 'script',
|
||||
SECTION: 'section',
|
||||
SELECT: 'select',
|
||||
SOURCE: 'source',
|
||||
SMALL: 'small',
|
||||
SPAN: 'span',
|
||||
STRIKE: 'strike',
|
||||
STRONG: 'strong',
|
||||
STYLE: 'style',
|
||||
SUB: 'sub',
|
||||
SUMMARY: 'summary',
|
||||
SUP: 'sup',
|
||||
|
||||
TABLE: 'table',
|
||||
TBODY: 'tbody',
|
||||
TEMPLATE: 'template',
|
||||
TEXTAREA: 'textarea',
|
||||
TFOOT: 'tfoot',
|
||||
TD: 'td',
|
||||
TH: 'th',
|
||||
THEAD: 'thead',
|
||||
TITLE: 'title',
|
||||
TR: 'tr',
|
||||
TRACK: 'track',
|
||||
TT: 'tt',
|
||||
|
||||
U: 'u',
|
||||
UL: 'ul',
|
||||
|
||||
SVG: 'svg',
|
||||
|
||||
VAR: 'var',
|
||||
|
||||
WBR: 'wbr',
|
||||
|
||||
XMP: 'xmp'
|
||||
};
|
||||
|
||||
var SPECIAL_ELEMENTS = exports.SPECIAL_ELEMENTS = Object.create(null);
|
||||
|
||||
SPECIAL_ELEMENTS[NS.HTML] = Object.create(null);
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.ADDRESS] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.APPLET] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.AREA] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.ARTICLE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.ASIDE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.BASE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.BASEFONT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.BGSOUND] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.BLOCKQUOTE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.BODY] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.BR] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.BUTTON] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.CAPTION] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.CENTER] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.COL] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.COLGROUP] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.DD] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.DETAILS] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.DIR] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.DIV] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.DL] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.DT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.EMBED] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.FIELDSET] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.FIGCAPTION] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.FIGURE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.FOOTER] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.FORM] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.FRAME] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.FRAMESET] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.H1] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.H2] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.H3] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.H4] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.H5] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.H6] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.HEAD] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.HEADER] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.HGROUP] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.HR] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.HTML] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.IFRAME] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.IMG] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.INPUT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.LI] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.LINK] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.LISTING] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.MAIN] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.MARQUEE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.MENU] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.META] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.NAV] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.NOEMBED] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.NOFRAMES] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.NOSCRIPT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.OBJECT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.OL] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.P] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.PARAM] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.PLAINTEXT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.PRE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.SCRIPT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.SECTION] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.SELECT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.SOURCE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.STYLE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.SUMMARY] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TABLE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TBODY] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TD] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TEMPLATE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TEXTAREA] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TFOOT] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TH] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.THEAD] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TITLE] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TR] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.TRACK] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.UL] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.WBR] = true;
|
||||
SPECIAL_ELEMENTS[NS.HTML][$.XMP] = true;
|
||||
|
||||
SPECIAL_ELEMENTS[NS.MATHML] = Object.create(null);
|
||||
SPECIAL_ELEMENTS[NS.MATHML][$.MI] = true;
|
||||
SPECIAL_ELEMENTS[NS.MATHML][$.MO] = true;
|
||||
SPECIAL_ELEMENTS[NS.MATHML][$.MN] = true;
|
||||
SPECIAL_ELEMENTS[NS.MATHML][$.MS] = true;
|
||||
SPECIAL_ELEMENTS[NS.MATHML][$.MTEXT] = true;
|
||||
SPECIAL_ELEMENTS[NS.MATHML][$.ANNOTATION_XML] = true;
|
||||
|
||||
SPECIAL_ELEMENTS[NS.SVG] = Object.create(null);
|
||||
SPECIAL_ELEMENTS[NS.SVG][$.TITLE] = true;
|
||||
SPECIAL_ELEMENTS[NS.SVG][$.FOREIGN_OBJECT] = true;
|
||||
SPECIAL_ELEMENTS[NS.SVG][$.DESC] = true;
|
||||
47
node_modules/cheerio/node_modules/parse5/lib/common/unicode.js
generated
vendored
Normal file
47
node_modules/cheerio/node_modules/parse5/lib/common/unicode.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
exports.REPLACEMENT_CHARACTER = '\uFFFD';
|
||||
|
||||
exports.CODE_POINTS = {
|
||||
EOF: -1,
|
||||
NULL: 0x00,
|
||||
TABULATION: 0x09,
|
||||
CARRIAGE_RETURN: 0x0D,
|
||||
LINE_FEED: 0x0A,
|
||||
FORM_FEED: 0x0C,
|
||||
SPACE: 0x20,
|
||||
EXCLAMATION_MARK: 0x21,
|
||||
QUOTATION_MARK: 0x22,
|
||||
NUMBER_SIGN: 0x23,
|
||||
AMPERSAND: 0x26,
|
||||
APOSTROPHE: 0x27,
|
||||
HYPHEN_MINUS: 0x2D,
|
||||
SOLIDUS: 0x2F,
|
||||
DIGIT_0: 0x30,
|
||||
DIGIT_9: 0x39,
|
||||
SEMICOLON: 0x3B,
|
||||
LESS_THAN_SIGN: 0x3C,
|
||||
EQUALS_SIGN: 0x3D,
|
||||
GREATER_THAN_SIGN: 0x3E,
|
||||
QUESTION_MARK: 0x3F,
|
||||
LATIN_CAPITAL_A: 0x41,
|
||||
LATIN_CAPITAL_F: 0x46,
|
||||
LATIN_CAPITAL_X: 0x58,
|
||||
LATIN_CAPITAL_Z: 0x5A,
|
||||
GRAVE_ACCENT: 0x60,
|
||||
LATIN_SMALL_A: 0x61,
|
||||
LATIN_SMALL_F: 0x66,
|
||||
LATIN_SMALL_X: 0x78,
|
||||
LATIN_SMALL_Z: 0x7A,
|
||||
REPLACEMENT_CHARACTER: 0xFFFD
|
||||
};
|
||||
|
||||
exports.CODE_POINT_SEQUENCES = {
|
||||
DASH_DASH_STRING: [0x2D, 0x2D], //--
|
||||
DOCTYPE_STRING: [0x44, 0x4F, 0x43, 0x54, 0x59, 0x50, 0x45], //DOCTYPE
|
||||
CDATA_START_STRING: [0x5B, 0x43, 0x44, 0x41, 0x54, 0x41, 0x5B], //[CDATA[
|
||||
CDATA_END_STRING: [0x5D, 0x5D, 0x3E], //]]>
|
||||
SCRIPT_STRING: [0x73, 0x63, 0x72, 0x69, 0x70, 0x74], //script
|
||||
PUBLIC_STRING: [0x50, 0x55, 0x42, 0x4C, 0x49, 0x43], //PUBLIC
|
||||
SYSTEM_STRING: [0x53, 0x59, 0x53, 0x54, 0x45, 0x4D] //SYSTEM
|
||||
};
|
||||
34
node_modules/cheerio/node_modules/parse5/lib/extensions/location_info/open_element_stack_mixin.js
generated
vendored
Normal file
34
node_modules/cheerio/node_modules/parse5/lib/extensions/location_info/open_element_stack_mixin.js
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
var Mixin = require('../../utils/mixin'),
|
||||
inherits = require('util').inherits;
|
||||
|
||||
var LocationInfoOpenElementStackMixin = module.exports = function (stack, options) {
|
||||
Mixin.call(this, stack);
|
||||
|
||||
this.onItemPop = options.onItemPop;
|
||||
};
|
||||
|
||||
inherits(LocationInfoOpenElementStackMixin, Mixin);
|
||||
|
||||
LocationInfoOpenElementStackMixin.prototype._getOverriddenMethods = function (mxn, orig) {
|
||||
return {
|
||||
pop: function () {
|
||||
mxn.onItemPop(this.current);
|
||||
orig.pop.call(this);
|
||||
},
|
||||
|
||||
popAllUpToHtmlElement: function () {
|
||||
for (var i = this.stackTop; i > 0; i--)
|
||||
mxn.onItemPop(this.items[i]);
|
||||
|
||||
orig.popAllUpToHtmlElement.call(this);
|
||||
},
|
||||
|
||||
remove: function (element) {
|
||||
mxn.onItemPop(this.current);
|
||||
orig.remove.call(this, element);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
213
node_modules/cheerio/node_modules/parse5/lib/extensions/location_info/parser_mixin.js
generated
vendored
Normal file
213
node_modules/cheerio/node_modules/parse5/lib/extensions/location_info/parser_mixin.js
generated
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
'use strict';
|
||||
|
||||
var Mixin = require('../../utils/mixin'),
|
||||
Tokenizer = require('../../tokenizer'),
|
||||
LocationInfoTokenizerMixin = require('./tokenizer_mixin'),
|
||||
PositionTrackingPreprocessorMixin = require('../position_tracking/preprocessor_mixin'),
|
||||
LocationInfoOpenElementStackMixin = require('./open_element_stack_mixin'),
|
||||
HTML = require('../../common/html'),
|
||||
inherits = require('util').inherits;
|
||||
|
||||
|
||||
//Aliases
|
||||
var $ = HTML.TAG_NAMES;
|
||||
|
||||
var LocationInfoParserMixin = module.exports = function (parser) {
|
||||
Mixin.call(this, parser);
|
||||
|
||||
this.parser = parser;
|
||||
this.posTracker = null;
|
||||
this.lastStartTagToken = null;
|
||||
this.lastFosterParentingLocation = null;
|
||||
this.currentToken = null;
|
||||
};
|
||||
|
||||
inherits(LocationInfoParserMixin, Mixin);
|
||||
|
||||
|
||||
LocationInfoParserMixin.prototype._setStartLocation = function (element) {
|
||||
if (this.lastStartTagToken) {
|
||||
element.__location = Object.create(this.lastStartTagToken.location);
|
||||
element.__location.startTag = this.lastStartTagToken.location;
|
||||
}
|
||||
else
|
||||
element.__location = null;
|
||||
};
|
||||
|
||||
LocationInfoParserMixin.prototype._setEndLocation = function (element, closingToken) {
|
||||
var loc = element.__location;
|
||||
|
||||
if (loc) {
|
||||
if (closingToken.location) {
|
||||
var ctLoc = closingToken.location,
|
||||
tn = this.parser.treeAdapter.getTagName(element);
|
||||
|
||||
// NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing
|
||||
// tag and for cases like <td> <p> </td> - 'p' closes without a closing tag.
|
||||
var isClosingEndTag = closingToken.type === Tokenizer.END_TAG_TOKEN && tn === closingToken.tagName;
|
||||
|
||||
if (isClosingEndTag) {
|
||||
loc.endTag = Object.create(ctLoc);
|
||||
loc.endOffset = ctLoc.endOffset;
|
||||
}
|
||||
|
||||
else
|
||||
loc.endOffset = ctLoc.startOffset;
|
||||
}
|
||||
|
||||
else if (closingToken.type === Tokenizer.EOF_TOKEN)
|
||||
loc.endOffset = this.posTracker.offset;
|
||||
}
|
||||
};
|
||||
|
||||
LocationInfoParserMixin.prototype._getOverriddenMethods = function (mxn, orig) {
|
||||
return {
|
||||
_bootstrap: function (document, fragmentContext) {
|
||||
orig._bootstrap.call(this, document, fragmentContext);
|
||||
|
||||
mxn.lastStartTagToken = null;
|
||||
mxn.lastFosterParentingLocation = null;
|
||||
mxn.currentToken = null;
|
||||
mxn.posTracker = new PositionTrackingPreprocessorMixin(this.tokenizer.preprocessor);
|
||||
|
||||
new LocationInfoTokenizerMixin(this.tokenizer);
|
||||
|
||||
new LocationInfoOpenElementStackMixin(this.openElements, {
|
||||
onItemPop: function (element) {
|
||||
mxn._setEndLocation(element, mxn.currentToken);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_runParsingLoop: function (scriptHandler) {
|
||||
orig._runParsingLoop.call(this, scriptHandler);
|
||||
|
||||
// NOTE: generate location info for elements
|
||||
// that remains on open element stack
|
||||
for (var i = this.openElements.stackTop; i >= 0; i--)
|
||||
mxn._setEndLocation(this.openElements.items[i], mxn.currentToken);
|
||||
},
|
||||
|
||||
|
||||
//Token processing
|
||||
_processTokenInForeignContent: function (token) {
|
||||
mxn.currentToken = token;
|
||||
orig._processTokenInForeignContent.call(this, token);
|
||||
},
|
||||
|
||||
_processToken: function (token) {
|
||||
mxn.currentToken = token;
|
||||
orig._processToken.call(this, token);
|
||||
|
||||
//NOTE: <body> and <html> are never popped from the stack, so we need to updated
|
||||
//their end location explicitly.
|
||||
var requireExplicitUpdate = token.type === Tokenizer.END_TAG_TOKEN &&
|
||||
(token.tagName === $.HTML ||
|
||||
token.tagName === $.BODY && this.openElements.hasInScope($.BODY));
|
||||
|
||||
if (requireExplicitUpdate) {
|
||||
for (var i = this.openElements.stackTop; i >= 0; i--) {
|
||||
var element = this.openElements.items[i];
|
||||
|
||||
if (this.treeAdapter.getTagName(element) === token.tagName) {
|
||||
mxn._setEndLocation(element, token);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
//Doctype
|
||||
_setDocumentType: function (token) {
|
||||
orig._setDocumentType.call(this, token);
|
||||
|
||||
var documentChildren = this.treeAdapter.getChildNodes(this.document),
|
||||
cnLength = documentChildren.length;
|
||||
|
||||
for (var i = 0; i < cnLength; i++) {
|
||||
var node = documentChildren[i];
|
||||
|
||||
if (this.treeAdapter.isDocumentTypeNode(node)) {
|
||||
node.__location = token.location;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
//Elements
|
||||
_attachElementToTree: function (element) {
|
||||
//NOTE: _attachElementToTree is called from _appendElement, _insertElement and _insertTemplate methods.
|
||||
//So we will use token location stored in this methods for the element.
|
||||
mxn._setStartLocation(element);
|
||||
mxn.lastStartTagToken = null;
|
||||
orig._attachElementToTree.call(this, element);
|
||||
},
|
||||
|
||||
_appendElement: function (token, namespaceURI) {
|
||||
mxn.lastStartTagToken = token;
|
||||
orig._appendElement.call(this, token, namespaceURI);
|
||||
},
|
||||
|
||||
_insertElement: function (token, namespaceURI) {
|
||||
mxn.lastStartTagToken = token;
|
||||
orig._insertElement.call(this, token, namespaceURI);
|
||||
},
|
||||
|
||||
_insertTemplate: function (token) {
|
||||
mxn.lastStartTagToken = token;
|
||||
orig._insertTemplate.call(this, token);
|
||||
|
||||
var tmplContent = this.treeAdapter.getTemplateContent(this.openElements.current);
|
||||
|
||||
tmplContent.__location = null;
|
||||
},
|
||||
|
||||
_insertFakeRootElement: function () {
|
||||
orig._insertFakeRootElement.call(this);
|
||||
this.openElements.current.__location = null;
|
||||
},
|
||||
|
||||
//Comments
|
||||
_appendCommentNode: function (token, parent) {
|
||||
orig._appendCommentNode.call(this, token, parent);
|
||||
|
||||
var children = this.treeAdapter.getChildNodes(parent),
|
||||
commentNode = children[children.length - 1];
|
||||
|
||||
commentNode.__location = token.location;
|
||||
},
|
||||
|
||||
//Text
|
||||
_findFosterParentingLocation: function () {
|
||||
//NOTE: store last foster parenting location, so we will be able to find inserted text
|
||||
//in case of foster parenting
|
||||
mxn.lastFosterParentingLocation = orig._findFosterParentingLocation.call(this);
|
||||
|
||||
return mxn.lastFosterParentingLocation;
|
||||
},
|
||||
|
||||
_insertCharacters: function (token) {
|
||||
orig._insertCharacters.call(this, token);
|
||||
|
||||
var hasFosterParent = this._shouldFosterParentOnInsertion(),
|
||||
parent = hasFosterParent && mxn.lastFosterParentingLocation.parent ||
|
||||
this.openElements.currentTmplContent ||
|
||||
this.openElements.current,
|
||||
siblings = this.treeAdapter.getChildNodes(parent),
|
||||
textNodeIdx = hasFosterParent && mxn.lastFosterParentingLocation.beforeElement ?
|
||||
siblings.indexOf(mxn.lastFosterParentingLocation.beforeElement) - 1 :
|
||||
siblings.length - 1,
|
||||
textNode = siblings[textNodeIdx];
|
||||
|
||||
//NOTE: if we have location assigned by another token, then just update end position
|
||||
if (textNode.__location)
|
||||
textNode.__location.endOffset = token.location.endOffset;
|
||||
|
||||
else
|
||||
textNode.__location = token.location;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
117
node_modules/cheerio/node_modules/parse5/lib/extensions/location_info/tokenizer_mixin.js
generated
vendored
Normal file
117
node_modules/cheerio/node_modules/parse5/lib/extensions/location_info/tokenizer_mixin.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
'use strict';
|
||||
|
||||
var Mixin = require('../../utils/mixin'),
|
||||
Tokenizer = require('../../tokenizer'),
|
||||
PositionTrackingPreprocessorMixin = require('../position_tracking/preprocessor_mixin'),
|
||||
inherits = require('util').inherits;
|
||||
|
||||
var LocationInfoTokenizerMixin = module.exports = function (tokenizer) {
|
||||
Mixin.call(this, tokenizer);
|
||||
|
||||
this.tokenizer = tokenizer;
|
||||
this.posTracker = new PositionTrackingPreprocessorMixin(tokenizer.preprocessor);
|
||||
this.currentAttrLocation = null;
|
||||
this.currentTokenLocation = null;
|
||||
};
|
||||
|
||||
inherits(LocationInfoTokenizerMixin, Mixin);
|
||||
|
||||
LocationInfoTokenizerMixin.prototype._getCurrentLocation = function () {
|
||||
return {
|
||||
line: this.posTracker.line,
|
||||
col: this.posTracker.col,
|
||||
startOffset: this.posTracker.offset,
|
||||
endOffset: -1
|
||||
};
|
||||
};
|
||||
|
||||
LocationInfoTokenizerMixin.prototype._attachCurrentAttrLocationInfo = function () {
|
||||
this.currentAttrLocation.endOffset = this.posTracker.offset;
|
||||
|
||||
var currentToken = this.tokenizer.currentToken,
|
||||
currentAttr = this.tokenizer.currentAttr;
|
||||
|
||||
if (!currentToken.location.attrs)
|
||||
currentToken.location.attrs = Object.create(null);
|
||||
|
||||
currentToken.location.attrs[currentAttr.name] = this.currentAttrLocation;
|
||||
};
|
||||
|
||||
LocationInfoTokenizerMixin.prototype._getOverriddenMethods = function (mxn, orig) {
|
||||
var methods = {
|
||||
_createStartTagToken: function () {
|
||||
orig._createStartTagToken.call(this);
|
||||
this.currentToken.location = mxn.currentTokenLocation;
|
||||
},
|
||||
|
||||
_createEndTagToken: function () {
|
||||
orig._createEndTagToken.call(this);
|
||||
this.currentToken.location = mxn.currentTokenLocation;
|
||||
},
|
||||
|
||||
_createCommentToken: function () {
|
||||
orig._createCommentToken.call(this);
|
||||
this.currentToken.location = mxn.currentTokenLocation;
|
||||
},
|
||||
|
||||
_createDoctypeToken: function (initialName) {
|
||||
orig._createDoctypeToken.call(this, initialName);
|
||||
this.currentToken.location = mxn.currentTokenLocation;
|
||||
},
|
||||
|
||||
_createCharacterToken: function (type, ch) {
|
||||
orig._createCharacterToken.call(this, type, ch);
|
||||
this.currentCharacterToken.location = mxn.currentTokenLocation;
|
||||
},
|
||||
|
||||
_createAttr: function (attrNameFirstCh) {
|
||||
orig._createAttr.call(this, attrNameFirstCh);
|
||||
mxn.currentAttrLocation = mxn._getCurrentLocation();
|
||||
},
|
||||
|
||||
_leaveAttrName: function (toState) {
|
||||
orig._leaveAttrName.call(this, toState);
|
||||
mxn._attachCurrentAttrLocationInfo();
|
||||
},
|
||||
|
||||
_leaveAttrValue: function (toState) {
|
||||
orig._leaveAttrValue.call(this, toState);
|
||||
mxn._attachCurrentAttrLocationInfo();
|
||||
},
|
||||
|
||||
_emitCurrentToken: function () {
|
||||
//NOTE: if we have pending character token make it's end location equal to the
|
||||
//current token's start location.
|
||||
if (this.currentCharacterToken)
|
||||
this.currentCharacterToken.location.endOffset = this.currentToken.location.startOffset;
|
||||
|
||||
this.currentToken.location.endOffset = mxn.posTracker.offset + 1;
|
||||
orig._emitCurrentToken.call(this);
|
||||
},
|
||||
|
||||
_emitCurrentCharacterToken: function () {
|
||||
//NOTE: if we have character token and it's location wasn't set in the _emitCurrentToken(),
|
||||
//then set it's location at the current preprocessor position.
|
||||
//We don't need to increment preprocessor position, since character token
|
||||
//emission is always forced by the start of the next character token here.
|
||||
//So, we already have advanced position.
|
||||
if (this.currentCharacterToken && this.currentCharacterToken.location.endOffset === -1)
|
||||
this.currentCharacterToken.location.endOffset = mxn.posTracker.offset;
|
||||
|
||||
orig._emitCurrentCharacterToken.call(this);
|
||||
}
|
||||
};
|
||||
|
||||
//NOTE: patch initial states for each mode to obtain token start position
|
||||
Object.keys(Tokenizer.MODE).forEach(function (modeName) {
|
||||
var state = Tokenizer.MODE[modeName];
|
||||
|
||||
methods[state] = function (cp) {
|
||||
mxn.currentTokenLocation = mxn._getCurrentLocation();
|
||||
orig[state].call(this, cp);
|
||||
};
|
||||
});
|
||||
|
||||
return methods;
|
||||
};
|
||||
|
||||
72
node_modules/cheerio/node_modules/parse5/lib/extensions/position_tracking/preprocessor_mixin.js
generated
vendored
Normal file
72
node_modules/cheerio/node_modules/parse5/lib/extensions/position_tracking/preprocessor_mixin.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var Mixin = require('../../utils/mixin'),
|
||||
inherits = require('util').inherits,
|
||||
UNICODE = require('../../common/unicode');
|
||||
|
||||
//Aliases
|
||||
var $ = UNICODE.CODE_POINTS;
|
||||
|
||||
var PositionTrackingPreprocessorMixin = module.exports = function (preprocessor) {
|
||||
// NOTE: avoid installing tracker twice
|
||||
if (!preprocessor.__locTracker) {
|
||||
preprocessor.__locTracker = this;
|
||||
|
||||
Mixin.call(this, preprocessor);
|
||||
|
||||
this.preprocessor = preprocessor;
|
||||
this.isEol = false;
|
||||
this.lineStartPos = 0;
|
||||
this.droppedBufferSize = 0;
|
||||
|
||||
this.col = -1;
|
||||
this.line = 1;
|
||||
}
|
||||
|
||||
return preprocessor.__locTracker;
|
||||
};
|
||||
|
||||
inherits(PositionTrackingPreprocessorMixin, Mixin);
|
||||
|
||||
Object.defineProperty(PositionTrackingPreprocessorMixin.prototype, 'offset', {
|
||||
get: function () {
|
||||
return this.droppedBufferSize + this.preprocessor.pos;
|
||||
}
|
||||
});
|
||||
|
||||
PositionTrackingPreprocessorMixin.prototype._getOverriddenMethods = function (mxn, orig) {
|
||||
return {
|
||||
advance: function () {
|
||||
var cp = orig.advance.call(this);
|
||||
|
||||
//NOTE: LF should be in the last column of the line
|
||||
if (mxn.isEol) {
|
||||
mxn.isEol = false;
|
||||
mxn.line++;
|
||||
mxn.lineStartPos = mxn.offset;
|
||||
}
|
||||
|
||||
if (cp === $.LINE_FEED)
|
||||
mxn.isEol = true;
|
||||
|
||||
mxn.col = mxn.offset - mxn.lineStartPos + 1;
|
||||
|
||||
return cp;
|
||||
},
|
||||
|
||||
retreat: function () {
|
||||
orig.retreat.call(this);
|
||||
mxn.isEol = false;
|
||||
|
||||
mxn.col = mxn.offset - mxn.lineStartPos + 1;
|
||||
},
|
||||
|
||||
dropParsedChunk: function () {
|
||||
var prevPos = this.pos;
|
||||
|
||||
orig.dropParsedChunk.call(this);
|
||||
|
||||
mxn.droppedBufferSize += prevPos - this.pos;
|
||||
}
|
||||
};
|
||||
};
|
||||
1077
node_modules/cheerio/node_modules/parse5/lib/index.d.ts
generated
vendored
Normal file
1077
node_modules/cheerio/node_modules/parse5/lib/index.d.ts
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
44
node_modules/cheerio/node_modules/parse5/lib/index.js
generated
vendored
Normal file
44
node_modules/cheerio/node_modules/parse5/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
var Parser = require('./parser'),
|
||||
Serializer = require('./serializer');
|
||||
|
||||
|
||||
// Shorthands
|
||||
exports.parse = function parse(html, options) {
|
||||
var parser = new Parser(options);
|
||||
|
||||
return parser.parse(html);
|
||||
};
|
||||
|
||||
exports.parseFragment = function parseFragment(fragmentContext, html, options) {
|
||||
if (typeof fragmentContext === 'string') {
|
||||
options = html;
|
||||
html = fragmentContext;
|
||||
fragmentContext = null;
|
||||
}
|
||||
|
||||
var parser = new Parser(options);
|
||||
|
||||
return parser.parseFragment(html, fragmentContext);
|
||||
};
|
||||
|
||||
exports.serialize = function (node, options) {
|
||||
var serializer = new Serializer(node, options);
|
||||
|
||||
return serializer.serialize();
|
||||
};
|
||||
|
||||
|
||||
// Tree adapters
|
||||
exports.treeAdapters = {
|
||||
default: require('./tree_adapters/default'),
|
||||
htmlparser2: require('./tree_adapters/htmlparser2')
|
||||
};
|
||||
|
||||
|
||||
// Streaming
|
||||
exports.ParserStream = require('./parser/parser_stream');
|
||||
exports.PlainTextConversionStream = require('./parser/plain_text_conversion_stream');
|
||||
exports.SerializerStream = require('./serializer/serializer_stream');
|
||||
exports.SAXParser = require('./sax');
|
||||
167
node_modules/cheerio/node_modules/parse5/lib/parser/formatting_element_list.js
generated
vendored
Normal file
167
node_modules/cheerio/node_modules/parse5/lib/parser/formatting_element_list.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
'use strict';
|
||||
|
||||
//Const
|
||||
var NOAH_ARK_CAPACITY = 3;
|
||||
|
||||
//List of formatting elements
|
||||
var FormattingElementList = module.exports = function (treeAdapter) {
|
||||
this.length = 0;
|
||||
this.entries = [];
|
||||
this.treeAdapter = treeAdapter;
|
||||
this.bookmark = null;
|
||||
};
|
||||
|
||||
//Entry types
|
||||
FormattingElementList.MARKER_ENTRY = 'MARKER_ENTRY';
|
||||
FormattingElementList.ELEMENT_ENTRY = 'ELEMENT_ENTRY';
|
||||
|
||||
//Noah Ark's condition
|
||||
//OPTIMIZATION: at first we try to find possible candidates for exclusion using
|
||||
//lightweight heuristics without thorough attributes check.
|
||||
FormattingElementList.prototype._getNoahArkConditionCandidates = function (newElement) {
|
||||
var candidates = [];
|
||||
|
||||
if (this.length >= NOAH_ARK_CAPACITY) {
|
||||
var neAttrsLength = this.treeAdapter.getAttrList(newElement).length,
|
||||
neTagName = this.treeAdapter.getTagName(newElement),
|
||||
neNamespaceURI = this.treeAdapter.getNamespaceURI(newElement);
|
||||
|
||||
for (var i = this.length - 1; i >= 0; i--) {
|
||||
var entry = this.entries[i];
|
||||
|
||||
if (entry.type === FormattingElementList.MARKER_ENTRY)
|
||||
break;
|
||||
|
||||
var element = entry.element,
|
||||
elementAttrs = this.treeAdapter.getAttrList(element),
|
||||
isCandidate = this.treeAdapter.getTagName(element) === neTagName &&
|
||||
this.treeAdapter.getNamespaceURI(element) === neNamespaceURI &&
|
||||
elementAttrs.length === neAttrsLength;
|
||||
|
||||
if (isCandidate)
|
||||
candidates.push({idx: i, attrs: elementAttrs});
|
||||
}
|
||||
}
|
||||
|
||||
return candidates.length < NOAH_ARK_CAPACITY ? [] : candidates;
|
||||
};
|
||||
|
||||
FormattingElementList.prototype._ensureNoahArkCondition = function (newElement) {
|
||||
var candidates = this._getNoahArkConditionCandidates(newElement),
|
||||
cLength = candidates.length;
|
||||
|
||||
if (cLength) {
|
||||
var neAttrs = this.treeAdapter.getAttrList(newElement),
|
||||
neAttrsLength = neAttrs.length,
|
||||
neAttrsMap = Object.create(null);
|
||||
|
||||
//NOTE: build attrs map for the new element so we can perform fast lookups
|
||||
for (var i = 0; i < neAttrsLength; i++) {
|
||||
var neAttr = neAttrs[i];
|
||||
|
||||
neAttrsMap[neAttr.name] = neAttr.value;
|
||||
}
|
||||
|
||||
for (i = 0; i < neAttrsLength; i++) {
|
||||
for (var j = 0; j < cLength; j++) {
|
||||
var cAttr = candidates[j].attrs[i];
|
||||
|
||||
if (neAttrsMap[cAttr.name] !== cAttr.value) {
|
||||
candidates.splice(j, 1);
|
||||
cLength--;
|
||||
}
|
||||
|
||||
if (candidates.length < NOAH_ARK_CAPACITY)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//NOTE: remove bottommost candidates until Noah's Ark condition will not be met
|
||||
for (i = cLength - 1; i >= NOAH_ARK_CAPACITY - 1; i--) {
|
||||
this.entries.splice(candidates[i].idx, 1);
|
||||
this.length--;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Mutations
|
||||
FormattingElementList.prototype.insertMarker = function () {
|
||||
this.entries.push({type: FormattingElementList.MARKER_ENTRY});
|
||||
this.length++;
|
||||
};
|
||||
|
||||
FormattingElementList.prototype.pushElement = function (element, token) {
|
||||
this._ensureNoahArkCondition(element);
|
||||
|
||||
this.entries.push({
|
||||
type: FormattingElementList.ELEMENT_ENTRY,
|
||||
element: element,
|
||||
token: token
|
||||
});
|
||||
|
||||
this.length++;
|
||||
};
|
||||
|
||||
FormattingElementList.prototype.insertElementAfterBookmark = function (element, token) {
|
||||
var bookmarkIdx = this.length - 1;
|
||||
|
||||
for (; bookmarkIdx >= 0; bookmarkIdx--) {
|
||||
if (this.entries[bookmarkIdx] === this.bookmark)
|
||||
break;
|
||||
}
|
||||
|
||||
this.entries.splice(bookmarkIdx + 1, 0, {
|
||||
type: FormattingElementList.ELEMENT_ENTRY,
|
||||
element: element,
|
||||
token: token
|
||||
});
|
||||
|
||||
this.length++;
|
||||
};
|
||||
|
||||
FormattingElementList.prototype.removeEntry = function (entry) {
|
||||
for (var i = this.length - 1; i >= 0; i--) {
|
||||
if (this.entries[i] === entry) {
|
||||
this.entries.splice(i, 1);
|
||||
this.length--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
FormattingElementList.prototype.clearToLastMarker = function () {
|
||||
while (this.length) {
|
||||
var entry = this.entries.pop();
|
||||
|
||||
this.length--;
|
||||
|
||||
if (entry.type === FormattingElementList.MARKER_ENTRY)
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
//Search
|
||||
FormattingElementList.prototype.getElementEntryInScopeWithTagName = function (tagName) {
|
||||
for (var i = this.length - 1; i >= 0; i--) {
|
||||
var entry = this.entries[i];
|
||||
|
||||
if (entry.type === FormattingElementList.MARKER_ENTRY)
|
||||
return null;
|
||||
|
||||
if (this.treeAdapter.getTagName(entry.element) === tagName)
|
||||
return entry;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
FormattingElementList.prototype.getElementEntry = function (element) {
|
||||
for (var i = this.length - 1; i >= 0; i--) {
|
||||
var entry = this.entries[i];
|
||||
|
||||
if (entry.type === FormattingElementList.ELEMENT_ENTRY && entry.element === element)
|
||||
return entry;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
2819
node_modules/cheerio/node_modules/parse5/lib/parser/index.js
generated
vendored
Normal file
2819
node_modules/cheerio/node_modules/parse5/lib/parser/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
395
node_modules/cheerio/node_modules/parse5/lib/parser/open_element_stack.js
generated
vendored
Normal file
395
node_modules/cheerio/node_modules/parse5/lib/parser/open_element_stack.js
generated
vendored
Normal file
@@ -0,0 +1,395 @@
|
||||
'use strict';
|
||||
|
||||
var HTML = require('../common/html');
|
||||
|
||||
//Aliases
|
||||
var $ = HTML.TAG_NAMES,
|
||||
NS = HTML.NAMESPACES;
|
||||
|
||||
//Element utils
|
||||
|
||||
//OPTIMIZATION: Integer comparisons are low-cost, so we can use very fast tag name length filters here.
|
||||
//It's faster than using dictionary.
|
||||
function isImpliedEndTagRequired(tn) {
|
||||
switch (tn.length) {
|
||||
case 1:
|
||||
return tn === $.P;
|
||||
|
||||
case 2:
|
||||
return tn === $.RB || tn === $.RP || tn === $.RT || tn === $.DD || tn === $.DT || tn === $.LI;
|
||||
|
||||
case 3:
|
||||
return tn === $.RTC;
|
||||
|
||||
case 6:
|
||||
return tn === $.OPTION;
|
||||
|
||||
case 8:
|
||||
return tn === $.OPTGROUP || tn === $.MENUITEM;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isScopingElement(tn, ns) {
|
||||
switch (tn.length) {
|
||||
case 2:
|
||||
if (tn === $.TD || tn === $.TH)
|
||||
return ns === NS.HTML;
|
||||
|
||||
else if (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS)
|
||||
return ns === NS.MATHML;
|
||||
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if (tn === $.HTML)
|
||||
return ns === NS.HTML;
|
||||
|
||||
else if (tn === $.DESC)
|
||||
return ns === NS.SVG;
|
||||
|
||||
break;
|
||||
|
||||
case 5:
|
||||
if (tn === $.TABLE)
|
||||
return ns === NS.HTML;
|
||||
|
||||
else if (tn === $.MTEXT)
|
||||
return ns === NS.MATHML;
|
||||
|
||||
else if (tn === $.TITLE)
|
||||
return ns === NS.SVG;
|
||||
|
||||
break;
|
||||
|
||||
case 6:
|
||||
return (tn === $.APPLET || tn === $.OBJECT) && ns === NS.HTML;
|
||||
|
||||
case 7:
|
||||
return (tn === $.CAPTION || tn === $.MARQUEE) && ns === NS.HTML;
|
||||
|
||||
case 8:
|
||||
return tn === $.TEMPLATE && ns === NS.HTML;
|
||||
|
||||
case 13:
|
||||
return tn === $.FOREIGN_OBJECT && ns === NS.SVG;
|
||||
|
||||
case 14:
|
||||
return tn === $.ANNOTATION_XML && ns === NS.MATHML;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//Stack of open elements
|
||||
var OpenElementStack = module.exports = function (document, treeAdapter) {
|
||||
this.stackTop = -1;
|
||||
this.items = [];
|
||||
this.current = document;
|
||||
this.currentTagName = null;
|
||||
this.currentTmplContent = null;
|
||||
this.tmplCount = 0;
|
||||
this.treeAdapter = treeAdapter;
|
||||
};
|
||||
|
||||
//Index of element
|
||||
OpenElementStack.prototype._indexOf = function (element) {
|
||||
var idx = -1;
|
||||
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
if (this.items[i] === element) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
};
|
||||
|
||||
//Update current element
|
||||
OpenElementStack.prototype._isInTemplate = function () {
|
||||
return this.currentTagName === $.TEMPLATE && this.treeAdapter.getNamespaceURI(this.current) === NS.HTML;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype._updateCurrentElement = function () {
|
||||
this.current = this.items[this.stackTop];
|
||||
this.currentTagName = this.current && this.treeAdapter.getTagName(this.current);
|
||||
|
||||
this.currentTmplContent = this._isInTemplate() ? this.treeAdapter.getTemplateContent(this.current) : null;
|
||||
};
|
||||
|
||||
//Mutations
|
||||
OpenElementStack.prototype.push = function (element) {
|
||||
this.items[++this.stackTop] = element;
|
||||
this._updateCurrentElement();
|
||||
|
||||
if (this._isInTemplate())
|
||||
this.tmplCount++;
|
||||
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.pop = function () {
|
||||
this.stackTop--;
|
||||
|
||||
if (this.tmplCount > 0 && this._isInTemplate())
|
||||
this.tmplCount--;
|
||||
|
||||
this._updateCurrentElement();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.replace = function (oldElement, newElement) {
|
||||
var idx = this._indexOf(oldElement);
|
||||
|
||||
this.items[idx] = newElement;
|
||||
|
||||
if (idx === this.stackTop)
|
||||
this._updateCurrentElement();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.insertAfter = function (referenceElement, newElement) {
|
||||
var insertionIdx = this._indexOf(referenceElement) + 1;
|
||||
|
||||
this.items.splice(insertionIdx, 0, newElement);
|
||||
|
||||
if (insertionIdx === ++this.stackTop)
|
||||
this._updateCurrentElement();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.popUntilTagNamePopped = function (tagName) {
|
||||
while (this.stackTop > -1) {
|
||||
var tn = this.currentTagName,
|
||||
ns = this.treeAdapter.getNamespaceURI(this.current);
|
||||
|
||||
this.pop();
|
||||
|
||||
if (tn === tagName && ns === NS.HTML)
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.popUntilElementPopped = function (element) {
|
||||
while (this.stackTop > -1) {
|
||||
var poppedElement = this.current;
|
||||
|
||||
this.pop();
|
||||
|
||||
if (poppedElement === element)
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.popUntilNumberedHeaderPopped = function () {
|
||||
while (this.stackTop > -1) {
|
||||
var tn = this.currentTagName,
|
||||
ns = this.treeAdapter.getNamespaceURI(this.current);
|
||||
|
||||
this.pop();
|
||||
|
||||
if (tn === $.H1 || tn === $.H2 || tn === $.H3 || tn === $.H4 || tn === $.H5 || tn === $.H6 && ns === NS.HTML)
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.popUntilTableCellPopped = function () {
|
||||
while (this.stackTop > -1) {
|
||||
var tn = this.currentTagName,
|
||||
ns = this.treeAdapter.getNamespaceURI(this.current);
|
||||
|
||||
this.pop();
|
||||
|
||||
if (tn === $.TD || tn === $.TH && ns === NS.HTML)
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.popAllUpToHtmlElement = function () {
|
||||
//NOTE: here we assume that root <html> element is always first in the open element stack, so
|
||||
//we perform this fast stack clean up.
|
||||
this.stackTop = 0;
|
||||
this._updateCurrentElement();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.clearBackToTableContext = function () {
|
||||
while (this.currentTagName !== $.TABLE &&
|
||||
this.currentTagName !== $.TEMPLATE &&
|
||||
this.currentTagName !== $.HTML ||
|
||||
this.treeAdapter.getNamespaceURI(this.current) !== NS.HTML)
|
||||
this.pop();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.clearBackToTableBodyContext = function () {
|
||||
while (this.currentTagName !== $.TBODY &&
|
||||
this.currentTagName !== $.TFOOT &&
|
||||
this.currentTagName !== $.THEAD &&
|
||||
this.currentTagName !== $.TEMPLATE &&
|
||||
this.currentTagName !== $.HTML ||
|
||||
this.treeAdapter.getNamespaceURI(this.current) !== NS.HTML)
|
||||
this.pop();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.clearBackToTableRowContext = function () {
|
||||
while (this.currentTagName !== $.TR &&
|
||||
this.currentTagName !== $.TEMPLATE &&
|
||||
this.currentTagName !== $.HTML ||
|
||||
this.treeAdapter.getNamespaceURI(this.current) !== NS.HTML)
|
||||
this.pop();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.remove = function (element) {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
if (this.items[i] === element) {
|
||||
this.items.splice(i, 1);
|
||||
this.stackTop--;
|
||||
this._updateCurrentElement();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//Search
|
||||
OpenElementStack.prototype.tryPeekProperlyNestedBodyElement = function () {
|
||||
//Properly nested <body> element (should be second element in stack).
|
||||
var element = this.items[1];
|
||||
|
||||
return element && this.treeAdapter.getTagName(element) === $.BODY ? element : null;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.contains = function (element) {
|
||||
return this._indexOf(element) > -1;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.getCommonAncestor = function (element) {
|
||||
var elementIdx = this._indexOf(element);
|
||||
|
||||
return --elementIdx >= 0 ? this.items[elementIdx] : null;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.isRootHtmlElementCurrent = function () {
|
||||
return this.stackTop === 0 && this.currentTagName === $.HTML;
|
||||
};
|
||||
|
||||
//Element in scope
|
||||
OpenElementStack.prototype.hasInScope = function (tagName) {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
var tn = this.treeAdapter.getTagName(this.items[i]),
|
||||
ns = this.treeAdapter.getNamespaceURI(this.items[i]);
|
||||
|
||||
if (tn === tagName && ns === NS.HTML)
|
||||
return true;
|
||||
|
||||
if (isScopingElement(tn, ns))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.hasNumberedHeaderInScope = function () {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
var tn = this.treeAdapter.getTagName(this.items[i]),
|
||||
ns = this.treeAdapter.getNamespaceURI(this.items[i]);
|
||||
|
||||
if ((tn === $.H1 || tn === $.H2 || tn === $.H3 || tn === $.H4 || tn === $.H5 || tn === $.H6) && ns === NS.HTML)
|
||||
return true;
|
||||
|
||||
if (isScopingElement(tn, ns))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.hasInListItemScope = function (tagName) {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
var tn = this.treeAdapter.getTagName(this.items[i]),
|
||||
ns = this.treeAdapter.getNamespaceURI(this.items[i]);
|
||||
|
||||
if (tn === tagName && ns === NS.HTML)
|
||||
return true;
|
||||
|
||||
if ((tn === $.UL || tn === $.OL) && ns === NS.HTML || isScopingElement(tn, ns))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.hasInButtonScope = function (tagName) {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
var tn = this.treeAdapter.getTagName(this.items[i]),
|
||||
ns = this.treeAdapter.getNamespaceURI(this.items[i]);
|
||||
|
||||
if (tn === tagName && ns === NS.HTML)
|
||||
return true;
|
||||
|
||||
if (tn === $.BUTTON && ns === NS.HTML || isScopingElement(tn, ns))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.hasInTableScope = function (tagName) {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
var tn = this.treeAdapter.getTagName(this.items[i]),
|
||||
ns = this.treeAdapter.getNamespaceURI(this.items[i]);
|
||||
|
||||
if (ns !== NS.HTML)
|
||||
continue;
|
||||
|
||||
if (tn === tagName)
|
||||
return true;
|
||||
|
||||
if (tn === $.TABLE || tn === $.TEMPLATE || tn === $.HTML)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.hasTableBodyContextInTableScope = function () {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
var tn = this.treeAdapter.getTagName(this.items[i]),
|
||||
ns = this.treeAdapter.getNamespaceURI(this.items[i]);
|
||||
|
||||
if (ns !== NS.HTML)
|
||||
continue;
|
||||
|
||||
if (tn === $.TBODY || tn === $.THEAD || tn === $.TFOOT)
|
||||
return true;
|
||||
|
||||
if (tn === $.TABLE || tn === $.HTML)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.hasInSelectScope = function (tagName) {
|
||||
for (var i = this.stackTop; i >= 0; i--) {
|
||||
var tn = this.treeAdapter.getTagName(this.items[i]),
|
||||
ns = this.treeAdapter.getNamespaceURI(this.items[i]);
|
||||
|
||||
if (ns !== NS.HTML)
|
||||
continue;
|
||||
|
||||
if (tn === tagName)
|
||||
return true;
|
||||
|
||||
if (tn !== $.OPTION && tn !== $.OPTGROUP)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
//Implied end tags
|
||||
OpenElementStack.prototype.generateImpliedEndTags = function () {
|
||||
while (isImpliedEndTagRequired(this.currentTagName))
|
||||
this.pop();
|
||||
};
|
||||
|
||||
OpenElementStack.prototype.generateImpliedEndTagsWithExclusion = function (exclusionTagName) {
|
||||
while (isImpliedEndTagRequired(this.currentTagName) && this.currentTagName !== exclusionTagName)
|
||||
this.pop();
|
||||
};
|
||||
76
node_modules/cheerio/node_modules/parse5/lib/parser/parser_stream.js
generated
vendored
Normal file
76
node_modules/cheerio/node_modules/parse5/lib/parser/parser_stream.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
'use strict';
|
||||
|
||||
var WritableStream = require('stream').Writable,
|
||||
inherits = require('util').inherits,
|
||||
Parser = require('./index');
|
||||
|
||||
var ParserStream = module.exports = function (options) {
|
||||
WritableStream.call(this);
|
||||
|
||||
this.parser = new Parser(options);
|
||||
|
||||
this.lastChunkWritten = false;
|
||||
this.writeCallback = null;
|
||||
this.pausedByScript = false;
|
||||
|
||||
this.document = this.parser.treeAdapter.createDocument();
|
||||
|
||||
this.pendingHtmlInsertions = [];
|
||||
|
||||
this._resume = this._resume.bind(this);
|
||||
this._documentWrite = this._documentWrite.bind(this);
|
||||
this._scriptHandler = this._scriptHandler.bind(this);
|
||||
|
||||
this.parser._bootstrap(this.document, null);
|
||||
};
|
||||
|
||||
inherits(ParserStream, WritableStream);
|
||||
|
||||
//WritableStream implementation
|
||||
ParserStream.prototype._write = function (chunk, encoding, callback) {
|
||||
this.writeCallback = callback;
|
||||
this.parser.tokenizer.write(chunk.toString('utf8'), this.lastChunkWritten);
|
||||
this._runParsingLoop();
|
||||
};
|
||||
|
||||
ParserStream.prototype.end = function (chunk, encoding, callback) {
|
||||
this.lastChunkWritten = true;
|
||||
WritableStream.prototype.end.call(this, chunk || '', encoding, callback);
|
||||
};
|
||||
|
||||
//Scriptable parser implementation
|
||||
ParserStream.prototype._runParsingLoop = function () {
|
||||
this.parser.runParsingLoopForCurrentChunk(this.writeCallback, this._scriptHandler);
|
||||
};
|
||||
|
||||
ParserStream.prototype._resume = function () {
|
||||
if (!this.pausedByScript)
|
||||
throw new Error('Parser was already resumed');
|
||||
|
||||
while (this.pendingHtmlInsertions.length) {
|
||||
var html = this.pendingHtmlInsertions.pop();
|
||||
|
||||
this.parser.tokenizer.insertHtmlAtCurrentPos(html);
|
||||
}
|
||||
|
||||
this.pausedByScript = false;
|
||||
|
||||
//NOTE: keep parsing if we don't wait for the next input chunk
|
||||
if (this.parser.tokenizer.active)
|
||||
this._runParsingLoop();
|
||||
};
|
||||
|
||||
ParserStream.prototype._documentWrite = function (html) {
|
||||
if (!this.parser.stopped)
|
||||
this.pendingHtmlInsertions.push(html);
|
||||
};
|
||||
|
||||
ParserStream.prototype._scriptHandler = function (scriptElement) {
|
||||
if (this.listeners('script').length) {
|
||||
this.pausedByScript = true;
|
||||
this.emit('script', scriptElement, this._documentWrite, this._resume);
|
||||
}
|
||||
else
|
||||
this._runParsingLoop();
|
||||
};
|
||||
|
||||
20
node_modules/cheerio/node_modules/parse5/lib/parser/plain_text_conversion_stream.js
generated
vendored
Normal file
20
node_modules/cheerio/node_modules/parse5/lib/parser/plain_text_conversion_stream.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var ParserStream = require('./parser_stream'),
|
||||
inherits = require('util').inherits,
|
||||
$ = require('../common/html').TAG_NAMES;
|
||||
|
||||
var PlainTextConversionStream = module.exports = function (options) {
|
||||
ParserStream.call(this, options);
|
||||
|
||||
// NOTE: see https://html.spec.whatwg.org/#read-text
|
||||
this.parser._insertFakeElement($.HTML);
|
||||
this.parser._insertFakeElement($.HEAD);
|
||||
this.parser.openElements.pop();
|
||||
this.parser._insertFakeElement($.BODY);
|
||||
this.parser._insertFakeElement($.PRE);
|
||||
this.parser.treeAdapter.insertText(this.parser.openElements.current, '\n');
|
||||
this.parser.switchToPlaintextParsing();
|
||||
};
|
||||
|
||||
inherits(PlainTextConversionStream, ParserStream);
|
||||
14
node_modules/cheerio/node_modules/parse5/lib/sax/dev_null_stream.js
generated
vendored
Normal file
14
node_modules/cheerio/node_modules/parse5/lib/sax/dev_null_stream.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var WritableStream = require('stream').Writable,
|
||||
util = require('util');
|
||||
|
||||
var DevNullStream = module.exports = function () {
|
||||
WritableStream.call(this);
|
||||
};
|
||||
|
||||
util.inherits(DevNullStream, WritableStream);
|
||||
|
||||
DevNullStream.prototype._write = function (chunk, encoding, cb) {
|
||||
cb();
|
||||
};
|
||||
118
node_modules/cheerio/node_modules/parse5/lib/sax/index.js
generated
vendored
Normal file
118
node_modules/cheerio/node_modules/parse5/lib/sax/index.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
'use strict';
|
||||
|
||||
var TransformStream = require('stream').Transform,
|
||||
DevNullStream = require('./dev_null_stream'),
|
||||
inherits = require('util').inherits,
|
||||
Tokenizer = require('../tokenizer'),
|
||||
LocationInfoTokenizerMixin = require('../extensions/location_info/tokenizer_mixin'),
|
||||
ParserFeedbackSimulator = require('./parser_feedback_simulator'),
|
||||
mergeOptions = require('../utils/merge_options');
|
||||
|
||||
var DEFAULT_OPTIONS = {
|
||||
locationInfo: false
|
||||
};
|
||||
|
||||
var SAXParser = module.exports = function (options) {
|
||||
TransformStream.call(this);
|
||||
|
||||
this.options = mergeOptions(DEFAULT_OPTIONS, options);
|
||||
|
||||
this.tokenizer = new Tokenizer(options);
|
||||
|
||||
if (this.options.locationInfo)
|
||||
new LocationInfoTokenizerMixin(this.tokenizer);
|
||||
|
||||
this.parserFeedbackSimulator = new ParserFeedbackSimulator(this.tokenizer);
|
||||
|
||||
this.pendingText = null;
|
||||
this.currentTokenLocation = void 0;
|
||||
|
||||
this.lastChunkWritten = false;
|
||||
this.stopped = false;
|
||||
|
||||
// NOTE: always pipe stream to the /dev/null stream to avoid
|
||||
// `highWaterMark` hit even if we don't have consumers.
|
||||
// (see: https://github.com/inikulin/parse5/issues/97#issuecomment-171940774)
|
||||
this.pipe(new DevNullStream());
|
||||
};
|
||||
|
||||
inherits(SAXParser, TransformStream);
|
||||
|
||||
//TransformStream implementation
|
||||
SAXParser.prototype._transform = function (chunk, encoding, callback) {
|
||||
if (!this.stopped) {
|
||||
this.tokenizer.write(chunk.toString('utf8'), this.lastChunkWritten);
|
||||
this._runParsingLoop();
|
||||
}
|
||||
|
||||
this.push(chunk);
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
SAXParser.prototype._flush = function (callback) {
|
||||
callback();
|
||||
};
|
||||
|
||||
SAXParser.prototype.end = function (chunk, encoding, callback) {
|
||||
this.lastChunkWritten = true;
|
||||
TransformStream.prototype.end.call(this, chunk, encoding, callback);
|
||||
};
|
||||
|
||||
SAXParser.prototype.stop = function () {
|
||||
this.stopped = true;
|
||||
};
|
||||
|
||||
//Internals
|
||||
SAXParser.prototype._runParsingLoop = function () {
|
||||
do {
|
||||
var token = this.parserFeedbackSimulator.getNextToken();
|
||||
|
||||
if (token.type === Tokenizer.HIBERNATION_TOKEN)
|
||||
break;
|
||||
|
||||
if (token.type === Tokenizer.CHARACTER_TOKEN ||
|
||||
token.type === Tokenizer.WHITESPACE_CHARACTER_TOKEN ||
|
||||
token.type === Tokenizer.NULL_CHARACTER_TOKEN) {
|
||||
|
||||
if (this.options.locationInfo) {
|
||||
if (this.pendingText === null)
|
||||
this.currentTokenLocation = token.location;
|
||||
|
||||
else
|
||||
this.currentTokenLocation.endOffset = token.location.endOffset;
|
||||
}
|
||||
|
||||
this.pendingText = (this.pendingText || '') + token.chars;
|
||||
}
|
||||
|
||||
else {
|
||||
this._emitPendingText();
|
||||
this._handleToken(token);
|
||||
}
|
||||
} while (!this.stopped && token.type !== Tokenizer.EOF_TOKEN);
|
||||
};
|
||||
|
||||
SAXParser.prototype._handleToken = function (token) {
|
||||
if (this.options.locationInfo)
|
||||
this.currentTokenLocation = token.location;
|
||||
|
||||
if (token.type === Tokenizer.START_TAG_TOKEN)
|
||||
this.emit('startTag', token.tagName, token.attrs, token.selfClosing, this.currentTokenLocation);
|
||||
|
||||
else if (token.type === Tokenizer.END_TAG_TOKEN)
|
||||
this.emit('endTag', token.tagName, this.currentTokenLocation);
|
||||
|
||||
else if (token.type === Tokenizer.COMMENT_TOKEN)
|
||||
this.emit('comment', token.data, this.currentTokenLocation);
|
||||
|
||||
else if (token.type === Tokenizer.DOCTYPE_TOKEN)
|
||||
this.emit('doctype', token.name, token.publicId, token.systemId, this.currentTokenLocation);
|
||||
};
|
||||
|
||||
SAXParser.prototype._emitPendingText = function () {
|
||||
if (this.pendingText !== null) {
|
||||
this.emit('text', this.pendingText, this.currentTokenLocation);
|
||||
this.pendingText = null;
|
||||
}
|
||||
};
|
||||
153
node_modules/cheerio/node_modules/parse5/lib/sax/parser_feedback_simulator.js
generated
vendored
Normal file
153
node_modules/cheerio/node_modules/parse5/lib/sax/parser_feedback_simulator.js
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
'use strict';
|
||||
|
||||
var Tokenizer = require('../tokenizer'),
|
||||
foreignContent = require('../common/foreign_content'),
|
||||
UNICODE = require('../common/unicode'),
|
||||
HTML = require('../common/html');
|
||||
|
||||
|
||||
//Aliases
|
||||
var $ = HTML.TAG_NAMES,
|
||||
NS = HTML.NAMESPACES;
|
||||
|
||||
|
||||
//ParserFeedbackSimulator
|
||||
//Simulates adjustment of the Tokenizer which performed by standard parser during tree construction.
|
||||
var ParserFeedbackSimulator = module.exports = function (tokenizer) {
|
||||
this.tokenizer = tokenizer;
|
||||
|
||||
this.namespaceStack = [];
|
||||
this.namespaceStackTop = -1;
|
||||
this._enterNamespace(NS.HTML);
|
||||
};
|
||||
|
||||
ParserFeedbackSimulator.prototype.getNextToken = function () {
|
||||
var token = this.tokenizer.getNextToken();
|
||||
|
||||
if (token.type === Tokenizer.START_TAG_TOKEN)
|
||||
this._handleStartTagToken(token);
|
||||
|
||||
else if (token.type === Tokenizer.END_TAG_TOKEN)
|
||||
this._handleEndTagToken(token);
|
||||
|
||||
else if (token.type === Tokenizer.NULL_CHARACTER_TOKEN && this.inForeignContent) {
|
||||
token.type = Tokenizer.CHARACTER_TOKEN;
|
||||
token.chars = UNICODE.REPLACEMENT_CHARACTER;
|
||||
}
|
||||
|
||||
else if (this.skipNextNewLine) {
|
||||
if (token.type !== Tokenizer.HIBERNATION_TOKEN)
|
||||
this.skipNextNewLine = false;
|
||||
|
||||
if (token.type === Tokenizer.WHITESPACE_CHARACTER_TOKEN && token.chars[0] === '\n') {
|
||||
if (token.chars.length === 1)
|
||||
return this.getNextToken();
|
||||
|
||||
token.chars = token.chars.substr(1);
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
};
|
||||
|
||||
//Namespace stack mutations
|
||||
ParserFeedbackSimulator.prototype._enterNamespace = function (namespace) {
|
||||
this.namespaceStackTop++;
|
||||
this.namespaceStack.push(namespace);
|
||||
|
||||
this.inForeignContent = namespace !== NS.HTML;
|
||||
this.currentNamespace = namespace;
|
||||
this.tokenizer.allowCDATA = this.inForeignContent;
|
||||
};
|
||||
|
||||
ParserFeedbackSimulator.prototype._leaveCurrentNamespace = function () {
|
||||
this.namespaceStackTop--;
|
||||
this.namespaceStack.pop();
|
||||
|
||||
this.currentNamespace = this.namespaceStack[this.namespaceStackTop];
|
||||
this.inForeignContent = this.currentNamespace !== NS.HTML;
|
||||
this.tokenizer.allowCDATA = this.inForeignContent;
|
||||
};
|
||||
|
||||
//Token handlers
|
||||
ParserFeedbackSimulator.prototype._ensureTokenizerMode = function (tn) {
|
||||
if (tn === $.TEXTAREA || tn === $.TITLE)
|
||||
this.tokenizer.state = Tokenizer.MODE.RCDATA;
|
||||
|
||||
else if (tn === $.PLAINTEXT)
|
||||
this.tokenizer.state = Tokenizer.MODE.PLAINTEXT;
|
||||
|
||||
else if (tn === $.SCRIPT)
|
||||
this.tokenizer.state = Tokenizer.MODE.SCRIPT_DATA;
|
||||
|
||||
else if (tn === $.STYLE || tn === $.IFRAME || tn === $.XMP ||
|
||||
tn === $.NOEMBED || tn === $.NOFRAMES || tn === $.NOSCRIPT)
|
||||
this.tokenizer.state = Tokenizer.MODE.RAWTEXT;
|
||||
};
|
||||
|
||||
ParserFeedbackSimulator.prototype._handleStartTagToken = function (token) {
|
||||
var tn = token.tagName;
|
||||
|
||||
if (tn === $.SVG)
|
||||
this._enterNamespace(NS.SVG);
|
||||
|
||||
else if (tn === $.MATH)
|
||||
this._enterNamespace(NS.MATHML);
|
||||
|
||||
if (this.inForeignContent) {
|
||||
if (foreignContent.causesExit(token)) {
|
||||
this._leaveCurrentNamespace();
|
||||
return;
|
||||
}
|
||||
|
||||
var currentNs = this.currentNamespace;
|
||||
|
||||
if (currentNs === NS.MATHML)
|
||||
foreignContent.adjustTokenMathMLAttrs(token);
|
||||
|
||||
else if (currentNs === NS.SVG) {
|
||||
foreignContent.adjustTokenSVGTagName(token);
|
||||
foreignContent.adjustTokenSVGAttrs(token);
|
||||
}
|
||||
|
||||
foreignContent.adjustTokenXMLAttrs(token);
|
||||
|
||||
tn = token.tagName;
|
||||
|
||||
if (!token.selfClosing && foreignContent.isIntegrationPoint(tn, currentNs, token.attrs))
|
||||
this._enterNamespace(NS.HTML);
|
||||
}
|
||||
|
||||
else {
|
||||
if (tn === $.PRE || tn === $.TEXTAREA || tn === $.LISTING)
|
||||
this.skipNextNewLine = true;
|
||||
|
||||
else if (tn === $.IMAGE)
|
||||
token.tagName = $.IMG;
|
||||
|
||||
this._ensureTokenizerMode(tn);
|
||||
}
|
||||
};
|
||||
|
||||
ParserFeedbackSimulator.prototype._handleEndTagToken = function (token) {
|
||||
var tn = token.tagName;
|
||||
|
||||
if (!this.inForeignContent) {
|
||||
var previousNs = this.namespaceStack[this.namespaceStackTop - 1];
|
||||
|
||||
if (previousNs === NS.SVG && foreignContent.SVG_TAG_NAMES_ADJUSTMENT_MAP[tn])
|
||||
tn = foreignContent.SVG_TAG_NAMES_ADJUSTMENT_MAP[tn];
|
||||
|
||||
//NOTE: check for exit from integration point
|
||||
if (foreignContent.isIntegrationPoint(tn, previousNs, token.attrs))
|
||||
this._leaveCurrentNamespace();
|
||||
}
|
||||
|
||||
else if (tn === $.SVG && this.currentNamespace === NS.SVG ||
|
||||
tn === $.MATH && this.currentNamespace === NS.MATHML)
|
||||
this._leaveCurrentNamespace();
|
||||
|
||||
// NOTE: adjust end tag name as well for consistency
|
||||
if (this.currentNamespace === NS.SVG)
|
||||
foreignContent.adjustTokenSVGTagName(token);
|
||||
};
|
||||
162
node_modules/cheerio/node_modules/parse5/lib/serializer/index.js
generated
vendored
Normal file
162
node_modules/cheerio/node_modules/parse5/lib/serializer/index.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
'use strict';
|
||||
|
||||
var defaultTreeAdapter = require('../tree_adapters/default'),
|
||||
mergeOptions = require('../utils/merge_options'),
|
||||
doctype = require('../common/doctype'),
|
||||
HTML = require('../common/html');
|
||||
|
||||
//Aliases
|
||||
var $ = HTML.TAG_NAMES,
|
||||
NS = HTML.NAMESPACES;
|
||||
|
||||
//Default serializer options
|
||||
var DEFAULT_OPTIONS = {
|
||||
treeAdapter: defaultTreeAdapter
|
||||
};
|
||||
|
||||
//Escaping regexes
|
||||
var AMP_REGEX = /&/g,
|
||||
NBSP_REGEX = /\u00a0/g,
|
||||
DOUBLE_QUOTE_REGEX = /"/g,
|
||||
LT_REGEX = /</g,
|
||||
GT_REGEX = />/g;
|
||||
|
||||
//Serializer
|
||||
var Serializer = module.exports = function (node, options) {
|
||||
this.options = mergeOptions(DEFAULT_OPTIONS, options);
|
||||
this.treeAdapter = this.options.treeAdapter;
|
||||
|
||||
this.html = '';
|
||||
this.startNode = node;
|
||||
};
|
||||
|
||||
// NOTE: exported as static method for the testing purposes
|
||||
Serializer.escapeString = function (str, attrMode) {
|
||||
str = str
|
||||
.replace(AMP_REGEX, '&')
|
||||
.replace(NBSP_REGEX, ' ');
|
||||
|
||||
if (attrMode)
|
||||
str = str.replace(DOUBLE_QUOTE_REGEX, '"');
|
||||
|
||||
else {
|
||||
str = str
|
||||
.replace(LT_REGEX, '<')
|
||||
.replace(GT_REGEX, '>');
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
||||
|
||||
//API
|
||||
Serializer.prototype.serialize = function () {
|
||||
this._serializeChildNodes(this.startNode);
|
||||
|
||||
return this.html;
|
||||
};
|
||||
|
||||
|
||||
//Internals
|
||||
Serializer.prototype._serializeChildNodes = function (parentNode) {
|
||||
var childNodes = this.treeAdapter.getChildNodes(parentNode);
|
||||
|
||||
if (childNodes) {
|
||||
for (var i = 0, cnLength = childNodes.length; i < cnLength; i++) {
|
||||
var currentNode = childNodes[i];
|
||||
|
||||
if (this.treeAdapter.isElementNode(currentNode))
|
||||
this._serializeElement(currentNode);
|
||||
|
||||
else if (this.treeAdapter.isTextNode(currentNode))
|
||||
this._serializeTextNode(currentNode);
|
||||
|
||||
else if (this.treeAdapter.isCommentNode(currentNode))
|
||||
this._serializeCommentNode(currentNode);
|
||||
|
||||
else if (this.treeAdapter.isDocumentTypeNode(currentNode))
|
||||
this._serializeDocumentTypeNode(currentNode);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Serializer.prototype._serializeElement = function (node) {
|
||||
var tn = this.treeAdapter.getTagName(node),
|
||||
ns = this.treeAdapter.getNamespaceURI(node);
|
||||
|
||||
this.html += '<' + tn;
|
||||
this._serializeAttributes(node);
|
||||
this.html += '>';
|
||||
|
||||
if (tn !== $.AREA && tn !== $.BASE && tn !== $.BASEFONT && tn !== $.BGSOUND && tn !== $.BR && tn !== $.BR &&
|
||||
tn !== $.COL && tn !== $.EMBED && tn !== $.FRAME && tn !== $.HR && tn !== $.IMG && tn !== $.INPUT &&
|
||||
tn !== $.KEYGEN && tn !== $.LINK && tn !== $.MENUITEM && tn !== $.META && tn !== $.PARAM && tn !== $.SOURCE &&
|
||||
tn !== $.TRACK && tn !== $.WBR) {
|
||||
|
||||
var childNodesHolder = tn === $.TEMPLATE && ns === NS.HTML ?
|
||||
this.treeAdapter.getTemplateContent(node) :
|
||||
node;
|
||||
|
||||
this._serializeChildNodes(childNodesHolder);
|
||||
this.html += '</' + tn + '>';
|
||||
}
|
||||
};
|
||||
|
||||
Serializer.prototype._serializeAttributes = function (node) {
|
||||
var attrs = this.treeAdapter.getAttrList(node);
|
||||
|
||||
for (var i = 0, attrsLength = attrs.length; i < attrsLength; i++) {
|
||||
var attr = attrs[i],
|
||||
value = Serializer.escapeString(attr.value, true);
|
||||
|
||||
this.html += ' ';
|
||||
|
||||
if (!attr.namespace)
|
||||
this.html += attr.name;
|
||||
|
||||
else if (attr.namespace === NS.XML)
|
||||
this.html += 'xml:' + attr.name;
|
||||
|
||||
else if (attr.namespace === NS.XMLNS) {
|
||||
if (attr.name !== 'xmlns')
|
||||
this.html += 'xmlns:';
|
||||
|
||||
this.html += attr.name;
|
||||
}
|
||||
|
||||
else if (attr.namespace === NS.XLINK)
|
||||
this.html += 'xlink:' + attr.name;
|
||||
|
||||
else
|
||||
this.html += attr.namespace + ':' + attr.name;
|
||||
|
||||
this.html += '="' + value + '"';
|
||||
}
|
||||
};
|
||||
|
||||
Serializer.prototype._serializeTextNode = function (node) {
|
||||
var content = this.treeAdapter.getTextNodeContent(node),
|
||||
parent = this.treeAdapter.getParentNode(node),
|
||||
parentTn = void 0;
|
||||
|
||||
if (parent && this.treeAdapter.isElementNode(parent))
|
||||
parentTn = this.treeAdapter.getTagName(parent);
|
||||
|
||||
if (parentTn === $.STYLE || parentTn === $.SCRIPT || parentTn === $.XMP || parentTn === $.IFRAME ||
|
||||
parentTn === $.NOEMBED || parentTn === $.NOFRAMES || parentTn === $.PLAINTEXT || parentTn === $.NOSCRIPT)
|
||||
|
||||
this.html += content;
|
||||
|
||||
else
|
||||
this.html += Serializer.escapeString(content, false);
|
||||
};
|
||||
|
||||
Serializer.prototype._serializeCommentNode = function (node) {
|
||||
this.html += '<!--' + this.treeAdapter.getCommentNodeContent(node) + '-->';
|
||||
};
|
||||
|
||||
Serializer.prototype._serializeDocumentTypeNode = function (node) {
|
||||
var name = this.treeAdapter.getDocumentTypeNodeName(node);
|
||||
|
||||
this.html += '<' + doctype.serializeContent(name, null, null) + '>';
|
||||
};
|
||||
28
node_modules/cheerio/node_modules/parse5/lib/serializer/serializer_stream.js
generated
vendored
Normal file
28
node_modules/cheerio/node_modules/parse5/lib/serializer/serializer_stream.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var ReadableStream = require('stream').Readable,
|
||||
inherits = require('util').inherits,
|
||||
Serializer = require('./index');
|
||||
|
||||
var SerializerStream = module.exports = function (node, options) {
|
||||
ReadableStream.call(this);
|
||||
|
||||
this.serializer = new Serializer(node, options);
|
||||
|
||||
Object.defineProperty(this.serializer, 'html', {
|
||||
//NOTE: To make `+=` concat operator work properly we define
|
||||
//getter which always returns empty string
|
||||
get: function () {
|
||||
return '';
|
||||
},
|
||||
set: this.push.bind(this)
|
||||
});
|
||||
};
|
||||
|
||||
inherits(SerializerStream, ReadableStream);
|
||||
|
||||
//Readable stream implementation
|
||||
SerializerStream.prototype._read = function () {
|
||||
this.serializer.serialize();
|
||||
this.push(null);
|
||||
};
|
||||
2144
node_modules/cheerio/node_modules/parse5/lib/tokenizer/index.js
generated
vendored
Normal file
2144
node_modules/cheerio/node_modules/parse5/lib/tokenizer/index.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
5
node_modules/cheerio/node_modules/parse5/lib/tokenizer/named_entity_data.js
generated
vendored
Normal file
5
node_modules/cheerio/node_modules/parse5/lib/tokenizer/named_entity_data.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
147
node_modules/cheerio/node_modules/parse5/lib/tokenizer/preprocessor.js
generated
vendored
Normal file
147
node_modules/cheerio/node_modules/parse5/lib/tokenizer/preprocessor.js
generated
vendored
Normal file
@@ -0,0 +1,147 @@
|
||||
'use strict';
|
||||
|
||||
var UNICODE = require('../common/unicode');
|
||||
|
||||
//Aliases
|
||||
var $ = UNICODE.CODE_POINTS;
|
||||
|
||||
//Utils
|
||||
|
||||
//OPTIMIZATION: these utility functions should not be moved out of this module. V8 Crankshaft will not inline
|
||||
//this functions if they will be situated in another module due to context switch.
|
||||
//Always perform inlining check before modifying this functions ('node --trace-inlining').
|
||||
function isSurrogatePair(cp1, cp2) {
|
||||
return cp1 >= 0xD800 && cp1 <= 0xDBFF && cp2 >= 0xDC00 && cp2 <= 0xDFFF;
|
||||
}
|
||||
|
||||
function getSurrogatePairCodePoint(cp1, cp2) {
|
||||
return (cp1 - 0xD800) * 0x400 + 0x2400 + cp2;
|
||||
}
|
||||
|
||||
|
||||
//Const
|
||||
var DEFAULT_BUFFER_WATERLINE = 1 << 16;
|
||||
|
||||
|
||||
//Preprocessor
|
||||
//NOTE: HTML input preprocessing
|
||||
//(see: http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#preprocessing-the-input-stream)
|
||||
var Preprocessor = module.exports = function () {
|
||||
this.html = null;
|
||||
|
||||
this.pos = -1;
|
||||
this.lastGapPos = -1;
|
||||
this.lastCharPos = -1;
|
||||
|
||||
this.gapStack = [];
|
||||
|
||||
this.skipNextNewLine = false;
|
||||
|
||||
this.lastChunkWritten = false;
|
||||
this.endOfChunkHit = false;
|
||||
this.bufferWaterline = DEFAULT_BUFFER_WATERLINE;
|
||||
};
|
||||
|
||||
Preprocessor.prototype.dropParsedChunk = function () {
|
||||
if (this.pos > this.bufferWaterline) {
|
||||
this.lastCharPos -= this.pos;
|
||||
this.html = this.html.substring(this.pos);
|
||||
this.pos = 0;
|
||||
this.lastGapPos = -1;
|
||||
this.gapStack = [];
|
||||
}
|
||||
};
|
||||
|
||||
Preprocessor.prototype._addGap = function () {
|
||||
this.gapStack.push(this.lastGapPos);
|
||||
this.lastGapPos = this.pos;
|
||||
};
|
||||
|
||||
Preprocessor.prototype._processHighRangeCodePoint = function (cp) {
|
||||
//NOTE: try to peek a surrogate pair
|
||||
if (this.pos !== this.lastCharPos) {
|
||||
var nextCp = this.html.charCodeAt(this.pos + 1);
|
||||
|
||||
if (isSurrogatePair(cp, nextCp)) {
|
||||
//NOTE: we have a surrogate pair. Peek pair character and recalculate code point.
|
||||
this.pos++;
|
||||
cp = getSurrogatePairCodePoint(cp, nextCp);
|
||||
|
||||
//NOTE: add gap that should be avoided during retreat
|
||||
this._addGap();
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: we've hit the end of chunk, stop processing at this point
|
||||
else if (!this.lastChunkWritten) {
|
||||
this.endOfChunkHit = true;
|
||||
return $.EOF;
|
||||
}
|
||||
|
||||
return cp;
|
||||
};
|
||||
|
||||
Preprocessor.prototype.write = function (chunk, isLastChunk) {
|
||||
if (this.html)
|
||||
this.html += chunk;
|
||||
|
||||
else
|
||||
this.html = chunk;
|
||||
|
||||
this.lastCharPos = this.html.length - 1;
|
||||
this.endOfChunkHit = false;
|
||||
this.lastChunkWritten = isLastChunk;
|
||||
};
|
||||
|
||||
Preprocessor.prototype.insertHtmlAtCurrentPos = function (chunk) {
|
||||
this.html = this.html.substring(0, this.pos + 1) +
|
||||
chunk +
|
||||
this.html.substring(this.pos + 1, this.html.length);
|
||||
|
||||
this.lastCharPos = this.html.length - 1;
|
||||
this.endOfChunkHit = false;
|
||||
};
|
||||
|
||||
|
||||
Preprocessor.prototype.advance = function () {
|
||||
this.pos++;
|
||||
|
||||
if (this.pos > this.lastCharPos) {
|
||||
if (!this.lastChunkWritten)
|
||||
this.endOfChunkHit = true;
|
||||
|
||||
return $.EOF;
|
||||
}
|
||||
|
||||
var cp = this.html.charCodeAt(this.pos);
|
||||
|
||||
//NOTE: any U+000A LINE FEED (LF) characters that immediately follow a U+000D CARRIAGE RETURN (CR) character
|
||||
//must be ignored.
|
||||
if (this.skipNextNewLine && cp === $.LINE_FEED) {
|
||||
this.skipNextNewLine = false;
|
||||
this._addGap();
|
||||
return this.advance();
|
||||
}
|
||||
|
||||
//NOTE: all U+000D CARRIAGE RETURN (CR) characters must be converted to U+000A LINE FEED (LF) characters
|
||||
if (cp === $.CARRIAGE_RETURN) {
|
||||
this.skipNextNewLine = true;
|
||||
return $.LINE_FEED;
|
||||
}
|
||||
|
||||
this.skipNextNewLine = false;
|
||||
|
||||
//OPTIMIZATION: first perform check if the code point in the allowed range that covers most common
|
||||
//HTML input (e.g. ASCII codes) to avoid performance-cost operations for high-range code points.
|
||||
return cp >= 0xD800 ? this._processHighRangeCodePoint(cp) : cp;
|
||||
};
|
||||
|
||||
Preprocessor.prototype.retreat = function () {
|
||||
if (this.pos === this.lastGapPos) {
|
||||
this.lastGapPos = this.gapStack.pop();
|
||||
this.pos--;
|
||||
}
|
||||
|
||||
this.pos--;
|
||||
};
|
||||
|
||||
209
node_modules/cheerio/node_modules/parse5/lib/tree_adapters/default.js
generated
vendored
Normal file
209
node_modules/cheerio/node_modules/parse5/lib/tree_adapters/default.js
generated
vendored
Normal file
@@ -0,0 +1,209 @@
|
||||
'use strict';
|
||||
|
||||
var DOCUMENT_MODE = require('../common/html').DOCUMENT_MODE;
|
||||
|
||||
//Node construction
|
||||
exports.createDocument = function () {
|
||||
return {
|
||||
nodeName: '#document',
|
||||
mode: DOCUMENT_MODE.NO_QUIRKS,
|
||||
childNodes: []
|
||||
};
|
||||
};
|
||||
|
||||
exports.createDocumentFragment = function () {
|
||||
return {
|
||||
nodeName: '#document-fragment',
|
||||
childNodes: []
|
||||
};
|
||||
};
|
||||
|
||||
exports.createElement = function (tagName, namespaceURI, attrs) {
|
||||
return {
|
||||
nodeName: tagName,
|
||||
tagName: tagName,
|
||||
attrs: attrs,
|
||||
namespaceURI: namespaceURI,
|
||||
childNodes: [],
|
||||
parentNode: null
|
||||
};
|
||||
};
|
||||
|
||||
exports.createCommentNode = function (data) {
|
||||
return {
|
||||
nodeName: '#comment',
|
||||
data: data,
|
||||
parentNode: null
|
||||
};
|
||||
};
|
||||
|
||||
var createTextNode = function (value) {
|
||||
return {
|
||||
nodeName: '#text',
|
||||
value: value,
|
||||
parentNode: null
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
//Tree mutation
|
||||
var appendChild = exports.appendChild = function (parentNode, newNode) {
|
||||
parentNode.childNodes.push(newNode);
|
||||
newNode.parentNode = parentNode;
|
||||
};
|
||||
|
||||
var insertBefore = exports.insertBefore = function (parentNode, newNode, referenceNode) {
|
||||
var insertionIdx = parentNode.childNodes.indexOf(referenceNode);
|
||||
|
||||
parentNode.childNodes.splice(insertionIdx, 0, newNode);
|
||||
newNode.parentNode = parentNode;
|
||||
};
|
||||
|
||||
exports.setTemplateContent = function (templateElement, contentElement) {
|
||||
templateElement.content = contentElement;
|
||||
};
|
||||
|
||||
exports.getTemplateContent = function (templateElement) {
|
||||
return templateElement.content;
|
||||
};
|
||||
|
||||
exports.setDocumentType = function (document, name, publicId, systemId) {
|
||||
var doctypeNode = null;
|
||||
|
||||
for (var i = 0; i < document.childNodes.length; i++) {
|
||||
if (document.childNodes[i].nodeName === '#documentType') {
|
||||
doctypeNode = document.childNodes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (doctypeNode) {
|
||||
doctypeNode.name = name;
|
||||
doctypeNode.publicId = publicId;
|
||||
doctypeNode.systemId = systemId;
|
||||
}
|
||||
|
||||
else {
|
||||
appendChild(document, {
|
||||
nodeName: '#documentType',
|
||||
name: name,
|
||||
publicId: publicId,
|
||||
systemId: systemId
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.setDocumentMode = function (document, mode) {
|
||||
document.mode = mode;
|
||||
};
|
||||
|
||||
exports.getDocumentMode = function (document) {
|
||||
return document.mode;
|
||||
};
|
||||
|
||||
exports.detachNode = function (node) {
|
||||
if (node.parentNode) {
|
||||
var idx = node.parentNode.childNodes.indexOf(node);
|
||||
|
||||
node.parentNode.childNodes.splice(idx, 1);
|
||||
node.parentNode = null;
|
||||
}
|
||||
};
|
||||
|
||||
exports.insertText = function (parentNode, text) {
|
||||
if (parentNode.childNodes.length) {
|
||||
var prevNode = parentNode.childNodes[parentNode.childNodes.length - 1];
|
||||
|
||||
if (prevNode.nodeName === '#text') {
|
||||
prevNode.value += text;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
appendChild(parentNode, createTextNode(text));
|
||||
};
|
||||
|
||||
exports.insertTextBefore = function (parentNode, text, referenceNode) {
|
||||
var prevNode = parentNode.childNodes[parentNode.childNodes.indexOf(referenceNode) - 1];
|
||||
|
||||
if (prevNode && prevNode.nodeName === '#text')
|
||||
prevNode.value += text;
|
||||
else
|
||||
insertBefore(parentNode, createTextNode(text), referenceNode);
|
||||
};
|
||||
|
||||
exports.adoptAttributes = function (recipient, attrs) {
|
||||
var recipientAttrsMap = [];
|
||||
|
||||
for (var i = 0; i < recipient.attrs.length; i++)
|
||||
recipientAttrsMap.push(recipient.attrs[i].name);
|
||||
|
||||
for (var j = 0; j < attrs.length; j++) {
|
||||
if (recipientAttrsMap.indexOf(attrs[j].name) === -1)
|
||||
recipient.attrs.push(attrs[j]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//Tree traversing
|
||||
exports.getFirstChild = function (node) {
|
||||
return node.childNodes[0];
|
||||
};
|
||||
|
||||
exports.getChildNodes = function (node) {
|
||||
return node.childNodes;
|
||||
};
|
||||
|
||||
exports.getParentNode = function (node) {
|
||||
return node.parentNode;
|
||||
};
|
||||
|
||||
exports.getAttrList = function (element) {
|
||||
return element.attrs;
|
||||
};
|
||||
|
||||
//Node data
|
||||
exports.getTagName = function (element) {
|
||||
return element.tagName;
|
||||
};
|
||||
|
||||
exports.getNamespaceURI = function (element) {
|
||||
return element.namespaceURI;
|
||||
};
|
||||
|
||||
exports.getTextNodeContent = function (textNode) {
|
||||
return textNode.value;
|
||||
};
|
||||
|
||||
exports.getCommentNodeContent = function (commentNode) {
|
||||
return commentNode.data;
|
||||
};
|
||||
|
||||
exports.getDocumentTypeNodeName = function (doctypeNode) {
|
||||
return doctypeNode.name;
|
||||
};
|
||||
|
||||
exports.getDocumentTypeNodePublicId = function (doctypeNode) {
|
||||
return doctypeNode.publicId;
|
||||
};
|
||||
|
||||
exports.getDocumentTypeNodeSystemId = function (doctypeNode) {
|
||||
return doctypeNode.systemId;
|
||||
};
|
||||
|
||||
//Node types
|
||||
exports.isTextNode = function (node) {
|
||||
return node.nodeName === '#text';
|
||||
};
|
||||
|
||||
exports.isCommentNode = function (node) {
|
||||
return node.nodeName === '#comment';
|
||||
};
|
||||
|
||||
exports.isDocumentTypeNode = function (node) {
|
||||
return node.nodeName === '#documentType';
|
||||
};
|
||||
|
||||
exports.isElementNode = function (node) {
|
||||
return !!node.tagName;
|
||||
};
|
||||
338
node_modules/cheerio/node_modules/parse5/lib/tree_adapters/htmlparser2.js
generated
vendored
Normal file
338
node_modules/cheerio/node_modules/parse5/lib/tree_adapters/htmlparser2.js
generated
vendored
Normal file
@@ -0,0 +1,338 @@
|
||||
'use strict';
|
||||
|
||||
var doctype = require('../common/doctype'),
|
||||
DOCUMENT_MODE = require('../common/html').DOCUMENT_MODE;
|
||||
|
||||
|
||||
//Conversion tables for DOM Level1 structure emulation
|
||||
var nodeTypes = {
|
||||
element: 1,
|
||||
text: 3,
|
||||
cdata: 4,
|
||||
comment: 8
|
||||
};
|
||||
|
||||
var nodePropertyShorthands = {
|
||||
tagName: 'name',
|
||||
childNodes: 'children',
|
||||
parentNode: 'parent',
|
||||
previousSibling: 'prev',
|
||||
nextSibling: 'next',
|
||||
nodeValue: 'data'
|
||||
};
|
||||
|
||||
//Node
|
||||
var Node = function (props) {
|
||||
for (var key in props) {
|
||||
if (props.hasOwnProperty(key))
|
||||
this[key] = props[key];
|
||||
}
|
||||
};
|
||||
|
||||
Node.prototype = {
|
||||
get firstChild() {
|
||||
var children = this.children;
|
||||
|
||||
return children && children[0] || null;
|
||||
},
|
||||
|
||||
get lastChild() {
|
||||
var children = this.children;
|
||||
|
||||
return children && children[children.length - 1] || null;
|
||||
},
|
||||
|
||||
get nodeType() {
|
||||
return nodeTypes[this.type] || nodeTypes.element;
|
||||
}
|
||||
};
|
||||
|
||||
Object.keys(nodePropertyShorthands).forEach(function (key) {
|
||||
var shorthand = nodePropertyShorthands[key];
|
||||
|
||||
Object.defineProperty(Node.prototype, key, {
|
||||
get: function () {
|
||||
return this[shorthand] || null;
|
||||
},
|
||||
set: function (val) {
|
||||
this[shorthand] = val;
|
||||
return val;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
//Node construction
|
||||
exports.createDocument = function () {
|
||||
return new Node({
|
||||
type: 'root',
|
||||
name: 'root',
|
||||
parent: null,
|
||||
prev: null,
|
||||
next: null,
|
||||
children: [],
|
||||
'x-mode': DOCUMENT_MODE.NO_QUIRKS
|
||||
});
|
||||
};
|
||||
|
||||
exports.createDocumentFragment = function () {
|
||||
return new Node({
|
||||
type: 'root',
|
||||
name: 'root',
|
||||
parent: null,
|
||||
prev: null,
|
||||
next: null,
|
||||
children: []
|
||||
});
|
||||
};
|
||||
|
||||
exports.createElement = function (tagName, namespaceURI, attrs) {
|
||||
var attribs = Object.create(null),
|
||||
attribsNamespace = Object.create(null),
|
||||
attribsPrefix = Object.create(null);
|
||||
|
||||
for (var i = 0; i < attrs.length; i++) {
|
||||
var attrName = attrs[i].name;
|
||||
|
||||
attribs[attrName] = attrs[i].value;
|
||||
attribsNamespace[attrName] = attrs[i].namespace;
|
||||
attribsPrefix[attrName] = attrs[i].prefix;
|
||||
}
|
||||
|
||||
return new Node({
|
||||
type: tagName === 'script' || tagName === 'style' ? tagName : 'tag',
|
||||
name: tagName,
|
||||
namespace: namespaceURI,
|
||||
attribs: attribs,
|
||||
'x-attribsNamespace': attribsNamespace,
|
||||
'x-attribsPrefix': attribsPrefix,
|
||||
children: [],
|
||||
parent: null,
|
||||
prev: null,
|
||||
next: null
|
||||
});
|
||||
};
|
||||
|
||||
exports.createCommentNode = function (data) {
|
||||
return new Node({
|
||||
type: 'comment',
|
||||
data: data,
|
||||
parent: null,
|
||||
prev: null,
|
||||
next: null
|
||||
});
|
||||
};
|
||||
|
||||
var createTextNode = function (value) {
|
||||
return new Node({
|
||||
type: 'text',
|
||||
data: value,
|
||||
parent: null,
|
||||
prev: null,
|
||||
next: null
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//Tree mutation
|
||||
var appendChild = exports.appendChild = function (parentNode, newNode) {
|
||||
var prev = parentNode.children[parentNode.children.length - 1];
|
||||
|
||||
if (prev) {
|
||||
prev.next = newNode;
|
||||
newNode.prev = prev;
|
||||
}
|
||||
|
||||
parentNode.children.push(newNode);
|
||||
newNode.parent = parentNode;
|
||||
};
|
||||
|
||||
var insertBefore = exports.insertBefore = function (parentNode, newNode, referenceNode) {
|
||||
var insertionIdx = parentNode.children.indexOf(referenceNode),
|
||||
prev = referenceNode.prev;
|
||||
|
||||
if (prev) {
|
||||
prev.next = newNode;
|
||||
newNode.prev = prev;
|
||||
}
|
||||
|
||||
referenceNode.prev = newNode;
|
||||
newNode.next = referenceNode;
|
||||
|
||||
parentNode.children.splice(insertionIdx, 0, newNode);
|
||||
newNode.parent = parentNode;
|
||||
};
|
||||
|
||||
exports.setTemplateContent = function (templateElement, contentElement) {
|
||||
appendChild(templateElement, contentElement);
|
||||
};
|
||||
|
||||
exports.getTemplateContent = function (templateElement) {
|
||||
return templateElement.children[0];
|
||||
};
|
||||
|
||||
exports.setDocumentType = function (document, name, publicId, systemId) {
|
||||
var data = doctype.serializeContent(name, publicId, systemId),
|
||||
doctypeNode = null;
|
||||
|
||||
for (var i = 0; i < document.children.length; i++) {
|
||||
if (document.children[i].type === 'directive' && document.children[i].name === '!doctype') {
|
||||
doctypeNode = document.children[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (doctypeNode) {
|
||||
doctypeNode.data = data;
|
||||
doctypeNode['x-name'] = name;
|
||||
doctypeNode['x-publicId'] = publicId;
|
||||
doctypeNode['x-systemId'] = systemId;
|
||||
}
|
||||
|
||||
else {
|
||||
appendChild(document, new Node({
|
||||
type: 'directive',
|
||||
name: '!doctype',
|
||||
data: data,
|
||||
'x-name': name,
|
||||
'x-publicId': publicId,
|
||||
'x-systemId': systemId
|
||||
}));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
exports.setDocumentMode = function (document, mode) {
|
||||
document['x-mode'] = mode;
|
||||
};
|
||||
|
||||
exports.getDocumentMode = function (document) {
|
||||
return document['x-mode'];
|
||||
};
|
||||
|
||||
exports.detachNode = function (node) {
|
||||
if (node.parent) {
|
||||
var idx = node.parent.children.indexOf(node),
|
||||
prev = node.prev,
|
||||
next = node.next;
|
||||
|
||||
node.prev = null;
|
||||
node.next = null;
|
||||
|
||||
if (prev)
|
||||
prev.next = next;
|
||||
|
||||
if (next)
|
||||
next.prev = prev;
|
||||
|
||||
node.parent.children.splice(idx, 1);
|
||||
node.parent = null;
|
||||
}
|
||||
};
|
||||
|
||||
exports.insertText = function (parentNode, text) {
|
||||
var lastChild = parentNode.children[parentNode.children.length - 1];
|
||||
|
||||
if (lastChild && lastChild.type === 'text')
|
||||
lastChild.data += text;
|
||||
else
|
||||
appendChild(parentNode, createTextNode(text));
|
||||
};
|
||||
|
||||
exports.insertTextBefore = function (parentNode, text, referenceNode) {
|
||||
var prevNode = parentNode.children[parentNode.children.indexOf(referenceNode) - 1];
|
||||
|
||||
if (prevNode && prevNode.type === 'text')
|
||||
prevNode.data += text;
|
||||
else
|
||||
insertBefore(parentNode, createTextNode(text), referenceNode);
|
||||
};
|
||||
|
||||
exports.adoptAttributes = function (recipient, attrs) {
|
||||
for (var i = 0; i < attrs.length; i++) {
|
||||
var attrName = attrs[i].name;
|
||||
|
||||
if (typeof recipient.attribs[attrName] === 'undefined') {
|
||||
recipient.attribs[attrName] = attrs[i].value;
|
||||
recipient['x-attribsNamespace'][attrName] = attrs[i].namespace;
|
||||
recipient['x-attribsPrefix'][attrName] = attrs[i].prefix;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//Tree traversing
|
||||
exports.getFirstChild = function (node) {
|
||||
return node.children[0];
|
||||
};
|
||||
|
||||
exports.getChildNodes = function (node) {
|
||||
return node.children;
|
||||
};
|
||||
|
||||
exports.getParentNode = function (node) {
|
||||
return node.parent;
|
||||
};
|
||||
|
||||
exports.getAttrList = function (element) {
|
||||
var attrList = [];
|
||||
|
||||
for (var name in element.attribs) {
|
||||
attrList.push({
|
||||
name: name,
|
||||
value: element.attribs[name],
|
||||
namespace: element['x-attribsNamespace'][name],
|
||||
prefix: element['x-attribsPrefix'][name]
|
||||
});
|
||||
}
|
||||
|
||||
return attrList;
|
||||
};
|
||||
|
||||
|
||||
//Node data
|
||||
exports.getTagName = function (element) {
|
||||
return element.name;
|
||||
};
|
||||
|
||||
exports.getNamespaceURI = function (element) {
|
||||
return element.namespace;
|
||||
};
|
||||
|
||||
exports.getTextNodeContent = function (textNode) {
|
||||
return textNode.data;
|
||||
};
|
||||
|
||||
exports.getCommentNodeContent = function (commentNode) {
|
||||
return commentNode.data;
|
||||
};
|
||||
|
||||
exports.getDocumentTypeNodeName = function (doctypeNode) {
|
||||
return doctypeNode['x-name'];
|
||||
};
|
||||
|
||||
exports.getDocumentTypeNodePublicId = function (doctypeNode) {
|
||||
return doctypeNode['x-publicId'];
|
||||
};
|
||||
|
||||
exports.getDocumentTypeNodeSystemId = function (doctypeNode) {
|
||||
return doctypeNode['x-systemId'];
|
||||
};
|
||||
|
||||
|
||||
//Node types
|
||||
exports.isTextNode = function (node) {
|
||||
return node.type === 'text';
|
||||
};
|
||||
|
||||
exports.isCommentNode = function (node) {
|
||||
return node.type === 'comment';
|
||||
};
|
||||
|
||||
exports.isDocumentTypeNode = function (node) {
|
||||
return node.type === 'directive' && node.name === '!doctype';
|
||||
};
|
||||
|
||||
exports.isElementNode = function (node) {
|
||||
return !!node.attribs;
|
||||
};
|
||||
13
node_modules/cheerio/node_modules/parse5/lib/utils/merge_options.js
generated
vendored
Normal file
13
node_modules/cheerio/node_modules/parse5/lib/utils/merge_options.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function mergeOptions(defaults, options) {
|
||||
options = options || Object.create(null);
|
||||
|
||||
return [defaults, options].reduce(function (merged, optObj) {
|
||||
Object.keys(optObj).forEach(function (key) {
|
||||
merged[key] = optObj[key];
|
||||
});
|
||||
|
||||
return merged;
|
||||
}, Object.create(null));
|
||||
};
|
||||
18
node_modules/cheerio/node_modules/parse5/lib/utils/mixin.js
generated
vendored
Normal file
18
node_modules/cheerio/node_modules/parse5/lib/utils/mixin.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var Mixin = module.exports = function (host) {
|
||||
var originalMethods = {},
|
||||
overriddenMethods = this._getOverriddenMethods(this, originalMethods);
|
||||
|
||||
Object.keys(overriddenMethods).forEach(function (key) {
|
||||
if (typeof overriddenMethods[key] === 'function') {
|
||||
originalMethods[key] = host[key];
|
||||
host[key] = overriddenMethods[key];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Mixin.prototype._getOverriddenMethods = function () {
|
||||
throw new Error('Not implemented');
|
||||
};
|
||||
|
||||
95
node_modules/cheerio/node_modules/parse5/package.json
generated
vendored
Normal file
95
node_modules/cheerio/node_modules/parse5/package.json
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"_from": "parse5@^3.0.1",
|
||||
"_id": "parse5@3.0.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==",
|
||||
"_location": "/cheerio/parse5",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "parse5@^3.0.1",
|
||||
"name": "parse5",
|
||||
"escapedName": "parse5",
|
||||
"rawSpec": "^3.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/cheerio"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz",
|
||||
"_shasum": "042f792ffdd36851551cf4e9e066b3874ab45b5c",
|
||||
"_spec": "parse5@^3.0.1",
|
||||
"_where": "D:\\dev\\crossmap\\backend-services\\cm-amazon-crawler\\node_modules\\cheerio",
|
||||
"author": {
|
||||
"name": "Ivan Nikulin",
|
||||
"email": "ifaaan@gmail.com",
|
||||
"url": "https://github.com/inikulin"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/inikulin/parse5/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": "https://github.com/inikulin/parse5/graphs/contributors",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.",
|
||||
"devDependencies": {
|
||||
"del": "^2.0.2",
|
||||
"gulp": "^3.9.0",
|
||||
"gulp-benchmark": "^1.1.1",
|
||||
"gulp-download": "0.0.1",
|
||||
"gulp-eslint": "^3.0.1",
|
||||
"gulp-install": "^0.6.0",
|
||||
"gulp-mocha": "^2.1.3",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-typedoc": "^2.0.0",
|
||||
"gulp-typescript": "^3.1.2",
|
||||
"publish-please": "^2.2.0",
|
||||
"through2": "^2.0.0",
|
||||
"typedoc": "^0.5.1",
|
||||
"typescript": "^2.0.6"
|
||||
},
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"homepage": "https://github.com/inikulin/parse5",
|
||||
"keywords": [
|
||||
"html",
|
||||
"parser",
|
||||
"html5",
|
||||
"WHATWG",
|
||||
"specification",
|
||||
"fast",
|
||||
"html parser",
|
||||
"html5 parser",
|
||||
"htmlparser",
|
||||
"parse5",
|
||||
"serializer",
|
||||
"html serializer",
|
||||
"htmlserializer",
|
||||
"sax",
|
||||
"simple api",
|
||||
"parse",
|
||||
"tokenize",
|
||||
"serialize",
|
||||
"tokenizer"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/index.js",
|
||||
"name": "parse5",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/inikulin/parse5.git"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublish": "publish-please guard",
|
||||
"publish-please": "publish-please",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"types": "./lib/index.d.ts",
|
||||
"version": "3.0.3"
|
||||
}
|
||||
85
node_modules/cheerio/package.json
generated
vendored
Normal file
85
node_modules/cheerio/package.json
generated
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"_from": "cheerio",
|
||||
"_id": "cheerio@1.0.0-rc.3",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA==",
|
||||
"_location": "/cheerio",
|
||||
"_phantomChildren": {
|
||||
"@types/node": "12.7.8"
|
||||
},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "cheerio",
|
||||
"name": "cheerio",
|
||||
"escapedName": "cheerio",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.3.tgz",
|
||||
"_shasum": "094636d425b2e9c0f4eb91a46c05630c9a1a8bf6",
|
||||
"_spec": "cheerio",
|
||||
"_where": "D:\\dev\\crossmap\\backend-services\\cm-amazon-crawler",
|
||||
"author": {
|
||||
"name": "Matt Mueller",
|
||||
"email": "mattmuelle@gmail.com",
|
||||
"url": "mat.io"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/cheeriojs/cheerio/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"css-select": "~1.2.0",
|
||||
"dom-serializer": "~0.1.1",
|
||||
"entities": "~1.1.1",
|
||||
"htmlparser2": "^3.9.1",
|
||||
"lodash": "^4.15.0",
|
||||
"parse5": "^3.0.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Tiny, fast, and elegant implementation of core jQuery designed specifically for the server",
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.0",
|
||||
"coveralls": "^2.11.9",
|
||||
"expect.js": "~0.3.1",
|
||||
"istanbul": "^0.4.3",
|
||||
"jquery": "^3.0.0",
|
||||
"jsdom": "^9.2.1",
|
||||
"jshint": "^2.9.2",
|
||||
"mocha": "^3.1.2",
|
||||
"xyz": "~1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"homepage": "https://github.com/cheeriojs/cheerio#readme",
|
||||
"keywords": [
|
||||
"htmlparser",
|
||||
"jquery",
|
||||
"selector",
|
||||
"scraper",
|
||||
"parser",
|
||||
"html"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"name": "cheerio",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/cheeriojs/cheerio.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "1.0.0-rc.3"
|
||||
}
|
||||
Reference in New Issue
Block a user