08-27-周三_17-09-29
This commit is contained in:
1
node_modules/gitbook-plugin-multipart/.gitattributes
generated
vendored
Normal file
1
node_modules/gitbook-plugin-multipart/.gitattributes
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
* text=auto
|
1
node_modules/gitbook-plugin-multipart/.npmignore
generated
vendored
Normal file
1
node_modules/gitbook-plugin-multipart/.npmignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
201
node_modules/gitbook-plugin-multipart/LICENSE.md
generated
vendored
Normal file
201
node_modules/gitbook-plugin-multipart/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
117
node_modules/gitbook-plugin-multipart/README.md
generated
vendored
Normal file
117
node_modules/gitbook-plugin-multipart/README.md
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
# gitbook-plugin-multipart
|
||||
|
||||
A plugin to [GitBook](https://www.gitbook.io) to structure your book into multiple parts, rather than a single list of chapters. Modifies the output of the default 'site' templates to treat top level chapters as book "parts", and renumber the child chapters uniquely within that "part".
|
||||
|
||||
In other words, it changes the rendered summary from this:
|
||||
|
||||
1. Part I - Introduction
|
||||
1.1. Really interesting
|
||||
1.2. Did you know?
|
||||
1.3. Oh yes
|
||||
1.3.1. I know!
|
||||
1.3.2. Quite
|
||||
1.4. Gosh
|
||||
2. Part 2 - Advanced
|
||||
2.1. Right then
|
||||
2.2. Let's get busy
|
||||
2.3. No more mucking about
|
||||
2.4. Of course
|
||||
|
||||
Into this:
|
||||
|
||||
Part I - Introduction
|
||||
1. Really interesting
|
||||
2. Did you know?
|
||||
3. Oh yes
|
||||
3.1. I know!
|
||||
3.2. Quite
|
||||
4. Gosh
|
||||
|
||||
Part 2 - Advanced
|
||||
1. Right then
|
||||
2. Let's get busy
|
||||
3. No more mucking about
|
||||
4. Of course
|
||||
|
||||
The difference is mainly cosmetic - the part headers lose their chapter numbers, and child chapters are renumbered to be unique to that part (their left-most chapter number is removed - `1.2.` becomes `2.`). Also, part headers are never greyed out, even if they don't have a link.
|
||||
|
||||
## Usage
|
||||
|
||||
You can install it via npm:
|
||||
|
||||
$ npm install gitbook-plugin-multipart
|
||||
|
||||
And use it in your book by updating the list of plugins in your `book.json` file:
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": [ ..., "multipart", ... ]
|
||||
}
|
||||
```
|
||||
|
||||
This plugin requires GitBook 0.6.0 or above (as it relies on the `summary:before` plugin hook).
|
||||
|
||||
Note that it only works with the default `site` generator, since it manipulates the HTML of the generated page.
|
||||
|
||||
## SUMMARY.md
|
||||
|
||||
No changes to the `SUMMARY.md` are necessary - all chapters are still written in a single large list, with top level list items being converted into part titles.
|
||||
|
||||
However, as of GitBook 0.6.0, the plugin can now rewrite the SUMMARY.md before it's processed by GitBook. That means you can now split your summary list into multiple lists, separated by h2 markdown headers. For example, instead of writing this in your SUMMARY.md:
|
||||
|
||||
```markdown
|
||||
# Book Title
|
||||
|
||||
* Part I - Introduction
|
||||
* Really interesting
|
||||
* Did you know?
|
||||
* Oh yes
|
||||
* I know!
|
||||
* Quite
|
||||
* Gosh
|
||||
* Part 2 - Advanced
|
||||
* Right then
|
||||
* Let's get busy
|
||||
* No more mucking about
|
||||
* Of course
|
||||
```
|
||||
|
||||
you can now write:
|
||||
|
||||
```markdown
|
||||
# Book Title
|
||||
|
||||
## Part I - Introduction
|
||||
* Really interesting
|
||||
* Did you know?
|
||||
* Oh yes
|
||||
* I know!
|
||||
* Quite
|
||||
* Gosh
|
||||
|
||||
## Part 2 - Advanced
|
||||
* Right then
|
||||
* Let's get busy
|
||||
* No more mucking about
|
||||
* Of course
|
||||
```
|
||||
|
||||
The plugin will render this as separate parts, with the header displayed in bold italics, and a divider placed above the new part heading.
|
||||
|
||||
Additionally, the plugin supports intro pages at the start of the summary. This are pages that don't have a heading, and appear directly below the Introduction node, with no visible page numbers and no divider.
|
||||
|
||||
```markdown
|
||||
# Book Title
|
||||
|
||||
* Getting Started
|
||||
* About this guide
|
||||
|
||||
## Part I - Introduction
|
||||
* Really interesting
|
||||
* Did you know?
|
||||
* Oh yes
|
||||
* I know!
|
||||
* Quite
|
||||
* Gosh
|
||||
```
|
||||
|
18
node_modules/gitbook-plugin-multipart/assets/multipart.css
generated
vendored
Normal file
18
node_modules/gitbook-plugin-multipart/assets/multipart.css
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
.book .book-summary ul.summary li.part {
|
||||
padding-top: 0px;
|
||||
}
|
||||
|
||||
.book .book-summary ul.summary li.part > ul.articles {
|
||||
padding-left: 0px;
|
||||
}
|
||||
|
||||
.book .book-summary ul.summary li.part.divider {
|
||||
margin: 10px 15px 10px 15px;
|
||||
}
|
||||
|
||||
.book .book-summary ul.summary li.part > span {
|
||||
font-style: italic;
|
||||
font-weight: bold;
|
||||
cursor: default;
|
||||
opacity: 1;
|
||||
}
|
82
node_modules/gitbook-plugin-multipart/index.js
generated
vendored
Normal file
82
node_modules/gitbook-plugin-multipart/index.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
var cheerio = require('cheerio');
|
||||
|
||||
module.exports = {
|
||||
book: {
|
||||
assets: "assets",
|
||||
css: [ "multipart.css" ]
|
||||
},
|
||||
hooks: {
|
||||
// Gets plain text content
|
||||
"summary:before": function(summary) {
|
||||
|
||||
// If the file contains an h2, we need to reformat it
|
||||
if (summary.content.match(/^## /m)) {
|
||||
|
||||
var parts = summary.content.split(/(?=##)/);
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
// Remove any blank lines
|
||||
parts[i] = parts[i].replace(/(\*.*)\n\n/gm, "$1\n");
|
||||
|
||||
// If the part has a heading, replace it and indent the child items in the list
|
||||
// Mark a heading as a part by smuggling some text into the list item.
|
||||
// Messy, but it's the only way.
|
||||
if (parts[i].indexOf('##') == 0) {
|
||||
parts[i] = parts[i].replace(/^([ \t]*\* .+)$/gm, " $1")
|
||||
.replace(/^## (.*)$/gm, "* -XPARTX-$1")
|
||||
}
|
||||
}
|
||||
summary.content = parts.join('');
|
||||
}
|
||||
|
||||
return summary;
|
||||
},
|
||||
|
||||
// Requires an unhealthy knowledge of the generated template...
|
||||
"page:after": function(page) {
|
||||
|
||||
var $ = cheerio.load(page.content);
|
||||
|
||||
// Replace top level li.chapter with li.part
|
||||
$('ul.summary > li.chapter').each(function(i, elem) {
|
||||
var li = $(elem);
|
||||
|
||||
// Replace the classes if the chapter is actually a part, and add a divider
|
||||
if (li.text().indexOf('-XPARTX-') > 0) {
|
||||
li.removeClass('chapter');
|
||||
li.addClass('part');
|
||||
|
||||
// Don't add a divider before the first part, let it come straight after the Introduction page
|
||||
if (i > 1)
|
||||
li.before('<li class="part divider" />');
|
||||
}
|
||||
});
|
||||
|
||||
// remove chapter numbers from any intro pages (and child pages)
|
||||
$('ul.summary > li.chapter span > b').remove();
|
||||
$('ul.summary > li.chapter a > b').remove();
|
||||
|
||||
// Remove the chapter number from the part header
|
||||
$('ul.summary > li.part > span > b').remove();
|
||||
$('ul.summary > li.part > a > b').remove();
|
||||
|
||||
// Replace the nasty munging of the name for part heading
|
||||
$('ul.summary > li.part > span').each(function(i, elem) {
|
||||
var span = $(elem);
|
||||
span.text(span.text().replace(/-XPARTX-/, ""));
|
||||
});
|
||||
|
||||
// Bump the remaining chapter numbers so each chapter is only unique
|
||||
// within the part
|
||||
$('ul.summary > li.part li.chapter b').each(function(i, elem) {
|
||||
var b = $(elem);
|
||||
var text = b.text();
|
||||
var index = text.indexOf('.');
|
||||
if (index > -1)
|
||||
b.text(text.substring(index + 1));
|
||||
});
|
||||
|
||||
page.content = $.html();
|
||||
return page;
|
||||
}
|
||||
}
|
||||
};
|
15
node_modules/gitbook-plugin-multipart/node_modules/cheerio/.jshintrc
generated
vendored
Normal file
15
node_modules/gitbook-plugin-multipart/node_modules/cheerio/.jshintrc
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"indent": 2,
|
||||
"eqnull": true,
|
||||
"laxbreak": true,
|
||||
"proto": true,
|
||||
"undef": true,
|
||||
"node": true,
|
||||
"quotmark": "single",
|
||||
"globals": {
|
||||
"expect": true,
|
||||
"it": true,
|
||||
"describe": true,
|
||||
"beforeEach": true
|
||||
}
|
||||
}
|
9
node_modules/gitbook-plugin-multipart/node_modules/cheerio/.npmignore
generated
vendored
Normal file
9
node_modules/gitbook-plugin-multipart/node_modules/cheerio/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
benchmark/
|
||||
src/
|
||||
support/
|
||||
tests/
|
||||
examples/
|
||||
*.sock
|
||||
*.tmproj
|
||||
coverage.html
|
||||
lib-cov
|
6
node_modules/gitbook-plugin-multipart/node_modules/cheerio/.travis.yml
generated
vendored
Normal file
6
node_modules/gitbook-plugin-multipart/node_modules/cheerio/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- 0.11
|
||||
matrix:
|
||||
fast_finish: true
|
47
node_modules/gitbook-plugin-multipart/node_modules/cheerio/CONTRIBUTING.md
generated
vendored
Normal file
47
node_modules/gitbook-plugin-multipart/node_modules/cheerio/CONTRIBUTING.md
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# Contributing to Cheerio
|
||||
|
||||
Thanks for your interest in contributing to the project! Here's a rundown of
|
||||
how we'd like to work with you:
|
||||
|
||||
1. File an issue on GitHub describing the contribution you'd like to make. This
|
||||
will help us to get you started on the right foot.
|
||||
2. Create a single commit that addresses the issue:
|
||||
1. Follow the project's code style (see below)
|
||||
2. Add enough unit tests to "prove" that your patch is correct
|
||||
3. Update the project documentation as needed (see below)
|
||||
4. Describe your approach with as much detail as necessary in the git
|
||||
commit message
|
||||
3. Open a pull request, and reference the initial issue in the pull request
|
||||
message.
|
||||
|
||||
# Documentation
|
||||
|
||||
Any API change should be reflected in the project's README.md file. Reuse
|
||||
[jQuery's documentation](http://api.jquery.com) wherever possible, but take
|
||||
care to note aspects that make Cheerio distinct.
|
||||
|
||||
# Code Style
|
||||
|
||||
This section is by no means complete. For undocumented stylistic choices,
|
||||
please try to maintain consistency with the code base.
|
||||
|
||||
- Single quotes: `'`
|
||||
- Whitespace
|
||||
- Two-space "soft" tabs
|
||||
- Once space following control flow statements (`if (condition) {` rather
|
||||
than `if(condition) {`)
|
||||
- Remove trailing spaces
|
||||
- [End each file with a newline
|
||||
character.](https://github.com/editorconfig/editorconfig/wiki/Newline-at-End-of-File-Support)
|
||||
- Terminate every statement with a semicolon
|
||||
- Private functionality (for re-using functionality that isn't part of the
|
||||
jQuery API)
|
||||
- *Static methods*: If the functionality does not require a reference to a
|
||||
Cheerio instance, simply define a named function within the module it is
|
||||
needed.
|
||||
- *Instance methods*: If the functionality requires a reference to a Cheerio
|
||||
instance, informally define the method as "private" using the following
|
||||
conventions:
|
||||
- Define the method as a function on the Cheerio prototype
|
||||
- Prefix the method name with an underscore (`_`) character
|
||||
- Include `@api private` in the code comment the documents the method
|
418
node_modules/gitbook-plugin-multipart/node_modules/cheerio/History.md
generated
vendored
Normal file
418
node_modules/gitbook-plugin-multipart/node_modules/cheerio/History.md
generated
vendored
Normal file
@@ -0,0 +1,418 @@
|
||||
|
||||
0.17.0 / 2014-06-10
|
||||
==================
|
||||
|
||||
|
||||
|
||||
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 tidy 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 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)
|
31
node_modules/gitbook-plugin-multipart/node_modules/cheerio/Makefile
generated
vendored
Normal file
31
node_modules/gitbook-plugin-multipart/node_modules/cheerio/Makefile
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
REPORTER = dot
|
||||
XYZ = node_modules/.bin/xyz --message 'Release X.Y.Z' --tag X.Y.Z --script scripts/prepublish
|
||||
|
||||
test:
|
||||
@./node_modules/.bin/jshint lib/ test/
|
||||
@./node_modules/.bin/mocha --reporter $(REPORTER)
|
||||
|
||||
setup:
|
||||
@npm install
|
||||
|
||||
subl:
|
||||
@subl lib/ test/ package.json index.js
|
||||
|
||||
test-cov: lib-cov
|
||||
@CHEERIO_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html
|
||||
|
||||
lib-cov:
|
||||
@jscoverage lib lib-cov
|
||||
|
||||
bench:
|
||||
@./benchmark/benchmark.js
|
||||
|
||||
.PHONY: release-major release-minor release-patch
|
||||
release-major: LEVEL = major
|
||||
release-minor: LEVEL = minor
|
||||
release-patch: LEVEL = patch
|
||||
|
||||
release-major release-minor release-patch:
|
||||
@$(XYZ) --increment $(LEVEL)
|
||||
|
||||
.PHONY: test build setup subl
|
793
node_modules/gitbook-plugin-multipart/node_modules/cheerio/Readme.md
generated
vendored
Normal file
793
node_modules/gitbook-plugin-multipart/node_modules/cheerio/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,793 @@
|
||||
# cheerio [](http://travis-ci.org/cheeriojs/cheerio)
|
||||
|
||||
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
|
||||
|
||||
## Introduction
|
||||
Teach your server HTML.
|
||||
|
||||
```js
|
||||
var cheerio = require('cheerio'),
|
||||
$ = cheerio.load('<h2 class="title">Hello world</h2>');
|
||||
|
||||
$('h2.title').text('Hello there!');
|
||||
$('h2').addClass('welcome');
|
||||
|
||||
$.html();
|
||||
//=> <h2 class="title welcome">Hello there!</h2>
|
||||
```
|
||||
|
||||
## Installation
|
||||
`npm install cheerio`
|
||||
|
||||
## Features
|
||||
__❤ Familiar syntax:__
|
||||
Cheerio implements a subset of core jQuery. Cheerio removes all the DOM inconsistencies and browser cruft from the jQuery library, revealing its truly gorgeous API.
|
||||
|
||||
__ϟ Blazingly fast:__
|
||||
Cheerio works with a very simple, consistent DOM model. As a result parsing, manipulating, and rendering are incredibly efficient. Preliminary end-to-end benchmarks suggest that cheerio is about __8x__ faster than JSDOM.
|
||||
|
||||
__❁ Incredibly flexible:__
|
||||
Cheerio wraps around @FB55's forgiving [htmlparser2](https://github.com/fb55/htmlparser2/). Cheerio can parse nearly any HTML or XML document.
|
||||
|
||||
## What about JSDOM?
|
||||
I wrote cheerio because I found myself increasingly frustrated with JSDOM. For me, there were three main sticking points that I kept running into again and again:
|
||||
|
||||
__• JSDOM's built-in parser is too strict:__
|
||||
JSDOM's bundled HTML parser cannot handle many popular sites out there today.
|
||||
|
||||
__• JSDOM is too slow:__
|
||||
Parsing big websites with JSDOM has a noticeable delay.
|
||||
|
||||
__• JSDOM feels too heavy:__
|
||||
The goal of JSDOM is to provide an identical DOM environment as what we see in the browser. I never really needed all this, I just wanted a simple, familiar way to do HTML manipulation.
|
||||
|
||||
## When I would use JSDOM
|
||||
|
||||
Cheerio will not solve all your problems. I would still use JSDOM if I needed to work in a browser-like environment on the server, particularly if I wanted to automate functional tests.
|
||||
|
||||
## API
|
||||
|
||||
### Markup example we'll be using:
|
||||
|
||||
```html
|
||||
<ul id="fruits">
|
||||
<li class="apple">Apple</li>
|
||||
<li class="orange">Orange</li>
|
||||
<li class="pear">Pear</li>
|
||||
</ul>
|
||||
```
|
||||
|
||||
This is the HTML markup we will be using in all of the API examples.
|
||||
|
||||
### Loading
|
||||
First you need to load in the HTML. This step in jQuery is implicit, since jQuery operates on the one, baked-in DOM. With Cheerio, we need to pass in the HTML document.
|
||||
|
||||
This is the _preferred_ method:
|
||||
|
||||
```js
|
||||
var cheerio = require('cheerio'),
|
||||
$ = cheerio.load('<ul id="fruits">...</ul>');
|
||||
```
|
||||
|
||||
Optionally, you can also load in the HTML by passing the string as the context:
|
||||
|
||||
```js
|
||||
$ = require('cheerio');
|
||||
$('ul', '<ul id="fruits">...</ul>');
|
||||
```
|
||||
|
||||
Or as the root:
|
||||
|
||||
```js
|
||||
$ = require('cheerio');
|
||||
$('li', 'ul', '<ul id="fruits">...</ul>');
|
||||
```
|
||||
|
||||
You can also pass an extra object to `.load()` if you need to modify any
|
||||
of the default parsing options:
|
||||
|
||||
```js
|
||||
$ = cheerio.load('<ul id="fruits">...</ul>', {
|
||||
normalizeWhitespace: true,
|
||||
xmlMode: true
|
||||
});
|
||||
```
|
||||
|
||||
These parsing options are taken directly from [htmlparser2](https://github.com/fb55/htmlparser2/wiki/Parser-options), therefore any options that can be used in `htmlparser2` are valid in cheerio as well. The default options are:
|
||||
|
||||
```js
|
||||
{
|
||||
normalizeWhitespace: false,
|
||||
xmlMode: false,
|
||||
decodeEntities: true
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
For a full list of options and their effects, see [this](https://github.com/fb55/DomHandler) and
|
||||
[htmlparser2's options](https://github.com/fb55/htmlparser2/wiki/Parser-options).
|
||||
|
||||
### Selectors
|
||||
|
||||
Cheerio's selector implementation is nearly identical to jQuery's, so the API is very similar.
|
||||
|
||||
#### $( selector, [context], [root] )
|
||||
`selector` searches within the `context` scope which searches within the `root` scope. `selector` and `context` can be an string expression, DOM Element, array of DOM elements, or cheerio object. `root` is typically the HTML document string.
|
||||
|
||||
This selector method is the starting point for traversing and manipulating the document. Like jQuery, it's the primary method for selecting elements in the document, but unlike jQuery it's built on top of the CSSSelect library, which implements most of the Sizzle selectors.
|
||||
|
||||
```js
|
||||
$('.apple', '#fruits').text()
|
||||
//=> Apple
|
||||
|
||||
$('ul .pear').attr('class')
|
||||
//=> pear
|
||||
|
||||
$('li[class=orange]').html()
|
||||
//=> <li class="orange">Orange</li>
|
||||
```
|
||||
|
||||
### Attributes
|
||||
Methods for getting and modifying attributes.
|
||||
|
||||
#### .attr( name, value )
|
||||
Method for getting and setting attributes. Gets the attribute value for only the first element in the matched set. If you set an attribute's value to `null`, you remove that attribute. You may also pass a `map` and `function` like jQuery.
|
||||
|
||||
```js
|
||||
$('ul').attr('id')
|
||||
//=> fruits
|
||||
|
||||
$('.apple').attr('id', 'favorite').html()
|
||||
//=> <li class="apple" id="favorite">Apple</li>
|
||||
```
|
||||
|
||||
> See http://api.jquery.com/attr/ for more information
|
||||
|
||||
#### .data( name, value )
|
||||
Method for getting and setting data attributes. Gets or sets the data attribute value for only the first element in the matched set.
|
||||
|
||||
```js
|
||||
$('<div data-apple-color="red"></div>').data()
|
||||
//=> { appleColor: 'red' }
|
||||
|
||||
$('<div data-apple-color="red"></div>').data('data-apple-color')
|
||||
//=> 'red'
|
||||
|
||||
var apple = $('.apple').data('kind', 'mac')
|
||||
apple.data('kind')
|
||||
//=> 'mac'
|
||||
```
|
||||
|
||||
> See http://api.jquery.com/data/ for more information
|
||||
|
||||
#### .val( [value] )
|
||||
Method for getting and setting the value of input, select, and textarea. Note: Support for `map`, and `function` has not been added yet.
|
||||
|
||||
```js
|
||||
$('input[type="text"]').val()
|
||||
//=> input_text
|
||||
|
||||
$('input[type="text"]').val('test').html()
|
||||
//=> <input type="text" value="test"/>
|
||||
```
|
||||
|
||||
#### .removeAttr( name )
|
||||
Method for removing attributes by `name`.
|
||||
|
||||
```js
|
||||
$('.pear').removeAttr('class').html()
|
||||
//=> <li>Pear</li>
|
||||
```
|
||||
|
||||
#### .hasClass( className )
|
||||
Check to see if *any* of the matched elements have the given `className`.
|
||||
|
||||
```js
|
||||
$('.pear').hasClass('pear')
|
||||
//=> true
|
||||
|
||||
$('apple').hasClass('fruit')
|
||||
//=> false
|
||||
|
||||
$('li').hasClass('pear')
|
||||
//=> true
|
||||
```
|
||||
|
||||
#### .addClass( className )
|
||||
Adds class(es) to all of the matched elements. Also accepts a `function` like jQuery.
|
||||
|
||||
```js
|
||||
$('.pear').addClass('fruit').html()
|
||||
//=> <li class="pear fruit">Pear</li>
|
||||
|
||||
$('.apple').addClass('fruit red').html()
|
||||
//=> <li class="apple fruit red">Apple</li>
|
||||
```
|
||||
|
||||
> See http://api.jquery.com/addClass/ for more information.
|
||||
|
||||
#### .removeClass( [className] )
|
||||
Removes one or more space-separated classes from the selected elements. If no `className` is defined, all classes will be removed. Also accepts a `function` like jQuery.
|
||||
|
||||
```js
|
||||
$('.pear').removeClass('pear').html()
|
||||
//=> <li class="">Pear</li>
|
||||
|
||||
$('.apple').addClass('red').removeClass().html()
|
||||
//=> <li class="">Apple</li>
|
||||
```
|
||||
|
||||
> See http://api.jquery.com/removeClass/ for more information.
|
||||
|
||||
#### .toggleClass( className, [switch] )
|
||||
Add or remove class(es) from the matched elements, depending on either the class's presence or the value of the switch argument. Also accepts a `function` like jQuery.
|
||||
|
||||
```js
|
||||
$('.apple.green').toggleClass('fruit green red').html()
|
||||
//=> <li class="apple fruit red">Apple</li>
|
||||
|
||||
$('.apple.green').toggleClass('fruit green red', true).html()
|
||||
//=> <li class="apple green fruit red">Apple</li>
|
||||
```
|
||||
|
||||
> See http://api.jquery.com/toggleClass/ for more information.
|
||||
|
||||
#### .is( selector )
|
||||
#### .is( element )
|
||||
#### .is( selection )
|
||||
#### .is( function(index) )
|
||||
Checks the current list of elements and returns `true` if _any_ of the elements match the selector. If using an element or Cheerio selection, returns `true` if _any_ of the elements match. If using a predicate function, the function is executed in the context of the selected element, so `this` refers to the current element.
|
||||
|
||||
|
||||
### Traversing
|
||||
|
||||
#### .find(selector)
|
||||
Get a set of descendants filtered by `selector` of each element in the current set of matched elements.
|
||||
|
||||
```js
|
||||
$('#fruits').find('li').length
|
||||
//=> 3
|
||||
```
|
||||
|
||||
#### .parent([selector])
|
||||
Get the parent of each element in the current set of matched elements, optionally filtered by a selector.
|
||||
|
||||
```js
|
||||
$('.pear').parent().attr('id')
|
||||
//=> fruits
|
||||
```
|
||||
|
||||
#### .parents([selector])
|
||||
Get a set of parents filtered by `selector` of each element in the current set of match elements.
|
||||
```js
|
||||
$('.orange').parents().length
|
||||
// => 2
|
||||
$('.orange').parents('#fruits').length
|
||||
// => 1
|
||||
```
|
||||
|
||||
#### .parentsUntil([selector][,filter])
|
||||
Get the ancestors of each element in the current set of matched elements, up to but not including the element matched by the selector, DOM node, or cheerio object.
|
||||
```js
|
||||
$('.orange').parentsUntil('#food').length
|
||||
// => 1
|
||||
```
|
||||
|
||||
#### .closest(selector)
|
||||
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.
|
||||
|
||||
```js
|
||||
$('.orange').closest()
|
||||
// => []
|
||||
$('.orange').closest('.apple')
|
||||
// => []
|
||||
$('.orange').closest('li')
|
||||
// => [<li class="orange">Orange</li>]
|
||||
$('.orange').closest('#fruits')
|
||||
// => [<ul id="fruits"> ... </ul>]
|
||||
```
|
||||
|
||||
#### .next([selector])
|
||||
Gets the next sibling of the first selected element, optionally filtered by a selector.
|
||||
|
||||
```js
|
||||
$('.apple').next().hasClass('orange')
|
||||
//=> true
|
||||
```
|
||||
|
||||
#### .nextAll()
|
||||
Gets all the following siblings of the first selected element.
|
||||
|
||||
```js
|
||||
$('.apple').nextAll()
|
||||
//=> [<li class="orange">Orange</li>, <li class="pear">Pear</li>]
|
||||
```
|
||||
|
||||
#### .nextUntil()
|
||||
Gets all the following siblings up to but not including the element matched by the selector.
|
||||
|
||||
```js
|
||||
$('.apple').nextUntil('.pear')
|
||||
//=> [<li class="orange">Orange</li>]
|
||||
```
|
||||
|
||||
#### .prev([selector])
|
||||
Gets the previous sibling of the first selected element optionally filtered by a selector.
|
||||
|
||||
```js
|
||||
$('.orange').prev().hasClass('apple')
|
||||
//=> true
|
||||
```
|
||||
|
||||
#### .prevAll()
|
||||
Gets all the preceding siblings of the first selected element.
|
||||
|
||||
```js
|
||||
$('.pear').prevAll()
|
||||
//=> [<li class="orange">Orange</li>, <li class="apple">Apple</li>]
|
||||
```
|
||||
|
||||
#### .prevUntil()
|
||||
Gets all the preceding siblings up to but not including the element matched by the selector.
|
||||
|
||||
```js
|
||||
$('.pear').prevUntil('.apple')
|
||||
//=> [<li class="orange">Orange</li>]
|
||||
```
|
||||
|
||||
#### .slice( start, [end] )
|
||||
Gets the elements matching the specified range
|
||||
|
||||
```js
|
||||
$('li').slice(1).eq(0).text()
|
||||
//=> 'Orange'
|
||||
|
||||
$('li').slice(1, 2).length
|
||||
//=> 1
|
||||
```
|
||||
|
||||
#### .siblings( selector )
|
||||
Gets the first selected element's siblings, excluding itself.
|
||||
|
||||
```js
|
||||
$('.pear').siblings().length
|
||||
//=> 2
|
||||
|
||||
$('.pear').siblings('.orange').length
|
||||
//=> 1
|
||||
|
||||
```
|
||||
|
||||
#### .children( selector )
|
||||
Gets the children of the first selected element.
|
||||
|
||||
```js
|
||||
$('#fruits').children().length
|
||||
//=> 3
|
||||
|
||||
$('#fruits').children('.pear').text()
|
||||
//=> Pear
|
||||
```
|
||||
|
||||
#### .contents()
|
||||
Gets the children of each element in the set of matched elements, including text and comment nodes.
|
||||
|
||||
```js
|
||||
$('#fruits').contents().length
|
||||
//=> 3
|
||||
```
|
||||
|
||||
#### .each( function(index, element) )
|
||||
Iterates over a cheerio object, executing a function for each matched element. When the callback is fired, the function is fired in the context of the DOM element, so `this` refers to the current element, which is equivalent to the function parameter `element`. To break out of the `each` loop early, return with `false`.
|
||||
|
||||
```js
|
||||
var fruits = [];
|
||||
|
||||
$('li').each(function(i, elem) {
|
||||
fruits[i] = $(this).text();
|
||||
});
|
||||
|
||||
fruits.join(', ');
|
||||
//=> Apple, Orange, Pear
|
||||
```
|
||||
|
||||
#### .map( function(index, element) )
|
||||
Pass each element in the current matched set through a function, producing a new Cheerio object containing the return values. The function can return an individual data item or an array of data items to be inserted into the resulting set. If an array is returned, the elements inside the array are inserted into the set. If the function returns null or undefined, no element will be inserted.
|
||||
|
||||
```js
|
||||
$('li').map(function(i, el) {
|
||||
// this === el
|
||||
return $('<div>').text($(this).text());
|
||||
}).html();
|
||||
//=> <div>apple</div><div>orange</div><div>pear</div>
|
||||
```
|
||||
|
||||
#### .filter( selector ) <br /> .filter( selection ) <br /> .filter( element ) <br /> .filter( function(index) )
|
||||
|
||||
Iterates over a cheerio object, reducing the set of selector elements to those that match the selector or pass the function's test. When a Cheerio selection is specified, return only the elements contained in that selection. When an element is specified, return only that element (if it is contained in the original selection). If using the function method, the function is executed in the context of the selected element, so `this` refers to the current element.
|
||||
|
||||
Selector:
|
||||
|
||||
```js
|
||||
$('li').filter('.orange').attr('class');
|
||||
//=> orange
|
||||
```
|
||||
|
||||
Function:
|
||||
|
||||
```js
|
||||
$('li').filter(function(i, el) {
|
||||
// this === el
|
||||
return $(this).attr('class') === 'orange';
|
||||
}).attr('class')
|
||||
//=> orange
|
||||
```
|
||||
|
||||
#### .first()
|
||||
Will select the first element of a cheerio object
|
||||
|
||||
```js
|
||||
$('#fruits').children().first().text()
|
||||
//=> Apple
|
||||
```
|
||||
|
||||
#### .last()
|
||||
Will select the last element of a cheerio object
|
||||
|
||||
```js
|
||||
$('#fruits').children().last().text()
|
||||
//=> Pear
|
||||
```
|
||||
|
||||
#### .eq( i )
|
||||
Reduce the set of matched elements to the one at the specified index. Use `.eq(-i)` to count backwards from the last selected element.
|
||||
|
||||
```js
|
||||
$('li').eq(0).text()
|
||||
//=> Apple
|
||||
|
||||
$('li').eq(-1).text()
|
||||
//=> Pear
|
||||
```
|
||||
|
||||
#### .get( [i] )
|
||||
|
||||
Retrieve the DOM elements matched by the Cheerio object. If an index is specified, retrieve one of the elements matched by the Cheerio object:
|
||||
|
||||
```js
|
||||
$('li').get(0).name
|
||||
//=> li
|
||||
```
|
||||
|
||||
If no index is specified, retrieve all elements matched by the Cheerio object:
|
||||
|
||||
```js
|
||||
$('li').get().length
|
||||
//=> 3
|
||||
```
|
||||
|
||||
#### .end()
|
||||
End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.
|
||||
|
||||
```js
|
||||
$('li').eq(0).end().length
|
||||
//=> 3
|
||||
```
|
||||
|
||||
#### .add( selector [, context] )
|
||||
#### .add( element )
|
||||
#### .add( elements )
|
||||
#### .add( html )
|
||||
#### .add( selection )
|
||||
Add elements to the set of matched elements.
|
||||
|
||||
```js
|
||||
$('.apple').add('.orange').length
|
||||
//=> 2
|
||||
```
|
||||
|
||||
### Manipulation
|
||||
Methods for modifying the DOM structure.
|
||||
|
||||
#### .append( content, [content, ...] )
|
||||
Inserts content as the *last* child of each of the selected elements.
|
||||
|
||||
```js
|
||||
$('ul').append('<li class="plum">Plum</li>')
|
||||
$.html()
|
||||
//=> <ul id="fruits">
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// <li class="pear">Pear</li>
|
||||
// <li class="plum">Plum</li>
|
||||
// </ul>
|
||||
```
|
||||
|
||||
#### .prepend( content, [content, ...] )
|
||||
Inserts content as the *first* child of each of the selected elements.
|
||||
|
||||
```js
|
||||
$('ul').prepend('<li class="plum">Plum</li>')
|
||||
$.html()
|
||||
//=> <ul id="fruits">
|
||||
// <li class="plum">Plum</li>
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// <li class="pear">Pear</li>
|
||||
// </ul>
|
||||
```
|
||||
|
||||
#### .after( content, [content, ...] )
|
||||
Insert content next to each element in the set of matched elements.
|
||||
|
||||
```js
|
||||
$('.apple').after('<li class="plum">Plum</li>')
|
||||
$.html()
|
||||
//=> <ul id="fruits">
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="plum">Plum</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// <li class="pear">Pear</li>
|
||||
// </ul>
|
||||
```
|
||||
|
||||
#### .before( content, [content, ...] )
|
||||
Insert content previous to each element in the set of matched elements.
|
||||
|
||||
```js
|
||||
$('.apple').before('<li class="plum">Plum</li>')
|
||||
$.html()
|
||||
//=> <ul id="fruits">
|
||||
// <li class="plum">Plum</li>
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// <li class="pear">Pear</li>
|
||||
// </ul>
|
||||
```
|
||||
|
||||
#### .remove( [selector] )
|
||||
Removes the set of matched elements from the DOM and all their children. `selector` filters the set of matched elements to be removed.
|
||||
|
||||
```js
|
||||
$('.pear').remove()
|
||||
$.html()
|
||||
//=> <ul id="fruits">
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// </ul>
|
||||
```
|
||||
|
||||
#### .replaceWith( content )
|
||||
Replaces matched elements with `content`.
|
||||
|
||||
```js
|
||||
var plum = $('<li class="plum">Plum</li>')
|
||||
$('.pear').replaceWith(plum)
|
||||
$.html()
|
||||
//=> <ul id="fruits">
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// <li class="plum">Plum</li>
|
||||
// </ul>
|
||||
```
|
||||
|
||||
#### .empty()
|
||||
Empties an element, removing all it's children.
|
||||
|
||||
```js
|
||||
$('ul').empty()
|
||||
$.html()
|
||||
//=> <ul id="fruits"></ul>
|
||||
```
|
||||
|
||||
#### .html( [htmlString] )
|
||||
Gets an html content string from the first selected element. If `htmlString` is specified, each selected element's content is replaced by the new content.
|
||||
|
||||
```js
|
||||
$('.orange').html()
|
||||
//=> Orange
|
||||
|
||||
$('#fruits').html('<li class="mango">Mango</li>').html()
|
||||
//=> <li class="mango">Mango</li>
|
||||
```
|
||||
|
||||
#### .text( [textString] )
|
||||
Get the combined text contents of each element in the set of matched elements, including their descendants.. If `textString` is specified, each selected element's content is replaced by the new text content.
|
||||
|
||||
```js
|
||||
$('.orange').text()
|
||||
//=> Orange
|
||||
|
||||
$('ul').text()
|
||||
//=> Apple
|
||||
// Orange
|
||||
// Pear
|
||||
```
|
||||
|
||||
#### .css( [propertName] ) <br /> .css( [ propertyNames] ) <br /> .css( [propertyName], [value] ) <br /> .css( [propertName], [function] ) <br /> .css( [properties] )
|
||||
|
||||
Get the value of a style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.
|
||||
|
||||
### Rendering
|
||||
When you're ready to render the document, you can use the `html` utility function:
|
||||
|
||||
```js
|
||||
$.html()
|
||||
//=> <ul id="fruits">
|
||||
// <li class="apple">Apple</li>
|
||||
// <li class="orange">Orange</li>
|
||||
// <li class="pear">Pear</li>
|
||||
// </ul>
|
||||
```
|
||||
|
||||
If you want to return the outerHTML you can use `$.html(selector)`:
|
||||
|
||||
```js
|
||||
$.html('.pear')
|
||||
//=> <li class="pear">Pear</li>
|
||||
```
|
||||
|
||||
By default, `html` will leave some tags open. Sometimes you may instead want to render a valid XML document. For example, you might parse the following XML snippet:
|
||||
|
||||
```xml
|
||||
$ = cheerio.load('<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123"/>');
|
||||
```
|
||||
|
||||
... and later want to render to XML. To do this, you can use the 'xml' utility function:
|
||||
|
||||
```js
|
||||
$.xml()
|
||||
//=> <media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123"/>
|
||||
```
|
||||
|
||||
|
||||
### Miscellaneous
|
||||
DOM element methods that don't fit anywhere else
|
||||
|
||||
#### .clone() ####
|
||||
Clone the cheerio object.
|
||||
|
||||
```js
|
||||
var moreFruit = $('#fruits').clone()
|
||||
```
|
||||
|
||||
### Utilities
|
||||
|
||||
#### $.root
|
||||
|
||||
Sometimes you need to work with the top-level root element. To query it, you can use `$.root()`.
|
||||
|
||||
```js
|
||||
$.root().append('<ul id="vegetables"></ul>').html();
|
||||
//=> <ul id="fruits">...</ul><ul id="vegetables"></ul>
|
||||
```
|
||||
|
||||
#### $.contains( container, contained )
|
||||
Checks to see if the `contained` DOM element is a descendent of the `container` DOM element.
|
||||
|
||||
#### $.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 compatability.
|
||||
|
||||
## Screencasts
|
||||
|
||||
http://vimeo.com/31950192
|
||||
|
||||
> This video tutorial is a follow-up to Nettut's "How to Scrape Web Pages with Node.js and jQuery", using cheerio instead of JSDOM + jQuery. This video shows how easy it is to use cheerio and how much faster cheerio is than JSDOM + jQuery.
|
||||
|
||||
## Test Coverage
|
||||
|
||||
Cheerio has high-test coverage, you can view the report [here](https://s3.amazonaws.com/MattMueller/Coverage/cheerio.html).
|
||||
|
||||
## Testing
|
||||
|
||||
To run the test suite, download the repository, then within the cheerio directory, run:
|
||||
|
||||
```shell
|
||||
make setup
|
||||
make test
|
||||
```
|
||||
|
||||
This will download the development packages and run the test suite.
|
||||
|
||||
## Contributors
|
||||
|
||||
These are some of the contributors that have made cheerio possible:
|
||||
|
||||
```
|
||||
project : cheerio
|
||||
repo age : 2 years, 6 months
|
||||
active : 285 days
|
||||
commits : 762
|
||||
files : 36
|
||||
authors :
|
||||
293 Matt Mueller 38.5%
|
||||
133 Matthew Mueller 17.5%
|
||||
92 Mike Pennisi 12.1%
|
||||
54 David Chambers 7.1%
|
||||
30 kpdecker 3.9%
|
||||
19 Felix Böhm 2.5%
|
||||
17 fb55 2.2%
|
||||
15 Siddharth Mahendraker 2.0%
|
||||
11 Adam Bretz 1.4%
|
||||
8 Nazar Leush 1.0%
|
||||
7 ironchefpython 0.9%
|
||||
6 Jarno Leppänen 0.8%
|
||||
5 Ben Sheldon 0.7%
|
||||
5 Jos Shepherd 0.7%
|
||||
5 Ryan Schmukler 0.7%
|
||||
5 Steven Vachon 0.7%
|
||||
4 Maciej Adwent 0.5%
|
||||
4 Amir Abu Shareb 0.5%
|
||||
3 jeremy.dentel@brandingbrand.com 0.4%
|
||||
3 Andi Neck 0.4%
|
||||
2 steve 0.3%
|
||||
2 alexbardas 0.3%
|
||||
2 finspin 0.3%
|
||||
2 Ali Farhadi 0.3%
|
||||
2 Chris Khoo 0.3%
|
||||
2 Rob Ashton 0.3%
|
||||
2 Thomas Heymann 0.3%
|
||||
2 Jaro Spisak 0.3%
|
||||
2 Dan Dascalescu 0.3%
|
||||
2 Torstein Thune 0.3%
|
||||
2 Wayne Larsen 0.3%
|
||||
1 Timm Preetz 0.1%
|
||||
1 Xavi 0.1%
|
||||
1 Alex Shaindlin 0.1%
|
||||
1 mattym 0.1%
|
||||
1 Felix Böhm 0.1%
|
||||
1 Farid Neshat 0.1%
|
||||
1 Dmitry Mazuro 0.1%
|
||||
1 Jeremy Hubble 0.1%
|
||||
1 nevermind 0.1%
|
||||
1 Manuel Alabor 0.1%
|
||||
1 Matt Liegey 0.1%
|
||||
1 Chris O'Hara 0.1%
|
||||
1 Michael Holroyd 0.1%
|
||||
1 Michiel De Mey 0.1%
|
||||
1 Ben Atkin 0.1%
|
||||
1 Rich Trott 0.1%
|
||||
1 Rob "Hurricane" Ashton 0.1%
|
||||
1 Robin Gloster 0.1%
|
||||
1 Simon Boudrias 0.1%
|
||||
1 Sindre Sorhus 0.1%
|
||||
1 xiaohwan 0.1%
|
||||
```
|
||||
|
||||
## Special Thanks
|
||||
|
||||
This library stands on the shoulders of some incredible developers. A special thanks to:
|
||||
|
||||
__• @FB55 for node-htmlparser2 & CSSSelect:__
|
||||
Felix has a knack for writing speedy parsing engines. He completely re-wrote both @tautologistic's `node-htmlparser` and @harry's `node-soupselect` from the ground up, making both of them much faster and more flexible. Cheerio would not be possible without his foundational work
|
||||
|
||||
__• @jQuery team for jQuery:__
|
||||
The core API is the best of its class and despite dealing with all the browser inconsistencies the code base is extremely clean and easy to follow. Much of cheerio's implementation and documentation is from jQuery. Thanks guys.
|
||||
|
||||
__• @visionmedia:__
|
||||
The style, the structure, the open-source"-ness" of this library comes from studying TJ's style and using many of his libraries. This dude consistently pumps out high-quality libraries and has always been more than willing to help or answer questions. You rock TJ.
|
||||
|
||||
## License
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012 Matt Mueller <mattmuelle@gmail.com>
|
||||
|
||||
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.
|
11
node_modules/gitbook-plugin-multipart/node_modules/cheerio/index.js
generated
vendored
Normal file
11
node_modules/gitbook-plugin-multipart/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').version;
|
413
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/attributes.js
generated
vendored
Normal file
413
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/attributes.js
generated
vendored
Normal file
@@ -0,0 +1,413 @@
|
||||
var _ = require('lodash'),
|
||||
utils = require('../utils'),
|
||||
isTag = utils.isTag,
|
||||
domEach = utils.domEach,
|
||||
hasOwn = Object.prototype.hasOwnProperty,
|
||||
camelCase = utils.camelCase,
|
||||
cssCase = utils.cssCase,
|
||||
rspace = /\s+/,
|
||||
dataAttrPrefix = 'data-',
|
||||
|
||||
// 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 elem.attribs[name];
|
||||
}
|
||||
};
|
||||
|
||||
var setAttr = function(el, name, value) {
|
||||
|
||||
if (value === null) {
|
||||
removeAttribute(el, name);
|
||||
} else {
|
||||
el.attribs[name] = value+'';
|
||||
}
|
||||
};
|
||||
|
||||
var attr = 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') {
|
||||
_.each(name, function(name, key) {
|
||||
el.attribs[key] = name+'';
|
||||
});
|
||||
} else {
|
||||
setAttr(el, name, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return getAttr(this[0], name);
|
||||
};
|
||||
|
||||
var setData = function(el, name, value) {
|
||||
if (typeof name === 'object') return _.extend(el.data, name);
|
||||
if (typeof name === 'string' && value !== undefined) {
|
||||
el.data[name] = value;
|
||||
} else if (typeof name === 'object') {
|
||||
_.exend(el.data, name);
|
||||
}
|
||||
};
|
||||
|
||||
// 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)) {
|
||||
value = JSON.parse(value);
|
||||
}
|
||||
|
||||
el.data[jsName] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return readAll ? el.data : value;
|
||||
};
|
||||
|
||||
var data = 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
|
||||
*/
|
||||
|
||||
var val = 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':
|
||||
var queryString = 'input[type=radio][name=' + this.attr('name') + ']:checked';
|
||||
var parentEl, root;
|
||||
|
||||
// Go up until we hit a form or root
|
||||
parentEl = this.closest('form');
|
||||
if (parentEl.length === 0) {
|
||||
root = (this.parents().last()[0] || this[0]).root;
|
||||
parentEl = this._make(root);
|
||||
}
|
||||
|
||||
if (querying) {
|
||||
return parentEl.find(queryString).attr('value');
|
||||
} else {
|
||||
parentEl.find(':checked').removeAttr('checked');
|
||||
parentEl.find('input[type=radio][value="' + value + '"]').attr('checked', '');
|
||||
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 (!this.attr().hasOwnProperty('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 (this.attr().hasOwnProperty('multiple')) {
|
||||
returnValue = [];
|
||||
domEach(option, function(i, el) {
|
||||
returnValue.push(el.attribs.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;
|
||||
|
||||
if (name === elem.attribs[name] && rboolean.test(elem.attribs[name]))
|
||||
elem.attribs[name] = false;
|
||||
else
|
||||
delete elem.attribs[name];
|
||||
};
|
||||
|
||||
|
||||
var removeAttr = exports.removeAttr = function(name) {
|
||||
domEach(this, function(i, elem) {
|
||||
removeAttribute(elem, name);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
var hasClass = exports.hasClass = function(className) {
|
||||
return _.any(this, function(elem) {
|
||||
var attrs = elem.attribs,
|
||||
clazz = attrs && attrs['class'],
|
||||
idx = -1,
|
||||
end;
|
||||
|
||||
if (clazz) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var addClass = exports.addClass = function(value) {
|
||||
// Support functions
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
var className = el.attribs['class'] || '';
|
||||
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))
|
||||
setClass += appendClass;
|
||||
}
|
||||
|
||||
setAttr(this[i], 'class', setClass.trim());
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
var splitClass = function(className) {
|
||||
return className ? className.trim().split(rspace) : [];
|
||||
};
|
||||
|
||||
var removeClass = exports.removeClass = function(value) {
|
||||
var classes,
|
||||
numClasses,
|
||||
removeAll;
|
||||
|
||||
// Handle if value is a function
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
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(' ');
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var toggleClass = exports.toggleClass = function(value, stateVal) {
|
||||
// Support functions
|
||||
if (typeof value === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
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;
|
||||
};
|
||||
|
||||
var is = exports.is = function (selector) {
|
||||
if (selector) {
|
||||
return this.filter(selector).length > 0;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
118
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/css.js
generated
vendored
Normal file
118
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/css.js
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
var _ = require('lodash'),
|
||||
domEach = require('../utils').domEach;
|
||||
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, el);
|
||||
}
|
||||
|
||||
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;
|
||||
}, {});
|
||||
}
|
304
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/manipulation.js
generated
vendored
Normal file
304
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/manipulation.js
generated
vendored
Normal file
@@ -0,0 +1,304 @@
|
||||
var _ = require('lodash'),
|
||||
parse = require('../parse'),
|
||||
$ = require('../static'),
|
||||
updateDOM = parse.update,
|
||||
evaluate = parse.evaluate,
|
||||
utils = require('../utils'),
|
||||
domEach = utils.domEach,
|
||||
encode = utils.encode,
|
||||
slice = Array.prototype.slice;
|
||||
|
||||
// Create an array of nodes, recursing into arrays and parsing strings if
|
||||
// necessary
|
||||
exports._makeDomArray = function makeDomArray(elem) {
|
||||
if (elem == null) {
|
||||
return [];
|
||||
} else if (elem.cheerio) {
|
||||
return elem.get();
|
||||
} else if (Array.isArray(elem)) {
|
||||
return _.flatten(elem.map(makeDomArray, this));
|
||||
} else if (typeof elem === 'string') {
|
||||
return evaluate(elem, this.options);
|
||||
} else {
|
||||
return [elem];
|
||||
}
|
||||
};
|
||||
|
||||
var _insert = function(concatenator) {
|
||||
return function() {
|
||||
var self = this,
|
||||
elems = slice.call(arguments),
|
||||
dom = this._makeDomArray(elems);
|
||||
|
||||
if (typeof elems[0] === 'function') {
|
||||
return domEach(this, function(i, el) {
|
||||
dom = self._makeDomArray(elems[0].call(el, i, $.html(el.children)));
|
||||
concatenator(dom, el.children, el);
|
||||
});
|
||||
} else {
|
||||
return domEach(this, function(i, el) {
|
||||
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);
|
||||
};
|
||||
|
||||
var append = exports.append = _insert(function(dom, children, parent) {
|
||||
uniqueSplice(children, children.length, 0, dom, parent);
|
||||
});
|
||||
|
||||
var prepend = exports.prepend = _insert(function(dom, children, parent) {
|
||||
uniqueSplice(children, 0, 0, dom, parent);
|
||||
});
|
||||
|
||||
var after = exports.after = function() {
|
||||
var elems = slice.call(arguments),
|
||||
dom = this._makeDomArray(elems),
|
||||
self = this;
|
||||
|
||||
domEach(this, function(i, el) {
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
index = siblings.indexOf(el);
|
||||
|
||||
// If not found, move on
|
||||
if (!~index) return;
|
||||
|
||||
if (typeof elems[0] === 'function') {
|
||||
dom = self._makeDomArray(elems[0].call(el, i));
|
||||
}
|
||||
|
||||
// Add element after `this` element
|
||||
uniqueSplice(siblings, ++index, 0, dom, parent);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
var before = exports.before = function() {
|
||||
var elems = slice.call(arguments),
|
||||
dom = this._makeDomArray(elems),
|
||||
self = this;
|
||||
|
||||
domEach(this, function(i, el) {
|
||||
var parent = el.parent || el.root;
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
var siblings = parent.children,
|
||||
index = siblings.indexOf(el);
|
||||
|
||||
// If not found, move on
|
||||
if (!~index) return;
|
||||
|
||||
if (typeof elems[0] === 'function') {
|
||||
dom = self._makeDomArray(elems[0].call(el, i));
|
||||
}
|
||||
|
||||
// Add element before `el` element
|
||||
uniqueSplice(siblings, index, 0, dom, parent);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
remove([selector])
|
||||
*/
|
||||
var remove = 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) 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;
|
||||
};
|
||||
|
||||
var replaceWith = 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;
|
||||
};
|
||||
|
||||
var empty = exports.empty = function() {
|
||||
domEach(this, function(i, el) {
|
||||
_.each(el.children, function(el) {
|
||||
el.next = el.prev = el.parent = null;
|
||||
});
|
||||
|
||||
el.children.length = 0;
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set/Get the HTML
|
||||
*/
|
||||
var 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) {
|
||||
_.each(el.children, function(el) {
|
||||
el.next = el.prev = el.parent = null;
|
||||
});
|
||||
|
||||
var content = str.cheerio ? str.clone().get() : evaluate(str, opts);
|
||||
|
||||
updateDOM(content, el);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
var toString = exports.toString = function() {
|
||||
return $.html(this);
|
||||
};
|
||||
|
||||
var text = 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 text.call($el, str.call(el, i, $.text($el)));
|
||||
});
|
||||
}
|
||||
|
||||
// Append text node to each selected elements
|
||||
domEach(this, function(i, el) {
|
||||
_.each(el.children, function(el) {
|
||||
el.next = el.prev = el.parent = null;
|
||||
});
|
||||
|
||||
var elem = {
|
||||
data: str,
|
||||
type: 'text',
|
||||
parent: el,
|
||||
prev: null,
|
||||
next: null,
|
||||
children: []
|
||||
};
|
||||
|
||||
updateDOM(elem, el);
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
var clone = exports.clone = function() {
|
||||
// Turn it into HTML, then recreate it,
|
||||
// Seems to be the easiest way to reconnect everything correctly
|
||||
return this._make($.html(this));
|
||||
};
|
361
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/traversing.js
generated
vendored
Normal file
361
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/api/traversing.js
generated
vendored
Normal file
@@ -0,0 +1,361 @@
|
||||
var _ = require('lodash'),
|
||||
select = require('CSSselect'),
|
||||
utils = require('../utils'),
|
||||
domEach = utils.domEach,
|
||||
uniqueSort = require('htmlparser2').DomUtils.uniqueSort,
|
||||
isTag = utils.isTag;
|
||||
|
||||
var find = exports.find = function(selector) {
|
||||
var elems = _.reduce(this, function(memo, elem) {
|
||||
return memo.concat(_.filter(elem.children, isTag));
|
||||
}, []);
|
||||
|
||||
return this._make(select(selector, elems, this.options));
|
||||
};
|
||||
|
||||
// Get the parent of each element in the current set of matched elements,
|
||||
// optionally filtered by a selector.
|
||||
var parent = exports.parent = function(selector) {
|
||||
var set = [];
|
||||
var $set;
|
||||
|
||||
domEach(this, function(idx, elem) {
|
||||
var parentElem = elem.parent;
|
||||
if (parentElem && set.indexOf(parentElem) < 0) {
|
||||
set.push(parentElem);
|
||||
}
|
||||
});
|
||||
|
||||
if (arguments.length) {
|
||||
set = filter.call(set, selector, this);
|
||||
}
|
||||
|
||||
return this._make(set);
|
||||
};
|
||||
|
||||
var parents = 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);
|
||||
};
|
||||
|
||||
var parentsUntil = 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.
|
||||
var closest = 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);
|
||||
};
|
||||
|
||||
var next = 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 ? filter.call(elems, selector, this) : this._make(elems);
|
||||
};
|
||||
|
||||
var nextAll = 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 ? filter.call(elems, selector, this) : this._make(elems);
|
||||
};
|
||||
|
||||
var nextUntil = 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 ?
|
||||
filter.call(elems, filterSelector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
var prev = 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 ? filter.call(elems, selector, this) : this._make(elems);
|
||||
};
|
||||
|
||||
var prevAll = 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 ? filter.call(elems, selector, this) : this._make(elems);
|
||||
};
|
||||
|
||||
var prevUntil = 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 ?
|
||||
filter.call(elems, filterSelector, this) :
|
||||
this._make(elems);
|
||||
};
|
||||
|
||||
var siblings = exports.siblings = function(selector) {
|
||||
var parent = this.parent();
|
||||
|
||||
var elems = _.filter(
|
||||
parent ? parent.children() : this.siblingsAndMe(),
|
||||
function(elem) { return isTag(elem) && !this.is(elem); },
|
||||
this
|
||||
);
|
||||
|
||||
if (selector !== undefined) {
|
||||
return filter.call(elems, selector, this);
|
||||
} else {
|
||||
return this._make(elems);
|
||||
}
|
||||
};
|
||||
|
||||
var children = 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);
|
||||
else if (typeof selector === 'number') return this._make(elems[selector]);
|
||||
|
||||
return filter.call(elems, selector, this);
|
||||
};
|
||||
|
||||
var contents = exports.contents = function() {
|
||||
return this._make(_.reduce(this, function(all, elem) {
|
||||
all.push.apply(all, elem.children);
|
||||
return all;
|
||||
}, []));
|
||||
};
|
||||
|
||||
var each = exports.each = function(fn) {
|
||||
var i = 0, len = this.length;
|
||||
while (i < len && fn.call(this[i], i, this[i]) !== false) ++i;
|
||||
return this;
|
||||
};
|
||||
|
||||
var map = 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 filter = exports.filter = function(match, container) {
|
||||
container = container || this;
|
||||
|
||||
var make = _.bind(container._make, container);
|
||||
var filterFn;
|
||||
|
||||
if (typeof match === 'string') {
|
||||
filterFn = select.compile(match, container.options);
|
||||
} else if (typeof match === 'function') {
|
||||
filterFn = function(el, i) {
|
||||
return match.call(el, i, el);
|
||||
};
|
||||
} else if (match.cheerio) {
|
||||
filterFn = match.is.bind(match);
|
||||
} else {
|
||||
filterFn = function(el) {
|
||||
return match === el;
|
||||
};
|
||||
}
|
||||
|
||||
return make(_.filter(this, filterFn));
|
||||
};
|
||||
|
||||
var first = exports.first = function() {
|
||||
return this.length > 1 ? this._make(this[0]) : this;
|
||||
};
|
||||
|
||||
var last = 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.
|
||||
var eq = 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.
|
||||
var get = exports.get = function(i) {
|
||||
if (i == null) {
|
||||
return Array.prototype.slice.call(this);
|
||||
} else {
|
||||
return this[i < 0 ? (this.length + i) : i];
|
||||
}
|
||||
};
|
||||
|
||||
var slice = 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 || 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.
|
||||
var end = exports.end = function() {
|
||||
return this.prevObject || this._make([]);
|
||||
};
|
||||
|
||||
var add = 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;
|
||||
};
|
161
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/cheerio.js
generated
vendored
Normal file
161
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/cheerio.js
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
Module dependencies
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
parse = require('./parse'),
|
||||
_ = require('lodash');
|
||||
|
||||
/*
|
||||
* The API
|
||||
*/
|
||||
|
||||
var api = [
|
||||
require('./api/attributes'),
|
||||
require('./api/traversing'),
|
||||
require('./api/manipulation'),
|
||||
require('./api/css')
|
||||
];
|
||||
|
||||
/*
|
||||
* A simple way to check for HTML strings or ID strings
|
||||
*/
|
||||
|
||||
var quickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/;
|
||||
|
||||
/*
|
||||
* 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(options || {}, this.options);
|
||||
|
||||
// $(), $(null), $(undefined), $(false)
|
||||
if (!selector) return this;
|
||||
|
||||
if (root) {
|
||||
if (typeof root === 'string') root = parse(root, this.options);
|
||||
this._root = Cheerio.call(this, root);
|
||||
}
|
||||
|
||||
// $($)
|
||||
if (selector.cheerio) return selector;
|
||||
|
||||
// $(dom)
|
||||
if (isNode(selector))
|
||||
selector = [selector];
|
||||
|
||||
// $([dom])
|
||||
if (Array.isArray(selector)) {
|
||||
_.forEach(selector, 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).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);
|
||||
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]';
|
||||
|
||||
/*
|
||||
* Cheerio default options
|
||||
*/
|
||||
|
||||
Cheerio.prototype.options = {
|
||||
normalizeWhitespace: false,
|
||||
xmlMode: false,
|
||||
decodeEntities: true
|
||||
};
|
||||
|
||||
/*
|
||||
* Make cheerio an array-like object
|
||||
*/
|
||||
|
||||
Cheerio.prototype.length = 0;
|
||||
Cheerio.prototype.splice = Array.prototype.splice;
|
||||
|
||||
/*
|
||||
* Check if string is HTML
|
||||
*/
|
||||
var 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]);
|
||||
};
|
||||
|
||||
/*
|
||||
* Make a cheerio object
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
Cheerio.prototype._make = function(dom, context) {
|
||||
var cheerio = new Cheerio(dom, context, this._root, this.options);
|
||||
cheerio.prevObject = this;
|
||||
return cheerio;
|
||||
};
|
||||
|
||||
/**
|
||||
* Turn a cheerio object into an array
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
|
||||
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';
|
||||
};
|
93
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/parse.js
generated
vendored
Normal file
93
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/parse.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
Module Dependencies
|
||||
*/
|
||||
var htmlparser = require('htmlparser2'),
|
||||
utils = require('./utils');
|
||||
|
||||
/*
|
||||
Parser
|
||||
*/
|
||||
exports = module.exports = function(content, options) {
|
||||
var dom = evaluate(content, options);
|
||||
|
||||
// Generic root element
|
||||
var root = {
|
||||
type: 'root',
|
||||
name: 'root',
|
||||
parent: null,
|
||||
prev: null,
|
||||
next: null,
|
||||
children: []
|
||||
};
|
||||
|
||||
// Update the dom using the root
|
||||
update(dom, root);
|
||||
|
||||
return root;
|
||||
};
|
||||
|
||||
var evaluate = exports.evaluate = function(content, options) {
|
||||
// options = options || $.fn.options;
|
||||
|
||||
var dom;
|
||||
|
||||
if (typeof content === 'string' || Buffer.isBuffer(content)) {
|
||||
dom = htmlparser.parseDOM(content, options);
|
||||
} else {
|
||||
dom = content;
|
||||
}
|
||||
|
||||
return dom;
|
||||
};
|
||||
|
||||
/*
|
||||
Update the dom structure, for one changed layer
|
||||
*/
|
||||
var update = 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);
|
156
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/static.js
generated
vendored
Normal file
156
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/static.js
generated
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
var select = require('CSSselect'),
|
||||
parse = require('./parse'),
|
||||
render = require('dom-serializer'),
|
||||
_ = require('lodash');
|
||||
|
||||
/**
|
||||
* $.load(str)
|
||||
*/
|
||||
|
||||
var load = exports.load = function(content, options) {
|
||||
var Cheerio = require('./cheerio');
|
||||
|
||||
options = _.defaults(options || {}, Cheerio.prototype.options);
|
||||
|
||||
var root = parse(content, options);
|
||||
|
||||
var initialize = function(selector, context, r, opts) {
|
||||
opts = _.defaults(opts || {}, options);
|
||||
return new Cheerio(selector, context, r || root, opts);
|
||||
};
|
||||
|
||||
// Add in the static methods
|
||||
initialize.__proto__ = exports;
|
||||
|
||||
// Add in the root
|
||||
initialize._root = root;
|
||||
// store options
|
||||
initialize._options = options;
|
||||
|
||||
return initialize;
|
||||
};
|
||||
|
||||
/**
|
||||
* $.html([selector | dom])
|
||||
*/
|
||||
|
||||
var html = exports.html = function(dom, options) {
|
||||
var Cheerio = require('./cheerio');
|
||||
|
||||
// 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(options || {}, this._options, Cheerio.prototype.options);
|
||||
|
||||
if (dom) {
|
||||
dom = (typeof dom === 'string') ? select(dom, this._root, options) : dom;
|
||||
return render(dom, options);
|
||||
} else if (this._root && this._root.children) {
|
||||
return render(this._root.children, options);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* $.xml([selector | dom])
|
||||
*/
|
||||
|
||||
var xml = exports.xml = function(dom) {
|
||||
if (dom) {
|
||||
dom = (typeof dom === 'string') ? select(dom, this._root, this.options) : dom;
|
||||
return render(dom, { xmlMode: true });
|
||||
} else if (this._root && this._root.children) {
|
||||
return render(this._root.children, { xmlMode: true });
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* $.text(dom)
|
||||
*/
|
||||
|
||||
var text = exports.text = function(elems) {
|
||||
if (!elems) return '';
|
||||
|
||||
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') {
|
||||
ret += 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.
|
||||
*/
|
||||
var parseHTML = 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);
|
||||
if (!keepScripts) {
|
||||
parsed('script').remove();
|
||||
}
|
||||
|
||||
return parsed.root()[0].children;
|
||||
};
|
||||
|
||||
/**
|
||||
* $.root()
|
||||
*/
|
||||
var root = exports.root = function() {
|
||||
return this(this._root);
|
||||
};
|
||||
|
||||
/**
|
||||
* $.contains()
|
||||
*/
|
||||
var 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;
|
||||
};
|
51
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/utils.js
generated
vendored
Normal file
51
node_modules/gitbook-plugin-multipart/node_modules/cheerio/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 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(i, cheerio[i]) !== false) ++i;
|
||||
return cheerio;
|
||||
};
|
106
node_modules/gitbook-plugin-multipart/node_modules/cheerio/package.json
generated
vendored
Normal file
106
node_modules/gitbook-plugin-multipart/node_modules/cheerio/package.json
generated
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "cheerio",
|
||||
"raw": "cheerio@0.17.0",
|
||||
"rawSpec": "0.17.0",
|
||||
"scope": null,
|
||||
"spec": "0.17.0",
|
||||
"type": "version"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart"
|
||||
]
|
||||
],
|
||||
"_from": "cheerio@0.17.0",
|
||||
"_id": "cheerio@0.17.0",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/gitbook-plugin-multipart/cheerio",
|
||||
"_npmUser": {
|
||||
"email": "dc@davidchambers.me",
|
||||
"name": "davidchambers"
|
||||
},
|
||||
"_npmVersion": "1.4.14",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "cheerio",
|
||||
"raw": "cheerio@0.17.0",
|
||||
"rawSpec": "0.17.0",
|
||||
"scope": null,
|
||||
"spec": "0.17.0",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gitbook-plugin-multipart"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/cheerio/-/cheerio-0.17.0.tgz",
|
||||
"_shasum": "fa5ae42cc60121133d296d0b46d983215f7268ea",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "cheerio@0.17.0",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart",
|
||||
"author": {
|
||||
"email": "mattmuelle@gmail.com",
|
||||
"name": "Matt Mueller",
|
||||
"url": "mat.io"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/MatthewMueller/cheerio/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"CSSselect": "~0.4.0",
|
||||
"dom-serializer": "~0.0.0",
|
||||
"entities": "~1.1.1",
|
||||
"htmlparser2": "~3.7.2",
|
||||
"lodash": "~2.4.1"
|
||||
},
|
||||
"description": "Tiny, fast, and elegant implementation of core jQuery designed specifically for the server",
|
||||
"devDependencies": {
|
||||
"benchmark": "~1.0.0",
|
||||
"expect.js": "~0.3.1",
|
||||
"jsdom": "~0.8.9",
|
||||
"jshint": "~2.3.0",
|
||||
"mocha": "*",
|
||||
"xyz": "~0.3.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "fa5ae42cc60121133d296d0b46d983215f7268ea",
|
||||
"tarball": "https://registry.npmjs.org/cheerio/-/cheerio-0.17.0.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
},
|
||||
"gitHead": "3210b2287a9fd3b1ec0bcc656092b12c08c2916c",
|
||||
"homepage": "https://github.com/MatthewMueller/cheerio",
|
||||
"keywords": [
|
||||
"htmlparser",
|
||||
"jquery",
|
||||
"selector",
|
||||
"scraper",
|
||||
"parser",
|
||||
"html"
|
||||
],
|
||||
"main": "./index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "mattmuelle@gmail.com",
|
||||
"name": "mattmueller"
|
||||
},
|
||||
{
|
||||
"email": "dc@davidchambers.me",
|
||||
"name": "davidchambers"
|
||||
}
|
||||
],
|
||||
"name": "cheerio",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/MatthewMueller/cheerio.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "make test"
|
||||
},
|
||||
"version": "0.17.0"
|
||||
}
|
15
node_modules/gitbook-plugin-multipart/node_modules/cheerio/scripts/prepublish
generated
vendored
Normal file
15
node_modules/gitbook-plugin-multipart/node_modules/cheerio/scripts/prepublish
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
tmp="$(mktemp -t "$(basename "$0").XXXXXXXXXX")"
|
||||
|
||||
printf "
|
||||
$VERSION / $(date +"%Y-%m-%d")
|
||||
==================
|
||||
|
||||
$(git --no-pager log --no-merges --pretty="format: * %s (%an)" $PREVIOUS_VERSION..)
|
||||
" >"$tmp"
|
||||
|
||||
cat History.md >>"$tmp"
|
||||
mv "$tmp" History.md
|
||||
git add History.md
|
662
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.attributes.js
generated
vendored
Normal file
662
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.attributes.js
generated
vendored
Normal file
@@ -0,0 +1,662 @@
|
||||
var expect = require('expect.js');
|
||||
|
||||
var cheerio = require('..');
|
||||
var fruits = require('./fixtures').fruits;
|
||||
var vegetables = require('./fixtures').vegetables;
|
||||
var food = require('./fixtures').food;
|
||||
var chocolates = require('./fixtures').chocolates;
|
||||
var inputs = require('./fixtures').inputs;
|
||||
var toArray = Function.call.bind(Array.prototype.slice);
|
||||
|
||||
describe('$(...)', function() {
|
||||
var $;
|
||||
|
||||
beforeEach(function() {
|
||||
$ = cheerio.load(fruits);
|
||||
});
|
||||
|
||||
describe('.attr', function() {
|
||||
|
||||
it('() : should get all the attributes', function() {
|
||||
var attrs = $('ul').attr();
|
||||
expect(attrs.id).to.equal('fruits');
|
||||
});
|
||||
|
||||
it('(invalid key) : invalid attr should get undefined', function() {
|
||||
var attr = $('.apple').attr('lol');
|
||||
expect(attr).to.be(undefined);
|
||||
});
|
||||
|
||||
it('(valid key) : valid attr should get value', function() {
|
||||
var cls = $('.apple').attr('class');
|
||||
expect(cls).to.equal('apple');
|
||||
});
|
||||
|
||||
it('(key, value) : should set attr', function() {
|
||||
var $pear = $('.pear').attr('id', 'pear');
|
||||
expect($('#pear')).to.have.length(1);
|
||||
expect($pear.cheerio).to.not.be(undefined);
|
||||
});
|
||||
|
||||
it('(key, value) : should set attr', function() {
|
||||
var $el = cheerio('<div></div> <div></div>').attr('class', 'pear');
|
||||
|
||||
expect($el[0].attribs['class']).to.equal('pear');
|
||||
expect($el[1].attribs).to.equal(undefined);
|
||||
expect($el[2].attribs['class']).to.equal('pear');
|
||||
});
|
||||
|
||||
it('(key, value) : should return an empty object for an empty object', function() {
|
||||
var $src = $().attr('key', 'value');
|
||||
expect($src.length).to.equal(0);
|
||||
expect($src[0]).to.be(undefined);
|
||||
});
|
||||
|
||||
it('(map) : object map should set multiple attributes', function() {
|
||||
$('.apple').attr({
|
||||
id: 'apple',
|
||||
style: 'color:red;',
|
||||
'data-url': 'http://apple.com'
|
||||
});
|
||||
var attrs = $('.apple').attr();
|
||||
expect(attrs.id).to.equal('apple');
|
||||
expect(attrs.style).to.equal('color:red;');
|
||||
expect(attrs['data-url']).to.equal('http://apple.com');
|
||||
});
|
||||
|
||||
it('(key, function) : should call the function and update the attribute with the return value', function() {
|
||||
var $fruits = $('#fruits');
|
||||
$fruits.attr('id', function(index, value) {
|
||||
expect(index).to.equal(0);
|
||||
expect(value).to.equal('fruits');
|
||||
return 'ninja';
|
||||
});
|
||||
var attrs = $fruits.attr();
|
||||
expect(attrs.id).to.equal('ninja');
|
||||
});
|
||||
|
||||
it('(key, value) : should correctly encode then decode unsafe values', function() {
|
||||
var $apple = $('.apple');
|
||||
$apple.attr('href', 'http://github.com/"><script>alert("XSS!")</script><br');
|
||||
expect($apple.attr('href')).to.equal('http://github.com/"><script>alert("XSS!")</script><br');
|
||||
|
||||
$apple.attr('href', 'http://github.com/"><script>alert("XSS!")</script><br');
|
||||
expect($apple.html()).to.not.contain('<script>alert("XSS!")</script>');
|
||||
});
|
||||
|
||||
it('(key, value) : should coerce values to a string', function() {
|
||||
var $apple = $('.apple');
|
||||
$apple.attr('data-test', 1);
|
||||
expect($apple[0].attribs['data-test']).to.equal('1');
|
||||
expect($apple.attr('data-test')).to.equal('1');
|
||||
});
|
||||
|
||||
it('(key, value) : handle removed boolean attributes', function() {
|
||||
var $apple = $('.apple');
|
||||
$apple.attr('autofocus', 'autofocus');
|
||||
expect($apple.attr('autofocus')).to.equal('autofocus');
|
||||
$apple.removeAttr('autofocus');
|
||||
expect($apple.attr('autofocus')).to.equal(false);
|
||||
});
|
||||
|
||||
it('(key, value) : should remove non-boolean attributes with names or values similar to boolean ones', function() {
|
||||
var $apple = $('.apple');
|
||||
$apple.attr('data-autofocus', 'autofocus');
|
||||
expect($apple.attr('data-autofocus')).to.equal('autofocus');
|
||||
$apple.removeAttr('data-autofocus');
|
||||
expect($apple.attr('data-autofocus')).to.be(undefined);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.data', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
$ = cheerio.load(chocolates);
|
||||
});
|
||||
|
||||
it('() : should get all data attributes initially declared in the markup', function() {
|
||||
var data = $('.linth').data();
|
||||
expect(data).to.eql({
|
||||
highlight: 'Lindor',
|
||||
origin: 'swiss'
|
||||
});
|
||||
});
|
||||
|
||||
it('() : should get all data set via `data`', function() {
|
||||
var $el = cheerio('<div>');
|
||||
$el.data('a', 1);
|
||||
$el.data('b', 2);
|
||||
|
||||
expect($el.data()).to.eql({
|
||||
a: 1,
|
||||
b: 2
|
||||
});
|
||||
});
|
||||
|
||||
it('() : should get all data attributes initially declared in the markup merged with all data additionally set via `data`', function() {
|
||||
var $el = cheerio('<div data-a="a">');
|
||||
$el.data('b', 'b');
|
||||
|
||||
expect($el.data()).to.eql({
|
||||
a: 'a',
|
||||
b: 'b'
|
||||
});
|
||||
});
|
||||
|
||||
it('() : no data attribute should return an empty object', function() {
|
||||
var data = $('.cailler').data();
|
||||
expect(data).to.be.empty();
|
||||
});
|
||||
|
||||
it('(invalid key) : invalid data attribute should return `undefined` ', function() {
|
||||
var data = $('.frey').data('lol');
|
||||
expect(data).to.be(undefined);
|
||||
});
|
||||
|
||||
it('(valid key) : valid data attribute should get value', function() {
|
||||
var highlight = $('.linth').data('highlight');
|
||||
var origin = $('.linth').data('origin');
|
||||
|
||||
expect(highlight).to.equal('Lindor');
|
||||
expect(origin).to.equal('swiss');
|
||||
});
|
||||
|
||||
it('(key) : should translate camel-cased key values to hyphen-separated versions', function() {
|
||||
var $el = cheerio('<div data--three-word-attribute="a" data-foo-Bar_BAZ-="b">');
|
||||
|
||||
expect($el.data('ThreeWordAttribute')).to.be('a');
|
||||
expect($el.data('fooBar_baz-')).to.be('b');
|
||||
});
|
||||
|
||||
it('(key) : should retrieve object values', function() {
|
||||
var data = {};
|
||||
var $el = cheerio('<div>');
|
||||
|
||||
$el.data('test', data);
|
||||
|
||||
expect($el.data('test')).to.be(data);
|
||||
});
|
||||
|
||||
it('(key) : should parse JSON data derived from the markup', function() {
|
||||
var $el = cheerio('<div data-json="[1, 2, 3]">');
|
||||
|
||||
expect($el.data('json')).to.eql([1,2,3]);
|
||||
});
|
||||
|
||||
it('(key) : should not parse JSON data set via the `data` API', function() {
|
||||
var $el = cheerio('<div>');
|
||||
$el.data('json', '[1, 2, 3]');
|
||||
|
||||
expect($el.data('json')).to.be('[1, 2, 3]');
|
||||
});
|
||||
|
||||
// See http://api.jquery.com/data/ and http://bugs.jquery.com/ticket/14523
|
||||
it('(key) : should ignore the markup value after the first access', function() {
|
||||
var $el = cheerio('<div data-test="a">');
|
||||
|
||||
expect($el.data('test')).to.be('a');
|
||||
|
||||
$el.attr('data-test', 'b');
|
||||
|
||||
expect($el.data('test')).to.be('a');
|
||||
});
|
||||
|
||||
it('(hyphen key) : data addribute with hyphen should be camelized ;-)', function() {
|
||||
var data = $('.frey').data();
|
||||
expect(data).to.eql({
|
||||
taste: 'sweet',
|
||||
bestCollection: 'Mahony'
|
||||
});
|
||||
});
|
||||
|
||||
it('(key, value) : should set data attribute', function() {
|
||||
// Adding as object.
|
||||
var a = $('.frey').data({
|
||||
balls: 'giandor'
|
||||
});
|
||||
// Adding as string.
|
||||
var b = $('.linth').data('snack', 'chocoletti');
|
||||
|
||||
expect(a.data('balls')).to.eql('giandor');
|
||||
expect(b.data('snack')).to.eql('chocoletti');
|
||||
});
|
||||
|
||||
it('(map) : object map should set multiple data attributes', function() {
|
||||
var data = $('.linth').data({
|
||||
id: 'Cailler',
|
||||
flop: 'Pippilotti Rist',
|
||||
top: 'Frigor',
|
||||
url: 'http://www.cailler.ch/'
|
||||
})['0'].data;
|
||||
|
||||
expect(data.id).to.equal('Cailler');
|
||||
expect(data.flop).to.equal('Pippilotti Rist');
|
||||
expect(data.top).to.equal('Frigor');
|
||||
expect(data.url).to.equal('http://www.cailler.ch/');
|
||||
});
|
||||
|
||||
describe('(attr) : data-* attribute type coercion :', function() {
|
||||
it('boolean', function() {
|
||||
var $el = cheerio('<div data-bool="true">');
|
||||
expect($el.data('bool')).to.be(true);
|
||||
});
|
||||
|
||||
it('number', function() {
|
||||
var $el = cheerio('<div data-number="23">');
|
||||
expect($el.data('number')).to.be(23);
|
||||
});
|
||||
|
||||
it('number (scientific notation is not coerced)', function() {
|
||||
var $el = cheerio('<div data-sci="1E10">');
|
||||
expect($el.data('sci')).to.be('1E10');
|
||||
});
|
||||
|
||||
it('null', function() {
|
||||
var $el = cheerio('<div data-null="null">');
|
||||
expect($el.data('null')).to.be(null);
|
||||
});
|
||||
|
||||
it('object', function() {
|
||||
var $el = cheerio('<div data-obj=\'{ "a": 45 }\'>');
|
||||
expect($el.data('obj')).to.eql({ a: 45 });
|
||||
});
|
||||
|
||||
it('array', function() {
|
||||
var $el = cheerio('<div data-array="[1, 2, 3]">');
|
||||
expect($el.data('array')).to.eql([1, 2, 3]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('.val', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
$ = cheerio.load(inputs);
|
||||
});
|
||||
|
||||
it('.val(): on select should get value', function() {
|
||||
var val = $('select#one').val();
|
||||
expect(val).to.equal('option_selected');
|
||||
});
|
||||
it('.val(): on option should get value', function() {
|
||||
var val = $('select#one option').eq(0).val();
|
||||
expect(val).to.equal('option_not_selected');
|
||||
});
|
||||
it('.val(): on text input should get value', function() {
|
||||
var val = $('input[type="text"]').val();
|
||||
expect(val).to.equal('input_text');
|
||||
});
|
||||
it('.val(): on checked checkbox should get value', function() {
|
||||
var val = $('input[name="checkbox_on"]').val();
|
||||
expect(val).to.equal('on');
|
||||
});
|
||||
it('.val(): on unchecked checkbox should get value', function() {
|
||||
var val = $('input[name="checkbox_off"]').val();
|
||||
expect(val).to.equal('off');
|
||||
});
|
||||
it('.val(): on radio should get value', function() {
|
||||
var val = $('input[type="radio"]').val();
|
||||
expect(val).to.equal('on');
|
||||
});
|
||||
it('.val(): on multiple select should get an array of values', function() {
|
||||
var val = $('select#multi').val();
|
||||
expect(val).to.have.length(2);
|
||||
});
|
||||
it('.val(value): on input text should set value', function() {
|
||||
var element = $('input[type="text"]').val('test');
|
||||
expect(element.val()).to.equal('test');
|
||||
});
|
||||
it('.val(value): on select should set value', function() {
|
||||
var element = $('select#one').val('option_not_selected');
|
||||
expect(element.val()).to.equal('option_not_selected');
|
||||
});
|
||||
it('.val(value): on option should set value', function() {
|
||||
var element = $('select#one option').eq(0).val('option_changed');
|
||||
expect(element.val()).to.equal('option_changed');
|
||||
});
|
||||
it('.val(value): on radio should set value', function() {
|
||||
var element = $('input[name="radio"]').val('off');
|
||||
expect(element.val()).to.equal('off');
|
||||
});
|
||||
it('.val(values): on multiple select should set multiple values', function() {
|
||||
var element = $('select#multi').val(['1', '3', '4']);
|
||||
expect(element.val()).to.have.length(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.removeAttr', function() {
|
||||
|
||||
it('(key) : should remove a single attr', function() {
|
||||
var $fruits = $('#fruits');
|
||||
expect($fruits.attr('id')).to.not.be(undefined);
|
||||
$fruits.removeAttr('id');
|
||||
expect($fruits.attr('id')).to.be(undefined);
|
||||
});
|
||||
|
||||
it('should return cheerio object', function() {
|
||||
var obj = $('ul').removeAttr('id').cheerio;
|
||||
expect(obj).to.be.ok();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.hasClass', function() {
|
||||
function test(attr) {
|
||||
return cheerio('<div class="' + attr + '"></div>');
|
||||
}
|
||||
|
||||
it('(valid class) : should return true', function() {
|
||||
var cls = $('.apple').hasClass('apple');
|
||||
expect(cls).to.be.ok();
|
||||
|
||||
expect(test('foo').hasClass('foo')).to.be.ok();
|
||||
expect(test('foo bar').hasClass('foo')).to.be.ok();
|
||||
expect(test('bar foo').hasClass('foo')).to.be.ok();
|
||||
expect(test('bar foo bar').hasClass('foo')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(invalid class) : should return false', function() {
|
||||
var cls = $('#fruits').hasClass('fruits');
|
||||
expect(cls).to.not.be.ok();
|
||||
expect(test('foo-bar').hasClass('foo')).to.not.be.ok();
|
||||
expect(test('foo-bar').hasClass('foo')).to.not.be.ok();
|
||||
expect(test('foo-bar').hasClass('foo-ba')).to.not.be.ok();
|
||||
});
|
||||
|
||||
it('should check multiple classes', function() {
|
||||
// Add a class
|
||||
$('.apple').addClass('red');
|
||||
expect($('.apple').hasClass('apple')).to.be.ok();
|
||||
expect($('.apple').hasClass('red')).to.be.ok();
|
||||
|
||||
// Remove one and test again
|
||||
$('.apple').removeClass('apple');
|
||||
expect($('li').eq(0).hasClass('apple')).to.not.be.ok();
|
||||
// expect($('li', $fruits).eq(0).hasClass('red')).to.be.ok();
|
||||
});
|
||||
});
|
||||
|
||||
describe('.addClass', function() {
|
||||
|
||||
it('(first class) : should add the class to the element', function() {
|
||||
var $fruits = $('#fruits');
|
||||
$fruits.addClass('fruits');
|
||||
var cls = $fruits.hasClass('fruits');
|
||||
expect(cls).to.be.ok();
|
||||
});
|
||||
|
||||
it('(single class) : should add the class to the element', function() {
|
||||
$('.apple').addClass('fruit');
|
||||
var cls = $('.apple').hasClass('fruit');
|
||||
expect(cls).to.be.ok();
|
||||
});
|
||||
|
||||
it('(class): adds classes to many selected items', function() {
|
||||
$('li').addClass('fruit');
|
||||
expect($('.apple').hasClass('fruit')).to.be.ok();
|
||||
expect($('.orange').hasClass('fruit')).to.be.ok();
|
||||
expect($('.pear').hasClass('fruit')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(class class class) : should add multiple classes to the element', function() {
|
||||
$('.apple').addClass('fruit red tasty');
|
||||
expect($('.apple').hasClass('apple')).to.be.ok();
|
||||
expect($('.apple').hasClass('fruit')).to.be.ok();
|
||||
expect($('.apple').hasClass('red')).to.be.ok();
|
||||
expect($('.apple').hasClass('tasty')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(fn) : should add classes returned from the function', function() {
|
||||
var $fruits = $('#fruits').children();
|
||||
var args = [];
|
||||
var thisVals = [];
|
||||
var toAdd = ['apple red', '', undefined];
|
||||
|
||||
$fruits.addClass(function(idx, currentClass) {
|
||||
args.push(toArray(arguments));
|
||||
thisVals.push(this);
|
||||
return toAdd[idx];
|
||||
});
|
||||
|
||||
expect(args).to.eql([
|
||||
[0, 'apple'],
|
||||
[1, 'orange'],
|
||||
[2, 'pear']
|
||||
]);
|
||||
expect(thisVals).to.eql([
|
||||
$fruits[0],
|
||||
$fruits[1],
|
||||
$fruits[2]
|
||||
]);
|
||||
expect($fruits.eq(0).hasClass('apple')).to.be.ok();
|
||||
expect($fruits.eq(0).hasClass('red')).to.be.ok();
|
||||
expect($fruits.eq(1).hasClass('orange')).to.be.ok();
|
||||
expect($fruits.eq(2).hasClass('pear')).to.be.ok();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.removeClass', function() {
|
||||
|
||||
it('() : should remove all the classes', function() {
|
||||
$('.pear').addClass('fruit');
|
||||
$('.pear').removeClass();
|
||||
expect($('.pear').attr('class')).to.be(undefined);
|
||||
});
|
||||
|
||||
it('("") : should not modify class list', function() {
|
||||
var $fruits = $('#fruits');
|
||||
$fruits.children().removeClass('');
|
||||
expect($('.apple')).to.have.length(1);
|
||||
});
|
||||
|
||||
it('(invalid class) : should not remove anything', function() {
|
||||
$('.pear').removeClass('fruit');
|
||||
expect($('.pear').hasClass('pear')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(no class attribute) : should not throw an exception', function() {
|
||||
var $vegetables = cheerio(vegetables);
|
||||
var thrown = null;
|
||||
expect(function() {
|
||||
$('li', $vegetables).removeClass('vegetable');
|
||||
})
|
||||
.to.not.throwException();
|
||||
});
|
||||
|
||||
it('(single class) : should remove a single class from the element', function() {
|
||||
$('.pear').addClass('fruit');
|
||||
expect($('.pear').hasClass('fruit')).to.be.ok();
|
||||
$('.pear').removeClass('fruit');
|
||||
expect($('.pear').hasClass('fruit')).to.not.be.ok();
|
||||
expect($('.pear').hasClass('pear')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(single class) : should remove a single class from multiple classes on the element', function() {
|
||||
$('.pear').addClass('fruit green tasty');
|
||||
expect($('.pear').hasClass('fruit')).to.be.ok();
|
||||
expect($('.pear').hasClass('green')).to.be.ok();
|
||||
expect($('.pear').hasClass('tasty')).to.be.ok();
|
||||
|
||||
$('.pear').removeClass('green');
|
||||
expect($('.pear').hasClass('fruit')).to.be.ok();
|
||||
expect($('.pear').hasClass('green')).to.not.be.ok();
|
||||
expect($('.pear').hasClass('tasty')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(class class class) : should remove multiple classes from the element', function() {
|
||||
$('.apple').addClass('fruit red tasty');
|
||||
expect($('.apple').hasClass('apple')).to.be.ok();
|
||||
expect($('.apple').hasClass('fruit')).to.be.ok();
|
||||
expect($('.apple').hasClass('red')).to.be.ok();
|
||||
expect($('.apple').hasClass('tasty')).to.be.ok();
|
||||
|
||||
$('.apple').removeClass('apple red tasty');
|
||||
expect($('.fruit').hasClass('apple')).to.not.be.ok();
|
||||
expect($('.fruit').hasClass('red')).to.not.be.ok();
|
||||
expect($('.fruit').hasClass('tasty')).to.not.be.ok();
|
||||
expect($('.fruit').hasClass('fruit')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(class) : should remove all occurrences of a class name', function() {
|
||||
var $div = cheerio('<div class="x x y x z"></div>');
|
||||
expect($div.removeClass('x').hasClass('x')).to.be(false);
|
||||
});
|
||||
|
||||
it('(fn) : should remove classes returned from the function', function() {
|
||||
var $fruits = $('#fruits').children();
|
||||
var args = [];
|
||||
var thisVals = [];
|
||||
var toAdd = ['apple red', '', undefined];
|
||||
|
||||
$fruits.removeClass(function(idx, currentClass) {
|
||||
args.push(toArray(arguments));
|
||||
thisVals.push(this);
|
||||
return toAdd[idx];
|
||||
});
|
||||
|
||||
expect(args).to.eql([
|
||||
[0, 'apple'],
|
||||
[1, 'orange'],
|
||||
[2, 'pear']
|
||||
]);
|
||||
expect(thisVals).to.eql([
|
||||
$fruits[0],
|
||||
$fruits[1],
|
||||
$fruits[2]
|
||||
]);
|
||||
expect($fruits.eq(0).hasClass('apple')).to.not.be.ok();
|
||||
expect($fruits.eq(0).hasClass('red')).to.not.be.ok();
|
||||
expect($fruits.eq(1).hasClass('orange')).to.be.ok();
|
||||
expect($fruits.eq(2).hasClass('pear')).to.be.ok();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.toggleClass', function() {
|
||||
|
||||
it('(class class) : should toggle multiple classes from the element', function() {
|
||||
$('.apple').addClass('fruit');
|
||||
expect($('.apple').hasClass('apple')).to.be.ok();
|
||||
expect($('.apple').hasClass('fruit')).to.be.ok();
|
||||
expect($('.apple').hasClass('red')).to.not.be.ok();
|
||||
|
||||
$('.apple').toggleClass('apple red');
|
||||
expect($('.fruit').hasClass('apple')).to.not.be.ok();
|
||||
expect($('.fruit').hasClass('red')).to.be.ok();
|
||||
expect($('.fruit').hasClass('fruit')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(class class, true) : should add multiple classes to the element', function() {
|
||||
$('.apple').addClass('fruit');
|
||||
expect($('.apple').hasClass('apple')).to.be.ok();
|
||||
expect($('.apple').hasClass('fruit')).to.be.ok();
|
||||
expect($('.apple').hasClass('red')).to.not.be.ok();
|
||||
|
||||
$('.apple').toggleClass('apple red', true);
|
||||
expect($('.fruit').hasClass('apple')).to.be.ok();
|
||||
expect($('.fruit').hasClass('red')).to.be.ok();
|
||||
expect($('.fruit').hasClass('fruit')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(class true) : should add only one instance of class', function () {
|
||||
$('.apple').toggleClass('tasty', true);
|
||||
$('.apple').toggleClass('tasty', true);
|
||||
expect($('.apple').attr('class').match(/tasty/g).length).to.equal(1);
|
||||
});
|
||||
|
||||
it('(class class, false) : should remove multiple classes from the element', function() {
|
||||
$('.apple').addClass('fruit');
|
||||
expect($('.apple').hasClass('apple')).to.be.ok();
|
||||
expect($('.apple').hasClass('fruit')).to.be.ok();
|
||||
expect($('.apple').hasClass('red')).to.not.be.ok();
|
||||
|
||||
$('.apple').toggleClass('apple red', false);
|
||||
expect($('.fruit').hasClass('apple')).to.not.be.ok();
|
||||
expect($('.fruit').hasClass('red')).to.not.be.ok();
|
||||
expect($('.fruit').hasClass('fruit')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(fn) : should toggle classes returned from the function', function() {
|
||||
$ = cheerio.load(food);
|
||||
|
||||
$('.apple').addClass('fruit');
|
||||
$('.carrot').addClass('vegetable');
|
||||
expect($('.apple').hasClass('fruit')).to.be.ok();
|
||||
expect($('.apple').hasClass('vegetable')).to.not.be.ok();
|
||||
expect($('.orange').hasClass('fruit')).to.not.be.ok();
|
||||
expect($('.orange').hasClass('vegetable')).to.not.be.ok();
|
||||
expect($('.carrot').hasClass('fruit')).to.not.be.ok();
|
||||
expect($('.carrot').hasClass('vegetable')).to.be.ok();
|
||||
expect($('.sweetcorn').hasClass('fruit')).to.not.be.ok();
|
||||
expect($('.sweetcorn').hasClass('vegetable')).to.not.be.ok();
|
||||
|
||||
$('li').toggleClass(function(index, className, switchVal) {
|
||||
return $(this).parent().is('#fruits') ? 'fruit' : 'vegetable';
|
||||
});
|
||||
expect($('.apple').hasClass('fruit')).to.not.be.ok();
|
||||
expect($('.apple').hasClass('vegetable')).to.not.be.ok();
|
||||
expect($('.orange').hasClass('fruit')).to.be.ok();
|
||||
expect($('.orange').hasClass('vegetable')).to.not.be.ok();
|
||||
expect($('.carrot').hasClass('fruit')).to.not.be.ok();
|
||||
expect($('.carrot').hasClass('vegetable')).to.not.be.ok();
|
||||
expect($('.sweetcorn').hasClass('fruit')).to.not.be.ok();
|
||||
expect($('.sweetcorn').hasClass('vegetable')).to.be.ok();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.is', function () {
|
||||
it('() : should return false', function() {
|
||||
expect($('li.apple').is()).to.be(false);
|
||||
});
|
||||
|
||||
it('(true selector) : should return true', function() {
|
||||
expect(cheerio('#vegetables', vegetables).is('ul')).to.be(true);
|
||||
});
|
||||
|
||||
it('(false selector) : should return false', function() {
|
||||
expect(cheerio('#vegetables', vegetables).is('div')).to.be(false);
|
||||
});
|
||||
|
||||
it('(true selection) : should return true', function() {
|
||||
var $vegetables = cheerio('li', vegetables);
|
||||
expect($vegetables.is($vegetables.eq(1))).to.be(true);
|
||||
});
|
||||
|
||||
it('(false selection) : should return false', function() {
|
||||
var $vegetableList = cheerio(vegetables);
|
||||
var $vegetables = $vegetableList.find('li');
|
||||
expect($vegetables.is($vegetableList)).to.be(false);
|
||||
});
|
||||
|
||||
it('(true element) : should return true', function() {
|
||||
var $vegetables = cheerio('li', vegetables);
|
||||
expect($vegetables.is($vegetables[0])).to.be(true);
|
||||
});
|
||||
|
||||
it('(false element) : should return false', function() {
|
||||
var $vegetableList = cheerio(vegetables);
|
||||
var $vegetables = $vegetableList.find('li');
|
||||
expect($vegetables.is($vegetableList[0])).to.be(false);
|
||||
});
|
||||
|
||||
it('(true predicate) : should return true', function() {
|
||||
var result = $('li').is(function() {
|
||||
return this.name === 'li' && $(this).hasClass('pear');
|
||||
});
|
||||
expect(result).to.be(true);
|
||||
});
|
||||
|
||||
it('(false predicate) : should return false', function () {
|
||||
var result = $('li').last().is(function() {
|
||||
return this.name === 'ul';
|
||||
});
|
||||
expect(result).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
88
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.css.js
generated
vendored
Normal file
88
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.css.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
var expect = require('expect.js');
|
||||
var cheerio = require('..');
|
||||
|
||||
describe('$(...)', function() {
|
||||
|
||||
describe('.css', function() {
|
||||
it('(prop): should return a css property value', function() {
|
||||
var el = cheerio('<li style="hai: there">');
|
||||
expect(el.css('hai')).to.equal('there');
|
||||
});
|
||||
|
||||
it('([prop1, prop2]): should return the specified property values as an object', function() {
|
||||
var el = cheerio('<li style="margin: 1px; padding: 2px; color: blue;">');
|
||||
expect(el.css(['margin', 'color'])).to.eql({ margin: '1px', color: 'blue' });
|
||||
});
|
||||
|
||||
it('(prop, val): should set a css property', function() {
|
||||
var el = cheerio('<li style="margin: 0;"></li><li></li>');
|
||||
el.css('color', 'red');
|
||||
expect(el.attr('style')).to.equal('margin: 0; color: red;');
|
||||
expect(el.eq(1).attr('style')).to.equal('color: red;');
|
||||
});
|
||||
|
||||
it('(prop, ""): should unset a css property', function() {
|
||||
var el = cheerio('<li style="padding: 1px; margin: 0;">');
|
||||
el.css('padding', '');
|
||||
expect(el.attr('style')).to.equal('margin: 0;');
|
||||
});
|
||||
|
||||
it('(prop): should not mangle embedded urls', function() {
|
||||
var el = cheerio('<li style="background-image:url(http://example.com/img.png);">');
|
||||
expect(el.css('background-image')).to.equal('url(http://example.com/img.png)');
|
||||
});
|
||||
|
||||
it('(prop): should ignore blank properties', function() {
|
||||
var el = cheerio('<li style=":#ccc;color:#aaa;">');
|
||||
expect(el.css()).to.eql({color:'#aaa'});
|
||||
});
|
||||
|
||||
it('(prop): should ignore blank values', function() {
|
||||
var el = cheerio('<li style="color:;position:absolute;">');
|
||||
expect(el.css()).to.eql({position:'absolute'});
|
||||
});
|
||||
|
||||
describe('(prop, function):', function() {
|
||||
beforeEach(function() {
|
||||
this.$el = cheerio('<div style="margin: 0;"></div><div style="margin: 0;"></div><div style="margin: 0;">');
|
||||
});
|
||||
|
||||
it('should iterate over the selection', function() {
|
||||
var count = 0;
|
||||
var $el = this.$el;
|
||||
this.$el.css('margin', function(idx, elem) {
|
||||
expect(idx).to.equal(count);
|
||||
expect(elem).to.equal($el[count]);
|
||||
expect(this).to.equal($el[count]);
|
||||
count++;
|
||||
});
|
||||
expect(count).to.equal(3);
|
||||
});
|
||||
|
||||
it('should set each attribute independently', function() {
|
||||
var values = ['4px', '', undefined];
|
||||
this.$el.css('margin', function(idx) {
|
||||
return values[idx];
|
||||
});
|
||||
expect(this.$el.eq(0).attr('style')).to.equal('margin: 4px;');
|
||||
expect(this.$el.eq(1).attr('style')).to.equal('');
|
||||
expect(this.$el.eq(2).attr('style')).to.equal('margin: 0;');
|
||||
});
|
||||
});
|
||||
|
||||
it('(obj): should set each key and val', function() {
|
||||
var el = cheerio('<li style="padding: 0;"></li><li></li>');
|
||||
el.css({ foo: 0 });
|
||||
expect(el.eq(0).attr('style')).to.equal('padding: 0; foo: 0;');
|
||||
expect(el.eq(1).attr('style')).to.equal('foo: 0;');
|
||||
});
|
||||
|
||||
describe('parser', function(){
|
||||
it('should allow any whitespace between declarations', function() {
|
||||
var el = cheerio('<li style="one \t:\n 0;\n two \f\r:\v 1">');
|
||||
expect(el.css(['one', 'two'])).to.eql({ one: 0, two: 1 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
945
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.manipulation.js
generated
vendored
Normal file
945
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.manipulation.js
generated
vendored
Normal file
@@ -0,0 +1,945 @@
|
||||
var expect = require('expect.js'),
|
||||
cheerio = require('..'),
|
||||
fruits = require('./fixtures').fruits,
|
||||
toArray = Function.call.bind(Array.prototype.slice);
|
||||
|
||||
describe('$(...)', function() {
|
||||
|
||||
var $, $fruits;
|
||||
|
||||
beforeEach(function() {
|
||||
$ = cheerio.load(fruits);
|
||||
$fruits = $('#fruits');
|
||||
});
|
||||
|
||||
describe('.append', function() {
|
||||
|
||||
it('() : should do nothing', function() {
|
||||
expect($('#fruits').append()[0].name).to.equal('ul');
|
||||
});
|
||||
|
||||
it('(html) : should add element as last child', function() {
|
||||
$fruits.append('<li class="plum">Plum</li>');
|
||||
expect($fruits.children(3).hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('($(...)) : should add element as last child', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
$fruits.append($plum);
|
||||
expect($fruits.children(3).hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(Node) : should add element as last child', function() {
|
||||
var plum = $('<li class="plum">Plum</li>')[0];
|
||||
$fruits.append(plum);
|
||||
expect($fruits.children(3).hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(existing Node) : should remove node from previous location', function() {
|
||||
var apple = $fruits.children()[0];
|
||||
var $children;
|
||||
|
||||
expect($fruits.children()).to.have.length(3);
|
||||
$fruits.append(apple);
|
||||
$children = $fruits.children();
|
||||
|
||||
expect($children).to.have.length(3);
|
||||
expect($children[0]).to.not.equal(apple);
|
||||
expect($children[2]).to.equal(apple);
|
||||
});
|
||||
|
||||
it('(existing Node) : should remove existing node from previous location', function() {
|
||||
var apple = $fruits.children()[0];
|
||||
var $children;
|
||||
var $dest = $('<div></div>');
|
||||
|
||||
expect($fruits.children()).to.have.length(3);
|
||||
$dest.append(apple);
|
||||
$children = $fruits.children();
|
||||
|
||||
expect($children).to.have.length(2);
|
||||
expect($children[0]).to.not.equal(apple);
|
||||
|
||||
expect($dest.children()).to.have.length(1);
|
||||
expect($dest.children()[0]).to.equal(apple);
|
||||
});
|
||||
|
||||
it('(existing Node) : should update original direct siblings', function() {
|
||||
$('.pear').append($('.orange'));
|
||||
expect($('.apple').next()[0]).to.be($('.pear')[0]);
|
||||
expect($('.pear').prev()[0]).to.be($('.apple')[0]);
|
||||
});
|
||||
|
||||
it('(elem) : should NOP if removed', function() {
|
||||
var $apple = $('.apple');
|
||||
|
||||
$apple.remove();
|
||||
$fruits.append($apple);
|
||||
expect($fruits.children(2).hasClass('apple')).to.be.ok();
|
||||
});
|
||||
|
||||
it('($(...), html) : should add multiple elements as last children', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var grape = '<li class="grape">Grape</li>';
|
||||
$fruits.append($plum, grape);
|
||||
expect($fruits.children(3).hasClass('plum')).to.be.ok();
|
||||
expect($fruits.children(4).hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(Array) : should append all elements in the array', function() {
|
||||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>')
|
||||
.get();
|
||||
$fruits.append(more);
|
||||
expect($fruits.children(3).hasClass('plum')).to.be.ok();
|
||||
expect($fruits.children(4).hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(fn) : should invoke the callback with the correct argument and context', function() {
|
||||
$fruits = $fruits.children();
|
||||
var args = [];
|
||||
var thisValues = [];
|
||||
|
||||
$fruits.append(function() {
|
||||
args.push(toArray(arguments));
|
||||
thisValues.push(this);
|
||||
});
|
||||
|
||||
expect(args).to.eql([
|
||||
[0, 'Apple'],
|
||||
[1, 'Orange'],
|
||||
[2, 'Pear']
|
||||
]);
|
||||
expect(thisValues).to.eql([
|
||||
$fruits[0],
|
||||
$fruits[1],
|
||||
$fruits[2]
|
||||
]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned string as last child', function() {
|
||||
$fruits = $fruits.children();
|
||||
var $apple, $orange, $pear;
|
||||
|
||||
$fruits.append(function() {
|
||||
return '<div class="first">';
|
||||
});
|
||||
|
||||
$apple = $fruits.eq(0);
|
||||
$orange = $fruits.eq(1);
|
||||
$pear = $fruits.eq(2);
|
||||
|
||||
expect($apple.find('.first')[0]).to.equal($apple.contents()[1]);
|
||||
expect($orange.find('.first')[0]).to.equal($orange.contents()[1]);
|
||||
expect($pear.find('.first')[0]).to.equal($pear.contents()[1]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned Cheerio object as last child', function() {
|
||||
var $apple, $orange, $pear;
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.append(function() {
|
||||
return $('<div class="second">');
|
||||
});
|
||||
|
||||
$apple = $fruits.eq(0);
|
||||
$orange = $fruits.eq(1);
|
||||
$pear = $fruits.eq(2);
|
||||
|
||||
expect($apple.find('.second')[0]).to.equal($apple.contents()[1]);
|
||||
expect($orange.find('.second')[0]).to.equal($orange.contents()[1]);
|
||||
expect($pear.find('.second')[0]).to.equal($pear.contents()[1]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned Node as last child', function() {
|
||||
var $apple, $orange, $pear;
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.append(function() {
|
||||
return $('<div class="third">')[0];
|
||||
});
|
||||
|
||||
$apple = $fruits.eq(0);
|
||||
$orange = $fruits.eq(1);
|
||||
$pear = $fruits.eq(2);
|
||||
|
||||
expect($apple.find('.third')[0]).to.equal($apple.contents()[1]);
|
||||
expect($orange.find('.third')[0]).to.equal($orange.contents()[1]);
|
||||
expect($pear.find('.third')[0]).to.equal($pear.contents()[1]);
|
||||
});
|
||||
|
||||
it('should maintain correct object state (Issue: #10)', function() {
|
||||
var $obj = $('<div></div>')
|
||||
.append('<div><div></div></div>')
|
||||
.children()
|
||||
.children()
|
||||
.parent();
|
||||
expect($obj).to.be.ok();
|
||||
});
|
||||
|
||||
it('($(...)) : should remove from root element', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var root = $plum[0].root;
|
||||
expect(root).to.be.ok();
|
||||
|
||||
$fruits.append($plum);
|
||||
expect($plum[0].root).to.not.be.ok();
|
||||
expect(root.children).to.not.contain($plum[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.prepend', function() {
|
||||
|
||||
it('() : should do nothing', function() {
|
||||
expect($('#fruits').prepend()[0].name).to.equal('ul');
|
||||
});
|
||||
|
||||
it('(html) : should add element as first child', function() {
|
||||
$fruits.prepend('<li class="plum">Plum</li>');
|
||||
expect($fruits.children(0).hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('($(...)) : should add element as first child', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
$fruits.prepend($plum);
|
||||
expect($fruits.children(0).hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(Node) : should add node as first child', function() {
|
||||
var plum = $('<li class="plum">Plum</li>')[0];
|
||||
$fruits.prepend(plum);
|
||||
expect($fruits.children(0).hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(existing Node) : should remove existing nodes from previous locations', function() {
|
||||
var pear = $fruits.children()[2];
|
||||
var $children;
|
||||
|
||||
expect($fruits.children()).to.have.length(3);
|
||||
$fruits.prepend(pear);
|
||||
$children = $fruits.children();
|
||||
|
||||
expect($children).to.have.length(3);
|
||||
expect($children[2]).to.not.equal(pear);
|
||||
expect($children[0]).to.equal(pear);
|
||||
});
|
||||
|
||||
it('(existing Node) : should update original direct siblings', function() {
|
||||
$('.pear').prepend($('.orange'));
|
||||
expect($('.apple').next()[0]).to.be($('.pear')[0]);
|
||||
expect($('.pear').prev()[0]).to.be($('.apple')[0]);
|
||||
});
|
||||
|
||||
it('(elem) : should handle if removed', function() {
|
||||
var $apple = $('.apple');
|
||||
|
||||
$apple.remove();
|
||||
$fruits.prepend($apple);
|
||||
expect($fruits.children(0).hasClass('apple')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(Array) : should add all elements in the array as inital children', function() {
|
||||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>')
|
||||
.get();
|
||||
$fruits.prepend(more);
|
||||
expect($fruits.children(0).hasClass('plum')).to.be.ok();
|
||||
expect($fruits.children(1).hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(html, $(...), html) : should add multiple elements as first children', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var grape = '<li class="grape">Grape</li>';
|
||||
$fruits.prepend($plum, grape);
|
||||
expect($fruits.children(0).hasClass('plum')).to.be.ok();
|
||||
expect($fruits.children(1).hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(fn) : should invoke the callback with the correct argument and context', function() {
|
||||
var args = [];
|
||||
var thisValues = [];
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.prepend(function() {
|
||||
args.push(toArray(arguments));
|
||||
thisValues.push(this);
|
||||
});
|
||||
|
||||
expect(args).to.eql([
|
||||
[0, 'Apple'],
|
||||
[1, 'Orange'],
|
||||
[2, 'Pear']
|
||||
]);
|
||||
expect(thisValues).to.eql([
|
||||
$fruits[0],
|
||||
$fruits[1],
|
||||
$fruits[2]
|
||||
]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned string as first child', function() {
|
||||
var $apple, $orange, $pear;
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.prepend(function() {
|
||||
return '<div class="first">';
|
||||
});
|
||||
|
||||
$apple = $fruits.eq(0);
|
||||
$orange = $fruits.eq(1);
|
||||
$pear = $fruits.eq(2);
|
||||
|
||||
expect($apple.find('.first')[0]).to.equal($apple.contents()[0]);
|
||||
expect($orange.find('.first')[0]).to.equal($orange.contents()[0]);
|
||||
expect($pear.find('.first')[0]).to.equal($pear.contents()[0]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned Cheerio object as first child', function() {
|
||||
var $apple, $orange, $pear;
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.prepend(function() {
|
||||
return $('<div class="second">');
|
||||
});
|
||||
|
||||
$apple = $fruits.eq(0);
|
||||
$orange = $fruits.eq(1);
|
||||
$pear = $fruits.eq(2);
|
||||
|
||||
expect($apple.find('.second')[0]).to.equal($apple.contents()[0]);
|
||||
expect($orange.find('.second')[0]).to.equal($orange.contents()[0]);
|
||||
expect($pear.find('.second')[0]).to.equal($pear.contents()[0]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned Node as first child', function() {
|
||||
var $apple, $orange, $pear;
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.prepend(function() {
|
||||
return $('<div class="third">')[0];
|
||||
});
|
||||
|
||||
$apple = $fruits.eq(0);
|
||||
$orange = $fruits.eq(1);
|
||||
$pear = $fruits.eq(2);
|
||||
|
||||
expect($apple.find('.third')[0]).to.equal($apple.contents()[0]);
|
||||
expect($orange.find('.third')[0]).to.equal($orange.contents()[0]);
|
||||
expect($pear.find('.third')[0]).to.equal($pear.contents()[0]);
|
||||
});
|
||||
|
||||
|
||||
it('($(...)) : should remove from root element', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var root = $plum[0].root;
|
||||
expect(root).to.be.ok();
|
||||
|
||||
$fruits.prepend($plum);
|
||||
expect($plum[0].root).to.not.be.ok();
|
||||
expect(root.children).to.not.contain($plum[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.after', function() {
|
||||
|
||||
it('() : should do nothing', function() {
|
||||
expect($('#fruits').after()[0].name).to.equal('ul');
|
||||
});
|
||||
|
||||
it('(html) : should add element as next sibling', function() {
|
||||
var grape = '<li class="grape">Grape</li>';
|
||||
$('.apple').after(grape);
|
||||
expect($('.apple').next().hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(Array) : should add all elements in the array as next sibling', function() {
|
||||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>')
|
||||
.get();
|
||||
$('.apple').after(more);
|
||||
expect($fruits.children(1).hasClass('plum')).to.be.ok();
|
||||
expect($fruits.children(2).hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('($(...)) : should add element as next sibling', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
$('.apple').after($plum);
|
||||
expect($('.apple').next().hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(Node) : should add element as next sibling', function() {
|
||||
var plum = $('<li class="plum">Plum</li>')[0];
|
||||
$('.apple').after(plum);
|
||||
expect($('.apple').next().hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(existing Node) : should remove existing nodes from previous locations', function() {
|
||||
var pear = $fruits.children()[2];
|
||||
var $children;
|
||||
|
||||
$('.apple').after(pear);
|
||||
|
||||
$children = $fruits.children();
|
||||
expect($children).to.have.length(3);
|
||||
expect($children[1]).to.be(pear);
|
||||
});
|
||||
|
||||
it('(existing Node) : should update original direct siblings', function() {
|
||||
$('.pear').after($('.orange'));
|
||||
expect($('.apple').next()[0]).to.be($('.pear')[0]);
|
||||
expect($('.pear').prev()[0]).to.be($('.apple')[0]);
|
||||
});
|
||||
|
||||
it('(elem) : should handle if removed', function() {
|
||||
var $apple = $('.apple');
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
|
||||
$apple.remove();
|
||||
$apple.after($plum);
|
||||
expect($plum.prev()).to.be.empty();
|
||||
});
|
||||
|
||||
it('($(...), html) : should add multiple elements as next siblings', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var grape = '<li class="grape">Grape</li>';
|
||||
$('.apple').after($plum, grape);
|
||||
expect($('.apple').next().hasClass('plum')).to.be.ok();
|
||||
expect($('.plum').next().hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(fn) : should invoke the callback with the correct argument and context', function() {
|
||||
var args = [];
|
||||
var thisValues = [];
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.after(function() {
|
||||
args.push(toArray(arguments));
|
||||
thisValues.push(this);
|
||||
});
|
||||
|
||||
expect(args).to.eql([[0], [1], [2]]);
|
||||
expect(thisValues).to.eql([
|
||||
$fruits[0],
|
||||
$fruits[1],
|
||||
$fruits[2]
|
||||
]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned string as next sibling', function() {
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.after(function() {
|
||||
return '<li class="first">';
|
||||
});
|
||||
|
||||
expect($('.first')[0]).to.equal($('#fruits').contents()[1]);
|
||||
expect($('.first')[1]).to.equal($('#fruits').contents()[3]);
|
||||
expect($('.first')[2]).to.equal($('#fruits').contents()[5]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned Cheerio object as next sibling', function() {
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.after(function() {
|
||||
return $('<li class="second">');
|
||||
});
|
||||
|
||||
expect($('.second')[0]).to.equal($('#fruits').contents()[1]);
|
||||
expect($('.second')[1]).to.equal($('#fruits').contents()[3]);
|
||||
expect($('.second')[2]).to.equal($('#fruits').contents()[5]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned element as next sibling', function() {
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.after(function() {
|
||||
return $('<li class="third">')[0];
|
||||
});
|
||||
|
||||
expect($('.third')[0]).to.equal($('#fruits').contents()[1]);
|
||||
expect($('.third')[1]).to.equal($('#fruits').contents()[3]);
|
||||
expect($('.third')[2]).to.equal($('#fruits').contents()[5]);
|
||||
});
|
||||
|
||||
it('($(...)) : should remove from root element', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var root = $plum[0].root;
|
||||
expect(root).to.be.ok();
|
||||
|
||||
$fruits.after($plum);
|
||||
expect($plum[0].root).to.not.be.ok();
|
||||
expect(root.children).to.not.contain($plum[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.before', function() {
|
||||
|
||||
it('() : should do nothing', function() {
|
||||
expect($('#fruits').before()[0].name).to.equal('ul');
|
||||
});
|
||||
|
||||
it('(html) : should add element as previous sibling', function() {
|
||||
var grape = '<li class="grape">Grape</li>';
|
||||
$('.apple').before(grape);
|
||||
expect($('.apple').prev().hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('($(...)) : should add element as previous sibling', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
$('.apple').before($plum);
|
||||
expect($('.apple').prev().hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(Node) : should add element as previous sibling', function() {
|
||||
var plum = $('<li class="plum">Plum</li>');
|
||||
$('.apple').before(plum);
|
||||
expect($('.apple').prev().hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(existing Node) : should remove existing nodes from previous locations', function() {
|
||||
var pear = $fruits.children()[2];
|
||||
var $children;
|
||||
|
||||
$('.apple').before(pear);
|
||||
|
||||
$children = $fruits.children();
|
||||
expect($children).to.have.length(3);
|
||||
expect($children[0]).to.be(pear);
|
||||
});
|
||||
|
||||
it('(existing Node) : should update original direct siblings', function() {
|
||||
$('.apple').before($('.orange'));
|
||||
expect($('.apple').next()[0]).to.be($('.pear')[0]);
|
||||
expect($('.pear').prev()[0]).to.be($('.apple')[0]);
|
||||
});
|
||||
|
||||
it('(elem) : should handle if removed', function() {
|
||||
var $apple = $('.apple');
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
|
||||
$apple.remove();
|
||||
$apple.before($plum);
|
||||
expect($plum.next()).to.be.empty();
|
||||
});
|
||||
|
||||
it('(Array) : should add all elements in the array as previous sibling', function() {
|
||||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>')
|
||||
.get();
|
||||
$('.apple').before(more);
|
||||
expect($fruits.children(0).hasClass('plum')).to.be.ok();
|
||||
expect($fruits.children(1).hasClass('grape')).to.be.ok();
|
||||
});
|
||||
|
||||
it('($(...), html) : should add multiple elements as previous siblings', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var grape = '<li class="grape">Grape</li>';
|
||||
$('.apple').before($plum, grape);
|
||||
expect($('.apple').prev().hasClass('grape')).to.be.ok();
|
||||
expect($('.grape').prev().hasClass('plum')).to.be.ok();
|
||||
});
|
||||
|
||||
it('(fn) : should invoke the callback with the correct argument and context', function() {
|
||||
var args = [];
|
||||
var thisValues = [];
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.before(function() {
|
||||
args.push(toArray(arguments));
|
||||
thisValues.push(this);
|
||||
});
|
||||
|
||||
expect(args).to.eql([[0], [1], [2]]);
|
||||
expect(thisValues).to.eql([
|
||||
$fruits[0],
|
||||
$fruits[1],
|
||||
$fruits[2]
|
||||
]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned string as previous sibling', function() {
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.before(function() {
|
||||
return '<li class="first">';
|
||||
});
|
||||
|
||||
expect($('.first')[0]).to.equal($('#fruits').contents()[0]);
|
||||
expect($('.first')[1]).to.equal($('#fruits').contents()[2]);
|
||||
expect($('.first')[2]).to.equal($('#fruits').contents()[4]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned Cheerio object as previous sibling', function() {
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.before(function() {
|
||||
return $('<li class="second">');
|
||||
});
|
||||
|
||||
expect($('.second')[0]).to.equal($('#fruits').contents()[0]);
|
||||
expect($('.second')[1]).to.equal($('#fruits').contents()[2]);
|
||||
expect($('.second')[2]).to.equal($('#fruits').contents()[4]);
|
||||
});
|
||||
|
||||
it('(fn) : should add returned Node as previous sibling', function() {
|
||||
$fruits = $fruits.children();
|
||||
|
||||
$fruits.before(function() {
|
||||
return $('<li class="third">')[0];
|
||||
});
|
||||
|
||||
expect($('.third')[0]).to.equal($('#fruits').contents()[0]);
|
||||
expect($('.third')[1]).to.equal($('#fruits').contents()[2]);
|
||||
expect($('.third')[2]).to.equal($('#fruits').contents()[4]);
|
||||
});
|
||||
|
||||
it('($(...)) : should remove from root element', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var root = $plum[0].root;
|
||||
expect(root).to.be.ok();
|
||||
|
||||
$fruits.before($plum);
|
||||
expect($plum[0].root).to.not.be.ok();
|
||||
expect(root.children).to.not.contain($plum[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.remove', function() {
|
||||
|
||||
it('() : should remove selected elements', function() {
|
||||
$('.apple').remove();
|
||||
expect($fruits.find('.apple')).to.have.length(0);
|
||||
});
|
||||
|
||||
it('() : should be reentrant', function() {
|
||||
var $apple = $('.apple');
|
||||
$apple.remove();
|
||||
$apple.remove();
|
||||
expect($fruits.find('.apple')).to.have.length(0);
|
||||
});
|
||||
|
||||
it('(selector) : should remove matching selected elements', function() {
|
||||
$('li').remove('.apple');
|
||||
expect($fruits.find('.apple')).to.have.length(0);
|
||||
});
|
||||
|
||||
it('($(...)) : should remove from root element', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var root = $plum[0].root;
|
||||
expect(root).to.be.ok();
|
||||
|
||||
$plum.remove();
|
||||
expect($plum[0].root).to.not.be.ok();
|
||||
expect(root.children).to.not.contain($plum[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.replaceWith', function() {
|
||||
|
||||
it('(elem) : should replace one <li> tag with another', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
$('.pear').replaceWith($plum);
|
||||
expect($('.orange').next().hasClass('plum')).to.be.ok();
|
||||
expect($('.orange').next().html()).to.equal('Plum');
|
||||
});
|
||||
|
||||
it('(Array) : should replace one <li> tag with the elements in the array', function() {
|
||||
var more = $('<li class="plum">Plum</li><li class="grape">Grape</li>')
|
||||
.get();
|
||||
$('.pear').replaceWith(more);
|
||||
|
||||
expect($fruits.children(2).hasClass('plum')).to.be.ok();
|
||||
expect($fruits.children(3).hasClass('grape')).to.be.ok();
|
||||
expect($fruits.children()).to.have.length(4);
|
||||
});
|
||||
|
||||
it('(Node) : should replace the selected element with given node', function() {
|
||||
var $src = $('<h2>hi <span>there</span></h2>');
|
||||
var $new = $('<ul></ul>');
|
||||
var $replaced = $src.find('span').replaceWith($new[0]);
|
||||
expect($new[0].parent).to.equal($src[0]);
|
||||
expect($replaced[0].parent).to.equal(null);
|
||||
expect($.html($src)).to.equal('<h2>hi <ul></ul></h2>');
|
||||
});
|
||||
|
||||
it('(existing element) : should remove element from its previous location', function() {
|
||||
$('.pear').replaceWith($('.apple'));
|
||||
expect($fruits.children()).to.have.length(2);
|
||||
expect($fruits.children()[0]).to.equal($('.orange')[0]);
|
||||
expect($fruits.children()[1]).to.equal($('.apple')[0]);
|
||||
});
|
||||
|
||||
it('(elem) : should NOP if removed', function() {
|
||||
var $pear = $('.pear');
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
|
||||
$pear.remove();
|
||||
$pear.replaceWith($plum);
|
||||
expect($('.orange').next().hasClass('plum')).to.not.be.ok();
|
||||
});
|
||||
|
||||
it('(elem) : should replace the single selected element with given element', function() {
|
||||
var $src = $('<h2>hi <span>there</span></h2>');
|
||||
var $new = $('<div>here</div>');
|
||||
var $replaced = $src.find('span').replaceWith($new);
|
||||
expect($new[0].parent).to.equal($src[0]);
|
||||
expect($replaced[0].parent).to.equal(null);
|
||||
expect($.html($src)).to.equal('<h2>hi <div>here</div></h2>');
|
||||
});
|
||||
|
||||
it('(str) : should accept strings', function() {
|
||||
var $src = $('<h2>hi <span>there</span></h2>');
|
||||
var newStr = '<div>here</div>';
|
||||
var $replaced = $src.find('span').replaceWith(newStr);
|
||||
expect($replaced[0].parent).to.equal(null);
|
||||
expect($.html($src)).to.equal('<h2>hi <div>here</div></h2>');
|
||||
});
|
||||
|
||||
it('(str) : should replace all selected elements', function() {
|
||||
var $src = $('<b>a<br>b<br>c<br>d</b>');
|
||||
var $replaced = $src.find('br').replaceWith(' ');
|
||||
expect($replaced[0].parent).to.equal(null);
|
||||
expect($.html($src)).to.equal('<b>a b c d</b>');
|
||||
});
|
||||
|
||||
it('(fn) : should invoke the callback with the correct argument and context', function() {
|
||||
var origChildren = $fruits.children().get();
|
||||
var args = [];
|
||||
var thisValues = [];
|
||||
|
||||
$fruits.children().replaceWith(function() {
|
||||
args.push(toArray(arguments));
|
||||
thisValues.push(this);
|
||||
return '<li class="first">';
|
||||
});
|
||||
|
||||
expect(args).to.eql([
|
||||
[0, origChildren[0]],
|
||||
[1, origChildren[1]],
|
||||
[2, origChildren[2]]
|
||||
]);
|
||||
expect(thisValues).to.eql([
|
||||
origChildren[0],
|
||||
origChildren[1],
|
||||
origChildren[2]
|
||||
]);
|
||||
});
|
||||
|
||||
it('(fn) : should replace the selected element with the returned string', function() {
|
||||
$fruits.children().replaceWith(function() {
|
||||
return '<li class="first">';
|
||||
});
|
||||
|
||||
expect($fruits.find('.first')).to.have.length(3);
|
||||
});
|
||||
|
||||
it('(fn) : should replace the selected element with the returned Cheerio object', function() {
|
||||
$fruits.children().replaceWith(function() {
|
||||
return $('<li class="second">');
|
||||
});
|
||||
|
||||
expect($fruits.find('.second')).to.have.length(3);
|
||||
});
|
||||
|
||||
it('(fn) : should replace the selected element with the returned node', function() {
|
||||
$fruits.children().replaceWith(function() {
|
||||
return $('<li class="third">')[0];
|
||||
});
|
||||
|
||||
expect($fruits.find('.third')).to.have.length(3);
|
||||
});
|
||||
|
||||
it('($(...)) : should remove from root element', function() {
|
||||
var $plum = $('<li class="plum">Plum</li>');
|
||||
var root = $plum[0].root;
|
||||
expect(root).to.be.ok();
|
||||
|
||||
$fruits.children().replaceWith($plum);
|
||||
expect($plum[0].root).to.not.be.ok();
|
||||
expect(root.children).to.not.contain($plum[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.empty', function() {
|
||||
it('() : should remove all children from selected elements', function() {
|
||||
expect($fruits.children()).to.have.length(3);
|
||||
|
||||
$fruits.empty();
|
||||
expect($fruits.children()).to.have.length(0);
|
||||
});
|
||||
|
||||
it('() : should allow element reinsertion', function() {
|
||||
var $children = $fruits.children();
|
||||
|
||||
$fruits.empty();
|
||||
expect($fruits.children()).to.have.length(0);
|
||||
expect($children).to.have.length(3);
|
||||
|
||||
$fruits.append($('<div></div><div></div>'));
|
||||
var $remove = $fruits.children().eq(0),
|
||||
$keep = $fruits.children().eq(1);
|
||||
$remove.replaceWith($children);
|
||||
expect($fruits.children()).to.have.length(4);
|
||||
});
|
||||
|
||||
it('() : should destroy children\'s references to the parent', function() {
|
||||
var $children = $fruits.children();
|
||||
|
||||
$fruits.empty();
|
||||
|
||||
expect($children.eq(0).parent()).to.have.length(0);
|
||||
expect($children.eq(0).next()).to.have.length(0);
|
||||
expect($children.eq(0).prev()).to.have.length(0);
|
||||
expect($children.eq(1).parent()).to.have.length(0);
|
||||
expect($children.eq(1).next()).to.have.length(0);
|
||||
expect($children.eq(1).prev()).to.have.length(0);
|
||||
expect($children.eq(2).parent()).to.have.length(0);
|
||||
expect($children.eq(2).next()).to.have.length(0);
|
||||
expect($children.eq(2).prev()).to.have.length(0);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.html', function() {
|
||||
|
||||
it('() : should get the innerHTML for an element', function() {
|
||||
expect($fruits.html()).to.equal([
|
||||
'<li class="apple">Apple</li>',
|
||||
'<li class="orange">Orange</li>',
|
||||
'<li class="pear">Pear</li>'
|
||||
].join(''));
|
||||
});
|
||||
|
||||
it('() : should get innerHTML even if its just text', function() {
|
||||
var item = '<li class="pear">Pear</li>';
|
||||
expect($('.pear', item).html()).to.equal('Pear');
|
||||
});
|
||||
|
||||
it('() : should return empty string if nothing inside', function() {
|
||||
var item = '<li></li>';
|
||||
expect($('li', item).html()).to.equal('');
|
||||
});
|
||||
|
||||
it('(html) : should set the html for its children', function() {
|
||||
$fruits.html('<li class="durian">Durian</li>');
|
||||
var html = $fruits.html();
|
||||
expect(html).to.equal('<li class="durian">Durian</li>');
|
||||
});
|
||||
|
||||
it('(html) : should add new elements for each element in selection', function() {
|
||||
var $fruits = $('li');
|
||||
$fruits.html('<li class="durian">Durian</li>');
|
||||
var tested = 0;
|
||||
$fruits.each(function(){
|
||||
expect($(this).children().parent().get(0)).to.equal(this);
|
||||
tested++;
|
||||
});
|
||||
expect(tested).to.equal(3);
|
||||
});
|
||||
|
||||
it('(elem) : should set the html for its children with element', function() {
|
||||
$fruits.html($('<li class="durian">Durian</li>'));
|
||||
var html = $fruits.html();
|
||||
expect(html).to.equal('<li class="durian">Durian</li>');
|
||||
});
|
||||
|
||||
it('() : should allow element reinsertion', function() {
|
||||
var $children = $fruits.children();
|
||||
|
||||
$fruits.html('<div></div><div></div>');
|
||||
expect($fruits.children()).to.have.length(2);
|
||||
|
||||
var $remove = $fruits.children().eq(0),
|
||||
$keep = $fruits.children().eq(1);
|
||||
$remove.replaceWith($children);
|
||||
expect($fruits.children()).to.have.length(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe('.toString', function() {
|
||||
it('() : should get the outerHTML for an element', function() {
|
||||
expect($fruits.toString()).to.equal(fruits);
|
||||
});
|
||||
|
||||
it('() : should return an html string for a set of elements', function() {
|
||||
expect($fruits.find('li').toString()).to.equal('<li class="apple">Apple</li><li class="orange">Orange</li><li class="pear">Pear</li>');
|
||||
});
|
||||
|
||||
it('() : should be called implicitly', function() {
|
||||
var string = [$('<foo>'), $('<bar>'), $('<baz>')].join('');
|
||||
expect(string).to.equal('<foo></foo><bar></bar><baz></baz>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('.text', function() {
|
||||
|
||||
it('() : gets the text for a single element', function() {
|
||||
expect($('.apple').text()).to.equal('Apple');
|
||||
});
|
||||
|
||||
it('() : combines all text from children text nodes', function() {
|
||||
expect($('#fruits').text()).to.equal('AppleOrangePear');
|
||||
});
|
||||
|
||||
it('(text) : sets the text for the child node', function() {
|
||||
$('.apple').text('Granny Smith Apple');
|
||||
expect($('.apple')[0].children[0].data).to.equal('Granny Smith Apple');
|
||||
});
|
||||
|
||||
it('(text) : inserts separate nodes for all children', function() {
|
||||
$('li').text('Fruits');
|
||||
var tested = 0;
|
||||
$('li').each(function(){
|
||||
expect(this.children[0].parent).to.equal(this);
|
||||
tested++;
|
||||
});
|
||||
expect(tested).to.equal(3);
|
||||
});
|
||||
|
||||
it('should allow functions as arguments', function() {
|
||||
$('.apple').text(function(idx, content) {
|
||||
expect(idx).to.equal(0);
|
||||
expect(content).to.equal('Apple');
|
||||
return 'whatever mate';
|
||||
});
|
||||
expect($('.apple')[0].children[0].data).to.equal('whatever mate');
|
||||
});
|
||||
|
||||
it('should decode special chars', function() {
|
||||
var text = $('<p>M&M</p>').text();
|
||||
expect(text).to.equal('M&M');
|
||||
});
|
||||
|
||||
it('should work with special chars added as strings', function() {
|
||||
var text = $('<p>M&M</p>').text();
|
||||
expect(text).to.equal('M&M');
|
||||
});
|
||||
|
||||
it('( undefined ) : should act as an accessor', function() {
|
||||
var $div = $('<div>test</div>');
|
||||
expect($div.text(undefined)).to.be.a('string');
|
||||
expect($div.text()).to.be('test');
|
||||
});
|
||||
|
||||
it('( "" ) : should convert to string', function() {
|
||||
var $div = $('<div>test</div>');
|
||||
expect($div.text('').text()).to.equal('');
|
||||
});
|
||||
|
||||
it('( null ) : should convert to string', function() {
|
||||
expect($('<div>').text(null).text()).to.equal('null');
|
||||
});
|
||||
|
||||
it('( 0 ) : should convert to string', function() {
|
||||
expect($('<div>').text(0).text()).to.equal('0');
|
||||
});
|
||||
|
||||
it('(str) should encode then decode unsafe characters', function() {
|
||||
var $apple = $('.apple');
|
||||
|
||||
$apple.text('blah <script>alert("XSS!")</script> blah');
|
||||
expect($apple[0].children[0].data).to.equal('blah <script>alert("XSS!")</script> blah');
|
||||
expect($apple.text()).to.equal('blah <script>alert("XSS!")</script> blah');
|
||||
|
||||
$apple.text('blah <script>alert("XSS!")</script> blah');
|
||||
expect($apple.html()).to.not.contain('<script>alert("XSS!")</script>');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
1182
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.traversing.js
generated
vendored
Normal file
1182
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.traversing.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
167
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.utils.js
generated
vendored
Normal file
167
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/api.utils.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
var expect = require('expect.js'),
|
||||
fixtures = require('./fixtures'),
|
||||
cheerio = require('..');
|
||||
|
||||
|
||||
describe('cheerio', function() {
|
||||
|
||||
describe('.html', function() {
|
||||
|
||||
it('() : should return innerHTML; $.html(obj) should return outerHTML', function() {
|
||||
var $div = cheerio('div', '<div><span>foo</span><span>bar</span></div>');
|
||||
var span = $div.children()[1];
|
||||
expect(cheerio(span).html()).to.equal('bar');
|
||||
expect(cheerio.html(span)).to.equal('<span>bar</span>');
|
||||
});
|
||||
|
||||
it('(<obj>) : should accept an object, an array, or a cheerio object', function() {
|
||||
var $span = cheerio('<span>foo</span>');
|
||||
expect(cheerio.html($span[0])).to.equal('<span>foo</span>');
|
||||
expect(cheerio.html($span)).to.equal('<span>foo</span>');
|
||||
});
|
||||
|
||||
it('(<value>) : should be able to set to an empty string', function() {
|
||||
var $elem = cheerio('<span>foo</span>').html('');
|
||||
expect(cheerio.html($elem)).to.equal('<span></span>');
|
||||
});
|
||||
|
||||
it('() : of empty cheerio object should return null', function() {
|
||||
expect(cheerio().html()).to.be(null);
|
||||
});
|
||||
|
||||
it('(selector) : should return the outerHTML of the selected element', function() {
|
||||
var $ = cheerio.load(fixtures.fruits);
|
||||
expect($.html('.pear')).to.equal('<li class="pear">Pear</li>');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('.load', function() {
|
||||
|
||||
it('(html) : should retain original root after creating a new node', function() {
|
||||
var $html = cheerio.load('<body><ul id="fruits"></ul></body>');
|
||||
expect($html('body')).to.have.length(1);
|
||||
$html('<script>');
|
||||
expect($html('body')).to.have.length(1);
|
||||
});
|
||||
|
||||
it('(html) : should handle lowercase tag options', function() {
|
||||
var $html = cheerio.load('<BODY><ul id="fruits"></ul></BODY>', { lowerCaseTags : true });
|
||||
expect($html.html()).to.be('<body><ul id="fruits"></ul></body>');
|
||||
});
|
||||
|
||||
it('(html) : should handle the `normalizeWhitepace` option', function() {
|
||||
var $html = cheerio.load('<body><b>foo</b> <b>bar</b></body>', { normalizeWhitespace : true });
|
||||
expect($html.html()).to.be('<body><b>foo</b> <b>bar</b></body>');
|
||||
});
|
||||
|
||||
// TODO:
|
||||
// it('(html) : should handle xml tag option', function() {
|
||||
// var $html = $.load('<body><script>oh hai</script></body>', { xmlMode : true });
|
||||
// console.log($html('script')[0].type);
|
||||
// expect($html('script')[0].type).to.be('tag');
|
||||
// });
|
||||
|
||||
it('(buffer) : should accept a buffer', function() {
|
||||
var $html = cheerio.load(new Buffer('<div>foo</div>'));
|
||||
expect($html.html()).to.be('<div>foo</div>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('.clone', function() {
|
||||
|
||||
it('() : should return a copy', function() {
|
||||
var $src = cheerio('<div><span>foo</span><span>bar</span><span>baz</span></div>').children();
|
||||
var $elem = $src.clone();
|
||||
expect($elem.length).to.equal(3);
|
||||
expect($elem.parent()).to.have.length(0);
|
||||
expect($elem.text()).to.equal($src.text());
|
||||
$src.text('rofl');
|
||||
expect($elem.text()).to.not.equal($src.text());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.parseHTML', function() {
|
||||
|
||||
it('() : returns null', function() {
|
||||
expect(cheerio.parseHTML()).to.equal(null);
|
||||
});
|
||||
|
||||
it('(null) : returns null', function() {
|
||||
expect(cheerio.parseHTML(null)).to.equal(null);
|
||||
});
|
||||
|
||||
it('("") : returns null', function() {
|
||||
expect(cheerio.parseHTML('')).to.equal(null);
|
||||
});
|
||||
|
||||
it('(largeHtmlString) : parses large HTML strings', function() {
|
||||
var html = new Array(10).join('<div></div>');
|
||||
var nodes = cheerio.parseHTML(html);
|
||||
|
||||
expect(nodes.length).to.be.greaterThan(4);
|
||||
expect(nodes).to.be.an('array');
|
||||
});
|
||||
|
||||
it('("<script>") : ignores scripts by default', function() {
|
||||
var html = '<script>undefined()</script>';
|
||||
expect(cheerio.parseHTML(html)).to.have.length(0);
|
||||
});
|
||||
|
||||
it('("<script>", true) : preserves scripts when requested', function() {
|
||||
var html = '<script>undefined()</script>';
|
||||
expect(cheerio.parseHTML(html, true)[0].name).to.match(/script/i);
|
||||
});
|
||||
|
||||
it('("scriptAndNonScript) : preserves non-script nodes', function() {
|
||||
var html = '<script>undefined()</script><div></div>';
|
||||
expect(cheerio.parseHTML(html)[0].name).to.match(/div/i);
|
||||
});
|
||||
|
||||
it('(scriptAndNonScript, true) : Preserves script position', function() {
|
||||
var html = '<script>undefined()</script><div></div>';
|
||||
expect(cheerio.parseHTML(html, true)[0].name).to.match(/script/i);
|
||||
});
|
||||
|
||||
it('(text) : returns a text node', function() {
|
||||
expect(cheerio.parseHTML('text')[0].type).to.be('text');
|
||||
});
|
||||
|
||||
it('(\\ttext) : preserves leading whitespace', function() {
|
||||
expect(cheerio.parseHTML('\t<div></div>')[0].data).to.equal('\t');
|
||||
});
|
||||
|
||||
it('( text) : Leading spaces are treated as text nodes', function() {
|
||||
expect(cheerio.parseHTML(' <div/> ')[0].type).to.be('text');
|
||||
});
|
||||
|
||||
it('(html) : should preserve content', function() {
|
||||
var html = '<div>test div</div>';
|
||||
expect(cheerio(cheerio.parseHTML(html)[0]).html()).to.equal('test div');
|
||||
});
|
||||
|
||||
it('(malformedHtml) : should not break', function() {
|
||||
expect(cheerio.parseHTML('<span><span>')).to.have.length(1);
|
||||
});
|
||||
|
||||
it('(garbageInput) : should not cause an error', function() {
|
||||
expect(cheerio.parseHTML('<#if><tr><p>This is a test.</p></tr><#/if>') || true).to.be.ok();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.root', function() {
|
||||
|
||||
it('() : should return a cheerio-wrapped root object', function() {
|
||||
var $html = cheerio.load('<div><span>foo</span><span>bar</span></div>');
|
||||
$html.root().append('<div id="test"></div>');
|
||||
expect($html.html()).to.equal('<div><span>foo</span><span>bar</span></div><div id="test"></div>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
280
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/cheerio.js
generated
vendored
Normal file
280
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/cheerio.js
generated
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
var expect = require('expect.js'),
|
||||
_ = require('lodash'),
|
||||
htmlparser2 = require('htmlparser2'),
|
||||
$ = require('../'),
|
||||
fixtures = require('./fixtures'),
|
||||
fruits = fixtures.fruits,
|
||||
food = fixtures.food;
|
||||
|
||||
// HTML
|
||||
var script = '<script src="script.js" type="text/javascript"></script>',
|
||||
multiclass = '<p><a class="btn primary" href="#">Save</a></p>';
|
||||
|
||||
describe('cheerio', function() {
|
||||
|
||||
it('should get the version', function() {
|
||||
expect(/\d+\.\d+\.\d+/.test($.version)).to.be.ok();
|
||||
});
|
||||
|
||||
it('$(null) should return be empty', function() {
|
||||
expect($(null)).to.be.empty();
|
||||
});
|
||||
|
||||
it('$(undefined) should be empty', function() {
|
||||
expect($(undefined)).to.be.empty();
|
||||
});
|
||||
|
||||
it('$(null) should be empty', function() {
|
||||
expect($('')).to.be.empty();
|
||||
});
|
||||
|
||||
it('$(selector) with no context or root should be empty', function() {
|
||||
expect($('.h2')).to.be.empty();
|
||||
expect($('#fruits')).to.be.empty();
|
||||
});
|
||||
|
||||
it('$(node) : should override previously-loaded nodes', function() {
|
||||
var C = $.load('<div><span></span></div>');
|
||||
var spanNode = C('span')[0];
|
||||
var $span = C(spanNode);
|
||||
expect($span[0]).to.equal(spanNode);
|
||||
});
|
||||
|
||||
it('should be able to create html without a root or context', function() {
|
||||
var $h2 = $('<h2>');
|
||||
expect($h2).to.not.be.empty();
|
||||
expect($h2).to.have.length(1);
|
||||
expect($h2[0].name).to.equal('h2');
|
||||
});
|
||||
|
||||
it('should be able to create complicated html', function() {
|
||||
var $script = $(script);
|
||||
expect($script).to.not.be.empty();
|
||||
expect($script).to.have.length(1);
|
||||
expect($script[0].attribs.src).to.equal('script.js');
|
||||
expect($script[0].attribs.type).to.equal('text/javascript');
|
||||
expect($script[0].children).to.be.empty();
|
||||
});
|
||||
|
||||
var testAppleSelect = function($apple) {
|
||||
expect($apple).to.have.length(1);
|
||||
$apple = $apple[0];
|
||||
expect($apple.parent.name).to.equal('ul');
|
||||
expect($apple.prev).to.be(null);
|
||||
expect($apple.next.attribs['class']).to.equal('orange');
|
||||
expect($apple.children).to.have.length(1);
|
||||
expect($apple.children[0].data).to.equal('Apple');
|
||||
};
|
||||
|
||||
it('should be able to select .apple with only a context', function() {
|
||||
var $apple = $('.apple', fruits);
|
||||
testAppleSelect($apple);
|
||||
});
|
||||
|
||||
it('should be able to select .apple with a node as context', function() {
|
||||
var $apple = $('.apple', $(fruits)[0]);
|
||||
testAppleSelect($apple);
|
||||
});
|
||||
|
||||
it('should be able to select .apple with only a root', function() {
|
||||
var $apple = $('.apple', null, fruits);
|
||||
testAppleSelect($apple);
|
||||
});
|
||||
|
||||
it('should be able to select an id', function() {
|
||||
var $fruits = $('#fruits', null, fruits);
|
||||
expect($fruits).to.have.length(1);
|
||||
expect($fruits[0].attribs.id).to.equal('fruits');
|
||||
});
|
||||
|
||||
it('should be able to select a tag', function() {
|
||||
var $ul = $('ul', fruits);
|
||||
expect($ul).to.have.length(1);
|
||||
expect($ul[0].name).to.equal('ul');
|
||||
});
|
||||
|
||||
it('should be able to filter down using the context', function() {
|
||||
var q = $.load(fruits),
|
||||
apple = q('.apple', 'ul'),
|
||||
lis = q('li', 'ul');
|
||||
|
||||
expect(apple).to.have.length(1);
|
||||
expect(lis).to.have.length(3);
|
||||
});
|
||||
|
||||
it('should accept a node reference as a context', function() {
|
||||
var $elems = $('<div><span></span></div>');
|
||||
expect($('span', $elems[0])).to.have.length(1);
|
||||
});
|
||||
|
||||
it('should accept an array of node references as a context', function() {
|
||||
var $elems = $('<div><span></span></div>');
|
||||
expect($('span', $elems.toArray())).to.have.length(1);
|
||||
});
|
||||
|
||||
it('should select only elements inside given context (Issue #193)', function() {
|
||||
var q = $.load(food),
|
||||
fruits = q('#fruits'),
|
||||
fruitElements = q('li', fruits);
|
||||
|
||||
expect(fruitElements).to.have.length(3);
|
||||
});
|
||||
|
||||
it('should allow loading a pre-parsed DOM', function() {
|
||||
var dom = htmlparser2.parseDOM(food),
|
||||
q = $.load(dom);
|
||||
|
||||
expect(q('ul')).to.have.length(3);
|
||||
});
|
||||
|
||||
it('should be able to select multiple tags', function() {
|
||||
var $fruits = $('li', null, fruits);
|
||||
expect($fruits).to.have.length(3);
|
||||
var classes = ['apple', 'orange', 'pear'];
|
||||
$fruits.each(function(idx, $fruit) {
|
||||
expect($fruit.attribs['class']).to.equal(classes[idx]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to do: $("#fruits .apple")', function() {
|
||||
var $apple = $('#fruits .apple', fruits);
|
||||
testAppleSelect($apple);
|
||||
});
|
||||
|
||||
it('should be able to do: $("li.apple")', function() {
|
||||
var $apple = $('li.apple', fruits);
|
||||
testAppleSelect($apple);
|
||||
});
|
||||
|
||||
it('should be able to select by attributes', function() {
|
||||
var $apple = $('li[class=apple]', fruits);
|
||||
testAppleSelect($apple);
|
||||
});
|
||||
|
||||
it('should be able to select multiple classes: $(".btn.primary")', function() {
|
||||
var $a = $('.btn.primary', multiclass);
|
||||
expect($a).to.have.length(1);
|
||||
expect($a[0].children[0].data).to.equal('Save');
|
||||
});
|
||||
|
||||
it('should not create a top-level node', function() {
|
||||
var $elem = $('* div', '<div>');
|
||||
expect($elem).to.have.length(0);
|
||||
});
|
||||
|
||||
it('should be able to select multiple elements: $(".apple, #fruits")', function() {
|
||||
var $elems = $('.apple, #fruits', fruits);
|
||||
expect($elems).to.have.length(2);
|
||||
|
||||
var $apple = _.filter($elems, function(elem) {
|
||||
return elem.attribs['class'] === 'apple';
|
||||
});
|
||||
var $fruits = _.filter($elems, function(elem) {
|
||||
return elem.attribs.id === 'fruits';
|
||||
});
|
||||
testAppleSelect($apple);
|
||||
expect($fruits[0].attribs.id).to.equal('fruits');
|
||||
});
|
||||
|
||||
it('should select first element $(:first)');
|
||||
// var $elem = $(':first', fruits);
|
||||
// var $h2 = $('<h2>fruits</h2>');
|
||||
// console.log($elem.before('hi'));
|
||||
// console.log($elem.before($h2));
|
||||
|
||||
it('should be able to select immediate children: $("#fruits > .pear")', function() {
|
||||
var $food = $(food);
|
||||
$('.pear', $food).append('<li class="pear">Another Pear!</li>');
|
||||
expect($('#fruits .pear', $food)).to.have.length(2);
|
||||
var $elem = $('#fruits > .pear', $food);
|
||||
expect($elem).to.have.length(1);
|
||||
expect($elem.attr('class')).to.equal('pear');
|
||||
});
|
||||
|
||||
it('should be able to select immediate children: $(".apple + .pear")', function() {
|
||||
var $elem = $('.apple + li', fruits);
|
||||
expect($elem).to.have.length(1);
|
||||
$elem = $('.apple + .pear', fruits);
|
||||
expect($elem).to.have.length(0);
|
||||
$elem = $('.apple + .orange', fruits);
|
||||
expect($elem).to.have.length(1);
|
||||
expect($elem.attr('class')).to.equal('orange');
|
||||
});
|
||||
|
||||
it('should be able to select immediate children: $(".apple ~ .pear")', function() {
|
||||
var $elem = $('.apple ~ li', fruits);
|
||||
expect($elem).to.have.length(2);
|
||||
$elem = $('.apple ~ .pear', fruits);
|
||||
expect($elem.attr('class')).to.equal('pear');
|
||||
});
|
||||
|
||||
it('should handle wildcards on attributes: $("li[class*=r]")', function() {
|
||||
var $elem = $('li[class*=r]', fruits);
|
||||
expect($elem).to.have.length(2);
|
||||
expect($elem.eq(0).attr('class')).to.equal('orange');
|
||||
expect($elem.eq(1).attr('class')).to.equal('pear');
|
||||
});
|
||||
|
||||
it('should handle beginning of attr selectors: $("li[class^=o]")', function() {
|
||||
var $elem = $('li[class^=o]', fruits);
|
||||
expect($elem).to.have.length(1);
|
||||
expect($elem.eq(0).attr('class')).to.equal('orange');
|
||||
});
|
||||
|
||||
it('should handle beginning of attr selectors: $("li[class$=e]")', function() {
|
||||
var $elem = $('li[class$=e]', fruits);
|
||||
expect($elem).to.have.length(2);
|
||||
expect($elem.eq(0).attr('class')).to.equal('apple');
|
||||
expect($elem.eq(1).attr('class')).to.equal('orange');
|
||||
});
|
||||
|
||||
it('should gracefully degrade on complex, unmatched queries', function() {
|
||||
var $elem = $('Eastern States Cup #8-fin <br>Downhill ');
|
||||
expect($elem).to.have.length(0); // []
|
||||
});
|
||||
|
||||
it('(extended Array) should not interfere with prototype methods (issue #119)', function() {
|
||||
var extended = [];
|
||||
var custom = extended.find = extended.children = extended.each = function() {};
|
||||
var $empty = $(extended);
|
||||
|
||||
expect($empty.find).to.be($.prototype.find);
|
||||
expect($empty.children).to.be($.prototype.children);
|
||||
expect($empty.each).to.be($.prototype.each);
|
||||
});
|
||||
|
||||
it('should render xml in html() when options.xmlMode = true', function() {
|
||||
var str = '<MixedCaseTag UPPERCASEATTRIBUTE=""></MixedCaseTag>',
|
||||
expected = '<MixedCaseTag UPPERCASEATTRIBUTE=""/>',
|
||||
dom = $.load(str, {xmlMode: true});
|
||||
|
||||
expect(dom('MixedCaseTag').get(0).name).to.equal('MixedCaseTag');
|
||||
expect(dom.html()).to.be(expected);
|
||||
});
|
||||
|
||||
it('should render xml in html() when options.xmlMode = true passed to html()', function() {
|
||||
var str = '<MixedCaseTag UPPERCASEATTRIBUTE=""></MixedCaseTag>',
|
||||
// since parsing done without xmlMode flag, all tags converted to lowercase
|
||||
expectedXml = '<mixedcasetag uppercaseattribute=""/>',
|
||||
expectedNoXml = '<mixedcasetag uppercaseattribute=""></mixedcasetag>',
|
||||
dom = $.load(str);
|
||||
|
||||
expect(dom('MixedCaseTag').get(0).name).to.equal('mixedcasetag');
|
||||
expect(dom.html()).to.be(expectedNoXml);
|
||||
expect(dom.html({xmlMode: true})).to.be(expectedXml);
|
||||
});
|
||||
|
||||
it('should respect options on the element level', function() {
|
||||
var str = '<!doctype html><html><head><title>Some test</title></head><body><footer><p>Copyright © 2003-2014</p></footer></body></html>',
|
||||
expectedHtml = '<p>Copyright © 2003-2014</p>',
|
||||
expectedXml = '<p>Copyright © 2003-2014</p>',
|
||||
domNotEncoded = $.load(str, {decodeEntities: false}),
|
||||
domEncoded = $.load(str);
|
||||
|
||||
expect(domNotEncoded('footer').html()).to.be(expectedHtml);
|
||||
// TODO: Make it more html friendly, maybe with custom encode tables
|
||||
expect(domEncoded('footer').html()).to.be(expectedXml);
|
||||
});
|
||||
|
||||
|
||||
});
|
53
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/fixtures.js
generated
vendored
Normal file
53
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/fixtures.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
/* jshint indent: false */
|
||||
exports.fruits = [
|
||||
'<ul id="fruits">',
|
||||
'<li class="apple">Apple</li>',
|
||||
'<li class="orange">Orange</li>',
|
||||
'<li class="pear">Pear</li>',
|
||||
'</ul>'
|
||||
].join('');
|
||||
|
||||
exports.vegetables = [
|
||||
'<ul id="vegetables">',
|
||||
'<li class="carrot">Carrot</li>',
|
||||
'<li class="sweetcorn">Sweetcorn</li>',
|
||||
'</ul>'
|
||||
].join('');
|
||||
|
||||
exports.chocolates = [
|
||||
'<ul id="chocolates">',
|
||||
'<li class="linth" data-highlight="Lindor" data-origin="swiss">Linth</li>',
|
||||
'<li class="frey" data-taste="sweet" data-best-collection="Mahony">Frey</li>',
|
||||
'<li class="cailler">Cailler</li>',
|
||||
'</ul>'
|
||||
].join('');
|
||||
|
||||
exports.drinks = [
|
||||
'<ul id="drinks">',
|
||||
'<li class="beer">Beer</li>',
|
||||
'<li class="juice">Juice</li>',
|
||||
'<li class="milk">Milk</li>',
|
||||
'<li class="water">Water</li>',
|
||||
'<li class="cider">Cider</li>',
|
||||
'</ul>'
|
||||
].join('');
|
||||
|
||||
exports.food = [
|
||||
'<ul id="food">',
|
||||
exports.fruits,
|
||||
exports.vegetables,
|
||||
'</ul>'
|
||||
].join('');
|
||||
|
||||
exports.inputs = [
|
||||
'<select id="one"><option value="option_not_selected">Option not selected</option><option value="option_selected" selected>Option selected</option></select>',
|
||||
'<input type="text" value="input_text" />',
|
||||
'<input type="checkbox" name="checkbox_off" value="off" /><input type="checkbox" name="checkbox_on" value="on" checked />',
|
||||
'<input type="radio" value="off" name="radio" /><input type="radio" name="radio" value="on" checked />',
|
||||
'<select id="multi" multiple><option value="1">1</option><option value="2" selected>2</option><option value="3" selected>3</option><option value="4">4</option></select>'
|
||||
].join('');
|
||||
|
||||
exports.text = [
|
||||
'<p>Apples, <b>oranges</b> and pears.</p>',
|
||||
'<p>Carrots and <!-- sweetcorn --></p>'
|
||||
].join('');
|
2
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/mocha.opts
generated
vendored
Normal file
2
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/mocha.opts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
--reporter list
|
||||
--growl
|
218
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/parse.js
generated
vendored
Normal file
218
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/parse.js
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
var expect = require('expect.js'),
|
||||
parse = require('../lib/parse'),
|
||||
defaultOpts = require('..').prototype.options;
|
||||
|
||||
|
||||
// Tags
|
||||
var basic = '<html></html>';
|
||||
var siblings = '<h2></h2><p></p>';
|
||||
|
||||
// Single Tags
|
||||
var single = '<br/>';
|
||||
var singleWrong = '<br>';
|
||||
|
||||
// Children
|
||||
var children = '<html><br/></html>';
|
||||
var li = '<li class="durian">Durian</li>';
|
||||
|
||||
// Attributes
|
||||
var attributes = '<img src="hello.png" alt="man waving">';
|
||||
var noValueAttribute = '<textarea disabled></textarea>';
|
||||
|
||||
// Comments
|
||||
var comment = '<!-- sexy -->';
|
||||
var conditional = '<!--[if IE 8]><html class="no-js ie8" lang="en"><![endif]-->';
|
||||
|
||||
// Text
|
||||
var text = 'lorem ipsum';
|
||||
|
||||
// Script
|
||||
var script = '<script type="text/javascript">alert("hi world!");</script>';
|
||||
var scriptEmpty = '<script></script>';
|
||||
|
||||
// Style
|
||||
var style = '<style type="text/css"> h2 { color:blue; } </style>';
|
||||
var styleEmpty = '<style></style>';
|
||||
|
||||
// Directives
|
||||
var directive = '<!doctype html>';
|
||||
|
||||
|
||||
describe('parse', function() {
|
||||
|
||||
describe('.eval', function() {
|
||||
|
||||
it('should parse basic empty tags: ' + basic, function() {
|
||||
var tag = parse.evaluate(basic, defaultOpts)[0];
|
||||
expect(tag.type).to.equal('tag');
|
||||
expect(tag.name).to.equal('html');
|
||||
expect(tag.children).to.be.empty();
|
||||
});
|
||||
|
||||
it('should handle sibling tags: ' + siblings, function() {
|
||||
var dom = parse.evaluate(siblings, defaultOpts),
|
||||
h2 = dom[0],
|
||||
p = dom[1];
|
||||
|
||||
expect(dom).to.have.length(2);
|
||||
expect(h2.name).to.equal('h2');
|
||||
expect(p.name).to.equal('p');
|
||||
});
|
||||
|
||||
it('should handle single tags: ' + single, function() {
|
||||
var tag = parse.evaluate(single, defaultOpts)[0];
|
||||
expect(tag.type).to.equal('tag');
|
||||
expect(tag.name).to.equal('br');
|
||||
expect(tag.children).to.be.empty();
|
||||
});
|
||||
|
||||
it('should handle malformatted single tags: ' + singleWrong, function() {
|
||||
var tag = parse.evaluate(singleWrong, defaultOpts)[0];
|
||||
expect(tag.type).to.equal('tag');
|
||||
expect(tag.name).to.equal('br');
|
||||
expect(tag.children).to.be.empty();
|
||||
});
|
||||
|
||||
it('should handle tags with children: ' + children, function() {
|
||||
var tag = parse.evaluate(children, defaultOpts)[0];
|
||||
expect(tag.type).to.equal('tag');
|
||||
expect(tag.name).to.equal('html');
|
||||
expect(tag.children).to.be.ok();
|
||||
expect(tag.children).to.have.length(1);
|
||||
});
|
||||
|
||||
it('should handle tags with children: ' + li, function() {
|
||||
var tag = parse.evaluate(li, defaultOpts)[0];
|
||||
expect(tag.children).to.have.length(1);
|
||||
expect(tag.children[0].data).to.equal('Durian');
|
||||
});
|
||||
|
||||
it('should handle tags with attributes: ' + attributes, function() {
|
||||
var attrs = parse.evaluate(attributes, defaultOpts)[0].attribs;
|
||||
expect(attrs).to.be.ok();
|
||||
expect(attrs.src).to.equal('hello.png');
|
||||
expect(attrs.alt).to.equal('man waving');
|
||||
});
|
||||
|
||||
it('should handle value-less attributes: ' + noValueAttribute, function() {
|
||||
var attrs = parse.evaluate(noValueAttribute, defaultOpts)[0].attribs;
|
||||
expect(attrs).to.be.ok();
|
||||
expect(attrs.disabled).to.equal('');
|
||||
});
|
||||
|
||||
it('should handle comments: ' + comment, function() {
|
||||
var elem = parse.evaluate(comment, defaultOpts)[0];
|
||||
expect(elem.type).to.equal('comment');
|
||||
expect(elem.data).to.equal(' sexy ');
|
||||
});
|
||||
|
||||
it('should handle conditional comments: ' + conditional, function() {
|
||||
var elem = parse.evaluate(conditional, defaultOpts)[0];
|
||||
expect(elem.type).to.equal('comment');
|
||||
expect(elem.data).to.equal(conditional.replace('<!--', '').replace('-->', ''));
|
||||
});
|
||||
|
||||
it('should handle text: ' + text, function() {
|
||||
var text_ = parse.evaluate(text, defaultOpts)[0];
|
||||
expect(text_.type).to.equal('text');
|
||||
expect(text_.data).to.equal('lorem ipsum');
|
||||
});
|
||||
|
||||
it('should handle script tags: ' + script, function() {
|
||||
var script_ = parse.evaluate(script, defaultOpts)[0];
|
||||
expect(script_.type).to.equal('script');
|
||||
expect(script_.name).to.equal('script');
|
||||
expect(script_.attribs.type).to.equal('text/javascript');
|
||||
expect(script_.children).to.have.length(1);
|
||||
expect(script_.children[0].type).to.equal('text');
|
||||
expect(script_.children[0].data).to.equal('alert("hi world!");');
|
||||
});
|
||||
|
||||
it('should handle style tags: ' + style, function() {
|
||||
var style_ = parse.evaluate(style, defaultOpts)[0];
|
||||
expect(style_.type).to.equal('style');
|
||||
expect(style_.name).to.equal('style');
|
||||
expect(style_.attribs.type).to.equal('text/css');
|
||||
expect(style_.children).to.have.length(1);
|
||||
expect(style_.children[0].type).to.equal('text');
|
||||
expect(style_.children[0].data).to.equal(' h2 { color:blue; } ');
|
||||
});
|
||||
|
||||
it('should handle directives: ' + directive, function() {
|
||||
var elem = parse.evaluate(directive, defaultOpts)[0];
|
||||
expect(elem.type).to.equal('directive');
|
||||
expect(elem.data).to.equal('!doctype html');
|
||||
expect(elem.name).to.equal('!doctype');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.parse', function() {
|
||||
|
||||
// root test utility
|
||||
function rootTest(root) {
|
||||
expect(root.name).to.equal('root');
|
||||
|
||||
// Should exist but be null
|
||||
expect(root.next).to.be(null);
|
||||
expect(root.prev).to.be(null);
|
||||
expect(root.parent).to.be(null);
|
||||
|
||||
var child = root.children[0];
|
||||
expect(child.parent).to.be(null);
|
||||
}
|
||||
|
||||
it('should add root to: ' + basic, function() {
|
||||
var root = parse(basic, defaultOpts);
|
||||
rootTest(root);
|
||||
expect(root.children).to.have.length(1);
|
||||
expect(root.children[0].name).to.equal('html');
|
||||
});
|
||||
|
||||
it('should add root to: ' + siblings, function() {
|
||||
var root = parse(siblings, defaultOpts);
|
||||
rootTest(root);
|
||||
expect(root.children).to.have.length(2);
|
||||
expect(root.children[0].name).to.equal('h2');
|
||||
expect(root.children[1].name).to.equal('p');
|
||||
expect(root.children[1].parent).to.equal(null);
|
||||
});
|
||||
|
||||
it('should add root to: ' + comment, function() {
|
||||
var root = parse(comment, defaultOpts);
|
||||
rootTest(root);
|
||||
expect(root.children).to.have.length(1);
|
||||
expect(root.children[0].type).to.equal('comment');
|
||||
});
|
||||
|
||||
it('should add root to: ' + text, function() {
|
||||
var root = parse(text, defaultOpts);
|
||||
rootTest(root);
|
||||
expect(root.children).to.have.length(1);
|
||||
expect(root.children[0].type).to.equal('text');
|
||||
});
|
||||
|
||||
it('should add root to: ' + scriptEmpty, function() {
|
||||
var root = parse(scriptEmpty, defaultOpts);
|
||||
rootTest(root);
|
||||
expect(root.children).to.have.length(1);
|
||||
expect(root.children[0].type).to.equal('script');
|
||||
});
|
||||
|
||||
it('should add root to: ' + styleEmpty, function() {
|
||||
var root = parse(styleEmpty, defaultOpts);
|
||||
rootTest(root);
|
||||
expect(root.children).to.have.length(1);
|
||||
expect(root.children[0].type).to.equal('style');
|
||||
});
|
||||
|
||||
it('should add root to: ' + directive, function() {
|
||||
var root = parse(directive, defaultOpts);
|
||||
rootTest(root);
|
||||
expect(root.children).to.have.length(1);
|
||||
expect(root.children[0].type).to.equal('directive');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
38
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/utilities.js
generated
vendored
Normal file
38
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/utilities.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
var expect = require('expect.js'),
|
||||
cheerio = require('..'),
|
||||
food = require('./fixtures').food;
|
||||
|
||||
describe('utility methods', function() {
|
||||
|
||||
describe('.contains', function() {
|
||||
|
||||
var $;
|
||||
|
||||
beforeEach(function() {
|
||||
$ = cheerio.load(food);
|
||||
});
|
||||
|
||||
it('(container, contained) : should correctly detect the provided element', function() {
|
||||
var $food = $('#food');
|
||||
var $fruits = $('#fruits');
|
||||
var $apple = $('.apple');
|
||||
|
||||
expect($.contains($food[0], $fruits[0])).to.equal(true);
|
||||
expect($.contains($food[0], $apple[0])).to.equal(true);
|
||||
});
|
||||
|
||||
it('(container, other) : should not detect elements that are not contained', function() {
|
||||
var $fruits = $('#fruits');
|
||||
var $vegetables = $('#vegetables');
|
||||
var $apple = $('.apple');
|
||||
|
||||
expect($.contains($vegetables[0], $apple[0])).to.equal(false);
|
||||
expect($.contains($fruits[0], $vegetables[0])).to.equal(false);
|
||||
expect($.contains($vegetables[0], $fruits[0])).to.equal(false);
|
||||
expect($.contains($fruits[0], $fruits[0])).to.equal(false);
|
||||
expect($.contains($vegetables[0], $vegetables[0])).to.equal(false);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
54
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/xml.js
generated
vendored
Normal file
54
node_modules/gitbook-plugin-multipart/node_modules/cheerio/test/xml.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
var expect = require('expect.js'),
|
||||
_ = require('lodash'),
|
||||
cheerio = require('..');
|
||||
|
||||
var xml = function(str, options) {
|
||||
options = _.extend({ xmlMode: true }, options);
|
||||
var dom = cheerio.load(str, options);
|
||||
return dom.xml();
|
||||
};
|
||||
|
||||
var dom = function(str, options) {
|
||||
var $ = cheerio.load('', options);
|
||||
return $(str).html();
|
||||
};
|
||||
|
||||
describe('render', function() {
|
||||
|
||||
describe('(xml)', function() {
|
||||
|
||||
it('should render <media:thumbnail /> tags correctly', function() {
|
||||
var str = '<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123" />';
|
||||
expect(xml(str)).to.equal('<media:thumbnail url="http://www.foo.com/keyframe.jpg" width="75" height="50" time="12:05:01.123"/>');
|
||||
});
|
||||
|
||||
it('should render <link /> tags (RSS) correctly', function() {
|
||||
var str = '<link>http://www.github.com/</link>';
|
||||
expect(xml(str)).to.equal('<link>http://www.github.com/</link>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('(dom)', function () {
|
||||
|
||||
it('should keep camelCase for new nodes', function() {
|
||||
var str = '<g><someElem someAttribute="something">hello</someElem></g>';
|
||||
expect(dom(str, {xmlMode: false})).to.equal('<someelem someattribute="something">hello</someelem>');
|
||||
});
|
||||
|
||||
it('should keep camelCase for new nodes', function() {
|
||||
var str = '<g><someElem someAttribute="something">hello</someElem></g>';
|
||||
expect(dom(str, {xmlMode: true})).to.equal('<someElem someAttribute="something">hello</someElem>');
|
||||
});
|
||||
|
||||
it('should maintain the parsing options of distinct contexts independently', function() {
|
||||
var str = '<g><someElem someAttribute="something">hello</someElem></g>';
|
||||
var $x = cheerio.load('', { xmlMode: false });
|
||||
var $h = cheerio.load('', { xmlMode: true });
|
||||
|
||||
expect($x(str).html()).to.equal('<someelem someattribute="something">hello</someelem>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
4
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/.travis.yml
generated
vendored
Normal file
4
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- 0.11
|
182
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/index.js
generated
vendored
Normal file
182
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/index.js
generated
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
Module dependencies
|
||||
*/
|
||||
var ElementType = require('domelementtype');
|
||||
var entities = require('entities');
|
||||
|
||||
/*
|
||||
Boolean Attributes
|
||||
*/
|
||||
var booleanAttributes = {
|
||||
__proto__: null,
|
||||
allowfullscreen: true,
|
||||
async: true,
|
||||
autofocus: true,
|
||||
autoplay: true,
|
||||
checked: true,
|
||||
controls: true,
|
||||
default: true,
|
||||
defer: true,
|
||||
disabled: true,
|
||||
hidden: true,
|
||||
ismap: true,
|
||||
loop: true,
|
||||
multiple: true,
|
||||
muted: true,
|
||||
open: true,
|
||||
readonly: true,
|
||||
required: true,
|
||||
reversed: true,
|
||||
scoped: true,
|
||||
seamless: true,
|
||||
selected: true,
|
||||
typemustmatch: true
|
||||
};
|
||||
|
||||
var unencodedElements = {
|
||||
__proto__: null,
|
||||
style: true,
|
||||
script: true,
|
||||
xmp: true,
|
||||
iframe: true,
|
||||
noembed: true,
|
||||
noframes: true,
|
||||
plaintext: true,
|
||||
noscript: true
|
||||
};
|
||||
|
||||
/*
|
||||
Format attributes
|
||||
*/
|
||||
function formatAttrs(attributes, opts) {
|
||||
if (!attributes) return;
|
||||
|
||||
var output = '',
|
||||
value;
|
||||
|
||||
// Loop through the attributes
|
||||
for (var key in attributes) {
|
||||
value = attributes[key];
|
||||
if (output) {
|
||||
output += ' ';
|
||||
}
|
||||
|
||||
if (!value && booleanAttributes[key]) {
|
||||
output += key;
|
||||
} else {
|
||||
output += key + '="' + (opts.decodeEntities ? entities.encodeXML(value) : value) + '"';
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
Self-enclosing tags (stolen from node-htmlparser)
|
||||
*/
|
||||
var singleTag = {
|
||||
__proto__: null,
|
||||
area: true,
|
||||
base: true,
|
||||
basefont: true,
|
||||
br: true,
|
||||
col: true,
|
||||
command: true,
|
||||
embed: true,
|
||||
frame: true,
|
||||
hr: true,
|
||||
img: true,
|
||||
input: true,
|
||||
isindex: true,
|
||||
keygen: true,
|
||||
link: true,
|
||||
meta: true,
|
||||
param: true,
|
||||
source: true,
|
||||
track: true,
|
||||
wbr: true,
|
||||
|
||||
//common self closing svg elements
|
||||
path: true,
|
||||
circle: true,
|
||||
ellipse: true,
|
||||
line: true,
|
||||
rect: true,
|
||||
use: true
|
||||
};
|
||||
|
||||
var render = module.exports = function(dom, opts) {
|
||||
if (!Array.isArray(dom) && !dom.cheerio) dom = [dom];
|
||||
opts = opts || {};
|
||||
|
||||
var output = '';
|
||||
|
||||
for(var i = 0; i < dom.length; i++){
|
||||
var elem = dom[i];
|
||||
|
||||
if (elem.type === 'root')
|
||||
output += render(elem.children, opts);
|
||||
else if (ElementType.isTag(elem))
|
||||
output += renderTag(elem, opts);
|
||||
else if (elem.type === ElementType.Directive)
|
||||
output += renderDirective(elem);
|
||||
else if (elem.type === ElementType.Comment)
|
||||
output += renderComment(elem);
|
||||
else if (elem.type === ElementType.CDATA)
|
||||
output += renderCdata(elem);
|
||||
else
|
||||
output += renderText(elem, opts);
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
function renderTag(elem, opts) {
|
||||
var tag = '<' + elem.name,
|
||||
attribs = formatAttrs(elem.attribs, opts);
|
||||
|
||||
if (attribs) {
|
||||
tag += ' ' + attribs;
|
||||
}
|
||||
|
||||
if (
|
||||
opts.xmlMode &&
|
||||
(!elem.children || elem.children.length === 0)
|
||||
) {
|
||||
tag += '/>';
|
||||
} else {
|
||||
tag += '>';
|
||||
tag += render(elem.children, opts);
|
||||
|
||||
if (!singleTag[elem.name] || opts.xmlMode) {
|
||||
tag += '</' + elem.name + '>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
function renderDirective(elem) {
|
||||
return '<' + elem.data + '>';
|
||||
}
|
||||
|
||||
function renderText(elem, opts) {
|
||||
var data = elem.data || '';
|
||||
|
||||
// if entities weren't decoded, no need to encode them back
|
||||
if (opts.decodeEntities && !(elem.parent && elem.parent.name in unencodedElements)) {
|
||||
data = entities.encodeXML(data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function renderCdata(elem) {
|
||||
return '<![CDATA[' + elem.children[0].data + ']]>';
|
||||
}
|
||||
|
||||
function renderComment(elem) {
|
||||
return '<!--' + elem.data + '-->';
|
||||
}
|
91
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/package.json
generated
vendored
Normal file
91
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/package.json
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "dom-serializer",
|
||||
"raw": "dom-serializer@~0.0.0",
|
||||
"rawSpec": "~0.0.0",
|
||||
"scope": null,
|
||||
"spec": ">=0.0.0 <0.1.0",
|
||||
"type": "range"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\cheerio"
|
||||
]
|
||||
],
|
||||
"_from": "dom-serializer@>=0.0.0 <0.1.0",
|
||||
"_id": "dom-serializer@0.0.1",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/gitbook-plugin-multipart/dom-serializer",
|
||||
"_npmUser": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
},
|
||||
"_npmVersion": "1.4.13",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "dom-serializer",
|
||||
"raw": "dom-serializer@~0.0.0",
|
||||
"rawSpec": "~0.0.0",
|
||||
"scope": null,
|
||||
"spec": ">=0.0.0 <0.1.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gitbook-plugin-multipart/cheerio"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.0.1.tgz",
|
||||
"_shasum": "9589827f1e32d22c37c829adabd59b3247af8eaf",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "dom-serializer@~0.0.0",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\cheerio",
|
||||
"author": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "Felix Boehm"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/cheeriojs/dom-renderer/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"domelementtype": "~1.1.1",
|
||||
"entities": "~1.1.1"
|
||||
},
|
||||
"description": "render dom nodes to string",
|
||||
"devDependencies": {
|
||||
"cheerio": "*",
|
||||
"expect.js": "~0.3.1",
|
||||
"jshint": "~2.3.0",
|
||||
"lodash": "~2.4.1",
|
||||
"mocha": "*"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "9589827f1e32d22c37c829adabd59b3247af8eaf",
|
||||
"tarball": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.0.1.tgz"
|
||||
},
|
||||
"gitHead": "d678d0face5a3eb6d338da949a29ce9b70cf901a",
|
||||
"homepage": "https://github.com/cheeriojs/dom-renderer",
|
||||
"keywords": [
|
||||
"html",
|
||||
"xml",
|
||||
"render"
|
||||
],
|
||||
"main": "./index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
}
|
||||
],
|
||||
"name": "dom-serializer",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/cheeriojs/dom-renderer.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha test.js"
|
||||
},
|
||||
"version": "0.0.1"
|
||||
}
|
103
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/test.js
generated
vendored
Normal file
103
node_modules/gitbook-plugin-multipart/node_modules/dom-serializer/test.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
var expect = require('expect.js'),
|
||||
defaultOpts = require('cheerio').prototype.options,
|
||||
_ = require('lodash'),
|
||||
parse = require('cheerio/lib/parse'),
|
||||
render = require('./index.js');
|
||||
|
||||
var html = function(preset, str, options) {
|
||||
options = _.defaults(options || {}, _.defaults(preset, defaultOpts));
|
||||
var dom = parse(str, options);
|
||||
return render(dom, options);
|
||||
};
|
||||
|
||||
var xml = function(str, options) {
|
||||
options = _.defaults(options || {}, defaultOpts);
|
||||
options.xmlMode = true;
|
||||
var dom = parse(str, options);
|
||||
return render(dom, options);
|
||||
};
|
||||
|
||||
describe('render', function() {
|
||||
|
||||
// only test applicable to the default setup
|
||||
describe('(html)', function() {
|
||||
var htmlFunc = _.partial(html, {});
|
||||
// it doesn't really make sense for {decodeEntities: false}
|
||||
// since currently it will convert <hr class='blah'> into <hr class="blah"> anyway.
|
||||
it('should handle double quotes within single quoted attributes properly', function() {
|
||||
var str = '<hr class=\'an "edge" case\' />';
|
||||
expect(htmlFunc(str)).to.equal('<hr class="an "edge" case">');
|
||||
});
|
||||
});
|
||||
|
||||
// run html with default options
|
||||
describe('(html, {})', _.partial( testBody, _.partial(html, {}) ));
|
||||
|
||||
// run html with turned off decodeEntities
|
||||
describe('(html, {decodeEntities: false})', _.partial( testBody, _.partial(html, {decodeEntities: false}) ));
|
||||
|
||||
describe('(xml)', function() {
|
||||
|
||||
it('should render CDATA correctly', function() {
|
||||
var str = '<a> <b> <![CDATA[ asdf&asdf ]]> <c/> <![CDATA[ asdf&asdf ]]> </b> </a>';
|
||||
expect(xml(str)).to.equal(str);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
function testBody(html) {
|
||||
|
||||
it('should render <br /> tags correctly', function() {
|
||||
var str = '<br />';
|
||||
expect(html(str)).to.equal('<br>');
|
||||
});
|
||||
|
||||
it('should retain encoded HTML content within attributes', function() {
|
||||
var str = '<hr class="cheerio & node = happy parsing" />';
|
||||
expect(html(str)).to.equal('<hr class="cheerio & node = happy parsing">');
|
||||
});
|
||||
|
||||
it('should shorten the "checked" attribute when it contains the value "checked"', function() {
|
||||
var str = '<input checked/>';
|
||||
expect(html(str)).to.equal('<input checked>');
|
||||
});
|
||||
|
||||
it('should not shorten the "name" attribute when it contains the value "name"', function() {
|
||||
var str = '<input name="name"/>';
|
||||
expect(html(str)).to.equal('<input name="name">');
|
||||
});
|
||||
|
||||
it('should render comments correctly', function() {
|
||||
var str = '<!-- comment -->';
|
||||
expect(html(str)).to.equal('<!-- comment -->');
|
||||
});
|
||||
|
||||
it('should render whitespace by default', function() {
|
||||
var str = '<a href="./haha.html">hi</a> <a href="./blah.html">blah</a>';
|
||||
expect(html(str)).to.equal(str);
|
||||
});
|
||||
|
||||
it('should normalize whitespace if specified', function() {
|
||||
var str = '<a href="./haha.html">hi</a> <a href="./blah.html">blah </a>';
|
||||
expect(html(str, { normalizeWhitespace: true })).to.equal('<a href="./haha.html">hi</a> <a href="./blah.html">blah </a>');
|
||||
});
|
||||
|
||||
it('should preserve multiple hyphens in data attributes', function() {
|
||||
var str = '<div data-foo-bar-baz="value"></div>';
|
||||
expect(html(str)).to.equal('<div data-foo-bar-baz="value"></div>');
|
||||
});
|
||||
|
||||
it('should not encode characters in script tag', function() {
|
||||
var str = '<script>alert("hello world")</script>';
|
||||
expect(html(str)).to.equal(str);
|
||||
});
|
||||
|
||||
it('should not encode json data', function() {
|
||||
var str = '<script>var json = {"simple_value": "value", "value_with_tokens": ""here & \'there\'""};</script>';
|
||||
expect(html(str)).to.equal(str);
|
||||
});
|
||||
|
||||
}
|
11
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/LICENSE
generated
vendored
Normal file
11
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) Felix Böhm
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/index.js
generated
vendored
Normal file
14
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/index.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
//Types of elements found in the DOM
|
||||
module.exports = {
|
||||
Text: "text", //Text
|
||||
Directive: "directive", //<? ... ?>
|
||||
Comment: "comment", //<!-- ... -->
|
||||
Script: "script", //<script> tags
|
||||
Style: "style", //<style> tags
|
||||
Tag: "tag", //Any tag
|
||||
CDATA: "cdata", //<![CDATA[ ... ]]>
|
||||
|
||||
isTag: function(elem){
|
||||
return elem.type === "tag" || elem.type === "script" || elem.type === "style";
|
||||
}
|
||||
};
|
82
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/package.json
generated
vendored
Normal file
82
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/package.json
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "domelementtype",
|
||||
"raw": "domelementtype@~1.1.1",
|
||||
"rawSpec": "~1.1.1",
|
||||
"scope": null,
|
||||
"spec": ">=1.1.1 <1.2.0",
|
||||
"type": "range"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\dom-serializer"
|
||||
]
|
||||
],
|
||||
"_from": "domelementtype@>=1.1.1 <1.2.0",
|
||||
"_id": "domelementtype@1.1.3",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/gitbook-plugin-multipart/domelementtype",
|
||||
"_nodeVersion": "0.10.32",
|
||||
"_npmUser": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
},
|
||||
"_npmVersion": "2.1.5",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "domelementtype",
|
||||
"raw": "domelementtype@~1.1.1",
|
||||
"rawSpec": "~1.1.1",
|
||||
"scope": null,
|
||||
"spec": ">=1.1.1 <1.2.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gitbook-plugin-multipart/dom-serializer",
|
||||
"/gitbook-plugin-multipart/domhandler",
|
||||
"/gitbook-plugin-multipart/htmlparser2"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz",
|
||||
"_shasum": "bd28773e2642881aec51544924299c5cd822185b",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "domelementtype@~1.1.1",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\dom-serializer",
|
||||
"author": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "Felix Boehm"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/FB55/domelementtype/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "all the types of nodes in htmlparser2's dom",
|
||||
"devDependencies": {},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "bd28773e2642881aec51544924299c5cd822185b",
|
||||
"tarball": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz"
|
||||
},
|
||||
"gitHead": "012a97a1d38737e096de2045b2b5f28768d8187e",
|
||||
"homepage": "https://github.com/FB55/domelementtype",
|
||||
"keywords": [
|
||||
"dom",
|
||||
"htmlparser2"
|
||||
],
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
}
|
||||
],
|
||||
"name": "domelementtype",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/FB55/domelementtype.git"
|
||||
},
|
||||
"scripts": {},
|
||||
"version": "1.1.3"
|
||||
}
|
1
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/readme.md
generated
vendored
Normal file
1
node_modules/gitbook-plugin-multipart/node_modules/domelementtype/readme.md
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
all the types of nodes in htmlparser2's dom
|
7
node_modules/gitbook-plugin-multipart/node_modules/domhandler/.travis.yml
generated
vendored
Normal file
7
node_modules/gitbook-plugin-multipart/node_modules/domhandler/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
before_install:
|
||||
- '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm install -g npm@1.4.28'
|
||||
- npm install -g npm@latest
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
- 0.10
|
11
node_modules/gitbook-plugin-multipart/node_modules/domhandler/LICENSE
generated
vendored
Normal file
11
node_modules/gitbook-plugin-multipart/node_modules/domhandler/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) Felix Böhm
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
171
node_modules/gitbook-plugin-multipart/node_modules/domhandler/index.js
generated
vendored
Normal file
171
node_modules/gitbook-plugin-multipart/node_modules/domhandler/index.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
var ElementType = require("domelementtype");
|
||||
|
||||
var re_whitespace = /\s+/g;
|
||||
var NodePrototype = require("./lib/node");
|
||||
var ElementPrototype = require("./lib/element");
|
||||
|
||||
function DomHandler(callback, options, elementCB){
|
||||
if(typeof callback === "object"){
|
||||
elementCB = options;
|
||||
options = callback;
|
||||
callback = null;
|
||||
} else if(typeof options === "function"){
|
||||
elementCB = options;
|
||||
options = defaultOpts;
|
||||
}
|
||||
this._callback = callback;
|
||||
this._options = options || defaultOpts;
|
||||
this._elementCB = elementCB;
|
||||
this.dom = [];
|
||||
this._done = false;
|
||||
this._tagStack = [];
|
||||
}
|
||||
|
||||
//default options
|
||||
var defaultOpts = {
|
||||
normalizeWhitespace: false //Replace all whitespace with single spaces
|
||||
};
|
||||
|
||||
//Resets the handler back to starting state
|
||||
DomHandler.prototype.onreset = function(){
|
||||
DomHandler.call(this, this._callback, this._options, this._elementCB);
|
||||
};
|
||||
|
||||
//Signals the handler that parsing is done
|
||||
DomHandler.prototype.onend = function(){
|
||||
if(this._done) return;
|
||||
this._done = true;
|
||||
this._handleCallback(null);
|
||||
};
|
||||
|
||||
DomHandler.prototype._handleCallback =
|
||||
DomHandler.prototype.onerror = function(error){
|
||||
if(typeof this._callback === "function"){
|
||||
this._callback(error, this.dom);
|
||||
} else {
|
||||
if(error) throw error;
|
||||
}
|
||||
};
|
||||
|
||||
DomHandler.prototype.onclosetag = function(){
|
||||
//if(this._tagStack.pop().name !== name) this._handleCallback(Error("Tagname didn't match!"));
|
||||
var elem = this._tagStack.pop();
|
||||
if(this._elementCB) this._elementCB(elem);
|
||||
};
|
||||
|
||||
DomHandler.prototype._addDomElement = function(element){
|
||||
var parent = this._tagStack[this._tagStack.length - 1];
|
||||
var siblings = parent ? parent.children : this.dom;
|
||||
var previousSibling = siblings[siblings.length - 1];
|
||||
|
||||
element.next = null;
|
||||
|
||||
if (this._options.withDomLvl1) {
|
||||
element.__proto__ = element.type === "tag" ? ElementPrototype : NodePrototype;
|
||||
}
|
||||
|
||||
if(previousSibling){
|
||||
element.prev = previousSibling;
|
||||
previousSibling.next = element;
|
||||
} else {
|
||||
element.prev = null;
|
||||
}
|
||||
|
||||
siblings.push(element);
|
||||
element.parent = parent || null;
|
||||
};
|
||||
|
||||
DomHandler.prototype.onopentag = function(name, attribs){
|
||||
var element = {
|
||||
type: name === "script" ? ElementType.Script : name === "style" ? ElementType.Style : ElementType.Tag,
|
||||
name: name,
|
||||
attribs: attribs,
|
||||
children: []
|
||||
};
|
||||
|
||||
this._addDomElement(element);
|
||||
|
||||
this._tagStack.push(element);
|
||||
};
|
||||
|
||||
DomHandler.prototype.ontext = function(data){
|
||||
//the ignoreWhitespace is officially dropped, but for now,
|
||||
//it's an alias for normalizeWhitespace
|
||||
var normalize = this._options.normalizeWhitespace || this._options.ignoreWhitespace;
|
||||
|
||||
var lastTag;
|
||||
|
||||
if(!this._tagStack.length && this.dom.length && (lastTag = this.dom[this.dom.length-1]).type === ElementType.Text){
|
||||
if(normalize){
|
||||
lastTag.data = (lastTag.data + data).replace(re_whitespace, " ");
|
||||
} else {
|
||||
lastTag.data += data;
|
||||
}
|
||||
} else {
|
||||
if(
|
||||
this._tagStack.length &&
|
||||
(lastTag = this._tagStack[this._tagStack.length - 1]) &&
|
||||
(lastTag = lastTag.children[lastTag.children.length - 1]) &&
|
||||
lastTag.type === ElementType.Text
|
||||
){
|
||||
if(normalize){
|
||||
lastTag.data = (lastTag.data + data).replace(re_whitespace, " ");
|
||||
} else {
|
||||
lastTag.data += data;
|
||||
}
|
||||
} else {
|
||||
if(normalize){
|
||||
data = data.replace(re_whitespace, " ");
|
||||
}
|
||||
|
||||
this._addDomElement({
|
||||
data: data,
|
||||
type: ElementType.Text
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DomHandler.prototype.oncomment = function(data){
|
||||
var lastTag = this._tagStack[this._tagStack.length - 1];
|
||||
|
||||
if(lastTag && lastTag.type === ElementType.Comment){
|
||||
lastTag.data += data;
|
||||
return;
|
||||
}
|
||||
|
||||
var element = {
|
||||
data: data,
|
||||
type: ElementType.Comment
|
||||
};
|
||||
|
||||
this._addDomElement(element);
|
||||
this._tagStack.push(element);
|
||||
};
|
||||
|
||||
DomHandler.prototype.oncdatastart = function(){
|
||||
var element = {
|
||||
children: [{
|
||||
data: "",
|
||||
type: ElementType.Text
|
||||
}],
|
||||
type: ElementType.CDATA
|
||||
};
|
||||
|
||||
this._addDomElement(element);
|
||||
this._tagStack.push(element);
|
||||
};
|
||||
|
||||
DomHandler.prototype.oncommentend = DomHandler.prototype.oncdataend = function(){
|
||||
this._tagStack.pop();
|
||||
};
|
||||
|
||||
DomHandler.prototype.onprocessinginstruction = function(name, data){
|
||||
this._addDomElement({
|
||||
name: name,
|
||||
data: data,
|
||||
type: ElementType.Directive
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = DomHandler;
|
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/lib/element.js
generated
vendored
Normal file
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/lib/element.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
// DOM-Level-1-compliant structure
|
||||
var NodePrototype = require('./node');
|
||||
var ElementPrototype = module.exports = Object.create(NodePrototype);
|
||||
|
||||
var domLvl1 = {
|
||||
tagName: "name"
|
||||
};
|
||||
|
||||
Object.keys(domLvl1).forEach(function(key) {
|
||||
var shorthand = domLvl1[key];
|
||||
Object.defineProperty(ElementPrototype, key, {
|
||||
get: function() {
|
||||
return this[shorthand] || null;
|
||||
},
|
||||
set: function(val) {
|
||||
this[shorthand] = val;
|
||||
return val;
|
||||
}
|
||||
});
|
||||
});
|
44
node_modules/gitbook-plugin-multipart/node_modules/domhandler/lib/node.js
generated
vendored
Normal file
44
node_modules/gitbook-plugin-multipart/node_modules/domhandler/lib/node.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// This object will be used as the prototype for Nodes when creating a
|
||||
// DOM-Level-1-compliant structure.
|
||||
var NodePrototype = module.exports = {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
var domLvl1 = {
|
||||
tagName: "name",
|
||||
childNodes: "children",
|
||||
parentNode: "parent",
|
||||
previousSibling: "prev",
|
||||
nextSibling: "next",
|
||||
nodeValue: "data"
|
||||
};
|
||||
|
||||
var nodeTypes = {
|
||||
element: 1,
|
||||
text: 3,
|
||||
cdata: 4,
|
||||
comment: 8
|
||||
};
|
||||
|
||||
Object.keys(domLvl1).forEach(function(key) {
|
||||
var shorthand = domLvl1[key];
|
||||
Object.defineProperty(NodePrototype, key, {
|
||||
get: function() {
|
||||
return this[shorthand] || null;
|
||||
},
|
||||
set: function(val) {
|
||||
this[shorthand] = val;
|
||||
return val;
|
||||
}
|
||||
});
|
||||
});
|
101
node_modules/gitbook-plugin-multipart/node_modules/domhandler/package.json
generated
vendored
Normal file
101
node_modules/gitbook-plugin-multipart/node_modules/domhandler/package.json
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "domhandler",
|
||||
"raw": "domhandler@2.2",
|
||||
"rawSpec": "2.2",
|
||||
"scope": null,
|
||||
"spec": ">=2.2.0 <2.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\htmlparser2"
|
||||
]
|
||||
],
|
||||
"_from": "domhandler@>=2.2.0 <2.3.0",
|
||||
"_id": "domhandler@2.2.1",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/gitbook-plugin-multipart/domhandler",
|
||||
"_nodeVersion": "0.10.32",
|
||||
"_npmUser": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
},
|
||||
"_npmVersion": "2.1.5",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "domhandler",
|
||||
"raw": "domhandler@2.2",
|
||||
"rawSpec": "2.2",
|
||||
"scope": null,
|
||||
"spec": ">=2.2.0 <2.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gitbook-plugin-multipart/htmlparser2"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.2.1.tgz",
|
||||
"_shasum": "59df9dcd227e808b365ae73e1f6684ac3d946fc2",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "domhandler@2.2",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\htmlparser2",
|
||||
"author": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "Felix Boehm"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fb55/DomHandler/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"domelementtype": "1"
|
||||
},
|
||||
"description": "handler for htmlparser2 that turns pages into a dom",
|
||||
"devDependencies": {
|
||||
"htmlparser2": "3.2",
|
||||
"jshint": "~2.3.0",
|
||||
"mocha": "1"
|
||||
},
|
||||
"directories": {
|
||||
"test": "tests"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "59df9dcd227e808b365ae73e1f6684ac3d946fc2",
|
||||
"tarball": "https://registry.npmjs.org/domhandler/-/domhandler-2.2.1.tgz"
|
||||
},
|
||||
"gitHead": "3b4885326dbbc85b71094fc988b93efb9c926b08",
|
||||
"homepage": "https://github.com/fb55/DomHandler",
|
||||
"jshintConfig": {
|
||||
"globals": {
|
||||
"it": true
|
||||
},
|
||||
"node": true,
|
||||
"proto": true,
|
||||
"quotmark": "double",
|
||||
"trailing": true,
|
||||
"undef": true,
|
||||
"unused": true
|
||||
},
|
||||
"keywords": [
|
||||
"dom",
|
||||
"htmlparser2"
|
||||
],
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
}
|
||||
],
|
||||
"name": "domhandler",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/fb55/DomHandler.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha -R list && jshint index.js test/"
|
||||
},
|
||||
"version": "2.2.1"
|
||||
}
|
102
node_modules/gitbook-plugin-multipart/node_modules/domhandler/readme.md
generated
vendored
Normal file
102
node_modules/gitbook-plugin-multipart/node_modules/domhandler/readme.md
generated
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
#DOMHandler [](http://travis-ci.org/fb55/DomHandler)
|
||||
|
||||
The DOM handler (formally known as DefaultHandler) creates a tree containing all nodes of a page. The tree may be manipulated using the DOMUtils library.
|
||||
|
||||
##Usage
|
||||
```javascript
|
||||
var handler = new DomHandler([ <func> callback(err, dom), ] [ <obj> options ]);
|
||||
// var parser = new Parser(handler[, options]);
|
||||
```
|
||||
|
||||
##Example
|
||||
```javascript
|
||||
var htmlparser = require("htmlparser2");
|
||||
var rawHtml = "Xyz <script language= javascript>var foo = '<<bar>>';< / script><!--<!-- Waah! -- -->";
|
||||
var handler = new htmlparser.DomHandler(function (error, dom) {
|
||||
if (error)
|
||||
[...do something for errors...]
|
||||
else
|
||||
[...parsing done, do something...]
|
||||
console.log(dom);
|
||||
});
|
||||
var parser = new htmlparser.Parser(handler);
|
||||
parser.write(rawHtml);
|
||||
parser.done();
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```javascript
|
||||
[{
|
||||
data: 'Xyz ',
|
||||
type: 'text'
|
||||
}, {
|
||||
type: 'script',
|
||||
name: 'script',
|
||||
attribs: {
|
||||
language: 'javascript'
|
||||
},
|
||||
children: [{
|
||||
data: 'var foo = \'<bar>\';<',
|
||||
type: 'text'
|
||||
}]
|
||||
}, {
|
||||
data: '<!-- Waah! -- ',
|
||||
type: 'comment'
|
||||
}]
|
||||
```
|
||||
|
||||
##Option: normalizeWhitespace
|
||||
Indicates whether the whitespace in text nodes should be normalized (= all whitespace should be replaced with single spaces). The default value is "false".
|
||||
|
||||
The following HTML will be used:
|
||||
|
||||
```html
|
||||
<font>
|
||||
<br>this is the text
|
||||
<font>
|
||||
```
|
||||
|
||||
###Example: true
|
||||
|
||||
```javascript
|
||||
[{
|
||||
type: 'tag',
|
||||
name: 'font',
|
||||
children: [{
|
||||
data: ' ',
|
||||
type: 'text'
|
||||
}, {
|
||||
type: 'tag',
|
||||
name: 'br'
|
||||
}, {
|
||||
data: 'this is the text ',
|
||||
type: 'text'
|
||||
}, {
|
||||
type: 'tag',
|
||||
name: 'font'
|
||||
}]
|
||||
}]
|
||||
```
|
||||
|
||||
###Example: false
|
||||
|
||||
```javascript
|
||||
[{
|
||||
type: 'tag',
|
||||
name: 'font',
|
||||
children: [{
|
||||
data: '\n\t',
|
||||
type: 'text'
|
||||
}, {
|
||||
type: 'tag',
|
||||
name: 'br'
|
||||
}, {
|
||||
data: 'this is the text\n',
|
||||
type: 'text'
|
||||
}, {
|
||||
type: 'tag',
|
||||
name: 'font'
|
||||
}]
|
||||
}]
|
||||
```
|
57
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/01-basic.json
generated
vendored
Normal file
57
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/01-basic.json
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "Basic test",
|
||||
"options": {},
|
||||
"html": "<!DOCTYPE html><html><title>The Title</title><body>Hello world</body></html>",
|
||||
"expected": [
|
||||
{
|
||||
"name": "!doctype",
|
||||
"data": "!DOCTYPE html",
|
||||
"type": "directive"
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "html",
|
||||
"attribs": {},
|
||||
"parent": null,
|
||||
"children": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "title",
|
||||
"attribs": {},
|
||||
"parent": {
|
||||
"type": "tag",
|
||||
"name": "html",
|
||||
"attribs": {}
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"data": "The Title",
|
||||
"type": "text",
|
||||
"parent": {
|
||||
"type": "tag",
|
||||
"name": "title",
|
||||
"attribs": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "body",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": "Hello world",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"prev": {
|
||||
"type": "tag",
|
||||
"name": "title",
|
||||
"attribs": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
21
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/02-single_tag_1.json
generated
vendored
Normal file
21
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/02-single_tag_1.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Single Tag 1",
|
||||
"options": {},
|
||||
"html": "<br>text</br>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
},
|
||||
{
|
||||
"data": "text",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
}
|
||||
]
|
||||
}
|
21
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/03-single_tag_2.json
generated
vendored
Normal file
21
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/03-single_tag_2.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Single Tag 2",
|
||||
"options": {},
|
||||
"html": "<br>text<br>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
},
|
||||
{
|
||||
"data": "text",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
}
|
||||
]
|
||||
}
|
27
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/04-unescaped_in_script.json
generated
vendored
Normal file
27
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/04-unescaped_in_script.json
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "Unescaped chars in script",
|
||||
"options": {},
|
||||
"html": "<head><script language=\"Javascript\">var foo = \"<bar>\"; alert(2 > foo); var baz = 10 << 2; var zip = 10 >> 1; var yap = \"<<>>>><<\";</script></head>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "head",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"type": "script",
|
||||
"name": "script",
|
||||
"attribs": {
|
||||
"language": "Javascript"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"data": "var foo = \"<bar>\"; alert(2 > foo); var baz = 10 << 2; var zip = 10 >> 1; var yap = \"<<>>>><<\";",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/05-tags_in_comment.json
generated
vendored
Normal file
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/05-tags_in_comment.json
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Special char in comment",
|
||||
"options": {},
|
||||
"html": "<head><!-- commented out tags <title>Test</title>--></head>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "head",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": " commented out tags <title>Test</title>",
|
||||
"type": "comment"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/06-comment_in_script.json
generated
vendored
Normal file
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/06-comment_in_script.json
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Script source in comment",
|
||||
"options": {},
|
||||
"html": "<script><!--var foo = 1;--></script>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "script",
|
||||
"name": "script",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": "<!--var foo = 1;-->",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/07-unescaped_in_style.json
generated
vendored
Normal file
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/07-unescaped_in_style.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Unescaped chars in style",
|
||||
"options": {},
|
||||
"html": "<style type=\"text/css\">\n body > p\n\t{ font-weight: bold; }</style>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "style",
|
||||
"name": "style",
|
||||
"attribs": {
|
||||
"type": "text/css"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"data": "\n body > p\n\t{ font-weight: bold; }",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json
generated
vendored
Normal file
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Extra spaces in tag",
|
||||
"options": {},
|
||||
"html": "<font\t\n size='14' \n>the text</\t\nfont\t \n>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "font",
|
||||
"attribs": {
|
||||
"size": "14"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"data": "the text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/09-unquoted_attrib.json
generated
vendored
Normal file
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/09-unquoted_attrib.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Unquoted attributes",
|
||||
"options": {},
|
||||
"html": "<font size= 14>the text</font>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "font",
|
||||
"attribs": {
|
||||
"size": "14"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"data": "the text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
15
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/10-singular_attribute.json
generated
vendored
Normal file
15
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/10-singular_attribute.json
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Singular attribute",
|
||||
"options": {},
|
||||
"html": "<option value='foo' selected>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "option",
|
||||
"attribs": {
|
||||
"value": "foo",
|
||||
"selected": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
40
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/11-text_outside_tags.json
generated
vendored
Normal file
40
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/11-text_outside_tags.json
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "Text outside tags",
|
||||
"options": {},
|
||||
"html": "Line one\n<br>\nline two",
|
||||
"expected": [
|
||||
{
|
||||
"data": "Line one\n",
|
||||
"type": "text",
|
||||
"prev": null,
|
||||
"next": {
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {},
|
||||
"prev": {
|
||||
"data": "Line one\n",
|
||||
"type": "text"
|
||||
},
|
||||
"next": {
|
||||
"data": "\nline two",
|
||||
"type": "text"
|
||||
}
|
||||
},
|
||||
{
|
||||
"data": "\nline two",
|
||||
"type": "text",
|
||||
"prev": {
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
},
|
||||
"next": null
|
||||
}
|
||||
]
|
||||
}
|
11
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/12-text_only.json
generated
vendored
Normal file
11
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/12-text_only.json
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Only text",
|
||||
"options": {},
|
||||
"html": "this is the text",
|
||||
"expected": [
|
||||
{
|
||||
"data": "this is the text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
19
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/13-comment_in_text.json
generated
vendored
Normal file
19
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/13-comment_in_text.json
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Comment within text",
|
||||
"options": {},
|
||||
"html": "this is <!-- the comment --> the text",
|
||||
"expected": [
|
||||
{
|
||||
"data": "this is ",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"data": " the comment ",
|
||||
"type": "comment"
|
||||
},
|
||||
{
|
||||
"data": " the text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/14-comment_in_text_in_script.json
generated
vendored
Normal file
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/14-comment_in_text_in_script.json
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Comment within text within script",
|
||||
"options": {},
|
||||
"html": "<script>this is <!-- the comment --> the text</script>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "script",
|
||||
"name": "script",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": "this is <!-- the comment --> the text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
22
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/15-non-verbose.json
generated
vendored
Normal file
22
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/15-non-verbose.json
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Option 'verbose' set to 'false'",
|
||||
"options": {
|
||||
"verbose": false
|
||||
},
|
||||
"html": "<font\t\n size='14' \n>the text</\t\nfont\t \n>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "font",
|
||||
"attribs": {
|
||||
"size": "14"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"data": "the text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
47
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/16-normalize_whitespace.json
generated
vendored
Normal file
47
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/16-normalize_whitespace.json
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "Normalize whitespace",
|
||||
"options": {
|
||||
"normalizeWhitespace": true
|
||||
},
|
||||
"html": "Line one\n<br>\t \r\n\f <br>\nline two<font><br> x </font>",
|
||||
"expected": [
|
||||
{
|
||||
"data": "Line one ",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
},
|
||||
{
|
||||
"data": " ",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
},
|
||||
{
|
||||
"data": " line two",
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "font",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "br",
|
||||
"attribs": {}
|
||||
},
|
||||
{
|
||||
"data": " x ",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/17-xml_namespace.json
generated
vendored
Normal file
18
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/17-xml_namespace.json
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "XML Namespace",
|
||||
"options": {},
|
||||
"html": "<ns:tag>text</ns:tag>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "ns:tag",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": "text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
16
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/18-enforce_empty_tags.json
generated
vendored
Normal file
16
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/18-enforce_empty_tags.json
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Enforce empty tags",
|
||||
"options": {},
|
||||
"html": "<link>text</link>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "link",
|
||||
"attribs": {}
|
||||
},
|
||||
{
|
||||
"data": "text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/19-ignore_empty_tags.json
generated
vendored
Normal file
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/19-ignore_empty_tags.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Ignore empty tags (xml mode)",
|
||||
"options": {
|
||||
"xmlMode": true
|
||||
},
|
||||
"html": "<link>text</link>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "link",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": "text",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/20-template_script_tags.json
generated
vendored
Normal file
20
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/20-template_script_tags.json
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Template script tags",
|
||||
"options": {},
|
||||
"html": "<script type=\"text/template\"><h1>Heading1</h1></script>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "script",
|
||||
"name": "script",
|
||||
"attribs": {
|
||||
"type": "text/template"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"data": "<h1>Heading1</h1>",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
15
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/21-conditional_comments.json
generated
vendored
Normal file
15
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/21-conditional_comments.json
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "Conditional comments",
|
||||
"options": {},
|
||||
"html": "<!--[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]--><!--[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]-->",
|
||||
"expected": [
|
||||
{
|
||||
"data": "[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]",
|
||||
"type": "comment"
|
||||
},
|
||||
{
|
||||
"data": "[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]",
|
||||
"type": "comment"
|
||||
}
|
||||
]
|
||||
}
|
41
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/22-lowercase_tags.json
generated
vendored
Normal file
41
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/22-lowercase_tags.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "lowercase tags",
|
||||
"options": {},
|
||||
"html": "<!DOCTYPE html><HTML><TITLE>The Title</title><BODY>Hello world</body></html>",
|
||||
"expected": [
|
||||
{
|
||||
"name": "!doctype",
|
||||
"data": "!DOCTYPE html",
|
||||
"type": "directive"
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "html",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "title",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": "The Title",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"name": "body",
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"data": "Hello world",
|
||||
"type": "text"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
131
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/23-dom-lvl1.json
generated
vendored
Normal file
131
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/cases/23-dom-lvl1.json
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
{
|
||||
"name": "DOM level 1",
|
||||
"options": { "withDomLvl1": true },
|
||||
"html": "<div>some stray text<h1>Hello, world.</h1><!-- comment node -->more stray text</div>",
|
||||
"expected": [
|
||||
{
|
||||
"type": "tag",
|
||||
"nodeType": 1,
|
||||
"name": "div",
|
||||
"tagName": "div",
|
||||
"attribs": {},
|
||||
"nodeValue": null,
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"nodeType": 3,
|
||||
"tagName": null,
|
||||
"data": "some stray text",
|
||||
"nodeValue": "some stray text",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null
|
||||
},
|
||||
{
|
||||
"type": "tag",
|
||||
"nodeType": 1,
|
||||
"name": "h1",
|
||||
"tagName": "h1",
|
||||
"nodeValue": null,
|
||||
"attribs": {},
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"nodeType": 3,
|
||||
"tagName": null,
|
||||
"data": "Hello, world.",
|
||||
"nodeValue": "Hello, world.",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null
|
||||
}
|
||||
],
|
||||
"firstChild": {
|
||||
"type": "text",
|
||||
"nodeType": 3,
|
||||
"tagName": null,
|
||||
"data": "Hello, world.",
|
||||
"nodeValue": "Hello, world.",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null
|
||||
},
|
||||
"lastChild": {
|
||||
"type": "text",
|
||||
"nodeType": 3,
|
||||
"tagName": null,
|
||||
"data": "Hello, world.",
|
||||
"nodeValue": "Hello, world.",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "comment",
|
||||
"nodeType": 8,
|
||||
"tagName": null,
|
||||
"data": " comment node ",
|
||||
"nodeValue": " comment node ",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null,
|
||||
"prev": {
|
||||
"type": "tag",
|
||||
"name": "h1",
|
||||
"nodeValue": null,
|
||||
"attribs": {}
|
||||
},
|
||||
"previousSibling": {
|
||||
"type": "tag",
|
||||
"name": "h1",
|
||||
"nodeValue": null,
|
||||
"attribs": {}
|
||||
},
|
||||
"next": {
|
||||
"type": "text",
|
||||
"tagName": null,
|
||||
"data": "more stray text"
|
||||
},
|
||||
"nextSibling": {
|
||||
"type": "text",
|
||||
"tagName": null,
|
||||
"data": "more stray text"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"nodeType": 3,
|
||||
"tagName": null,
|
||||
"data": "more stray text",
|
||||
"nodeValue": "more stray text",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null,
|
||||
"next": null,
|
||||
"nextSibling": null
|
||||
}
|
||||
],
|
||||
"firstChild": {
|
||||
"type": "text",
|
||||
"nodeType": 3,
|
||||
"tagName": null,
|
||||
"data": "some stray text",
|
||||
"nodeValue": "some stray text",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null
|
||||
},
|
||||
"lastChild": {
|
||||
"type": "text",
|
||||
"nodeType": 3,
|
||||
"tagName": null,
|
||||
"data": "more stray text",
|
||||
"nodeValue": "more stray text",
|
||||
"childNodes": null,
|
||||
"firstChild": null,
|
||||
"lastChild": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
58
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/tests.js
generated
vendored
Normal file
58
node_modules/gitbook-plugin-multipart/node_modules/domhandler/test/tests.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
var fs = require("fs"),
|
||||
path = require("path"),
|
||||
assert = require("assert"),
|
||||
util = require("util"),
|
||||
Parser = require("htmlparser2").Parser,
|
||||
Handler = require("../");
|
||||
|
||||
var basePath = path.resolve(__dirname, "cases"),
|
||||
inspectOpts = { showHidden: true, depth: null };
|
||||
|
||||
fs
|
||||
.readdirSync(basePath)
|
||||
.filter(RegExp.prototype.test, /\.json$/) //only allow .json files
|
||||
.map(function(name){
|
||||
return path.resolve(basePath, name);
|
||||
})
|
||||
.map(require)
|
||||
.forEach(function(test){
|
||||
it(test.name, function(){
|
||||
var expected = test.expected;
|
||||
|
||||
var handler = new Handler(function(err, actual){
|
||||
assert.ifError(err);
|
||||
try {
|
||||
compare(expected, actual);
|
||||
} catch(e){
|
||||
e.expected = util.inspect(expected, inspectOpts);
|
||||
e.actual = util.inspect(actual, inspectOpts);
|
||||
throw e;
|
||||
}
|
||||
}, test.options);
|
||||
|
||||
var data = test.html;
|
||||
|
||||
var parser = new Parser(handler, test.options);
|
||||
|
||||
//first, try to run the test via chunks
|
||||
for(var i = 0; i < data.length; i++){
|
||||
parser.write(data.charAt(i));
|
||||
}
|
||||
parser.done();
|
||||
|
||||
//then parse everything
|
||||
parser.parseComplete(data);
|
||||
});
|
||||
});
|
||||
|
||||
function compare(expected, result){
|
||||
assert.equal(typeof expected, typeof result, "types didn't match");
|
||||
if(typeof expected !== "object" || expected === null){
|
||||
assert.strictEqual(expected, result, "result doesn't equal expected");
|
||||
} else {
|
||||
for(var prop in expected){
|
||||
assert.ok(prop in result, "result didn't contain property " + prop);
|
||||
compare(expected[prop], result[prop]);
|
||||
}
|
||||
}
|
||||
}
|
2
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/.gitattributes
generated
vendored
Normal file
2
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/.gitattributes
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text eol=lf
|
6
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/.travis.yml
generated
vendored
Normal file
6
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.10
|
||||
- 0.11
|
||||
|
||||
script: npm run coveralls
|
18
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/LICENSE
generated
vendored
Normal file
18
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
Copyright 2010, 2011, Chris Winberry <chris@winberry.net>. All rights reserved.
|
||||
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.
|
86
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/README.md
generated
vendored
Normal file
86
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/README.md
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
#htmlparser2
|
||||
|
||||
[](https://npmjs.org/package/htmlparser2)
|
||||
[](https://npmjs.org/package/htmlparser2)
|
||||
[](http://travis-ci.org/fb55/htmlparser2)
|
||||
[](https://coveralls.io/r/fb55/htmlparser2)
|
||||
|
||||
A forgiving HTML/XML/RSS parser written in JS for NodeJS. The parser can handle streams (chunked data) and supports custom handlers for writing custom DOMs/output.
|
||||
|
||||
##Installing
|
||||
npm install htmlparser2
|
||||
|
||||
A live demo of htmlparser2 is available at http://demos.forbeslindesay.co.uk/htmlparser2/
|
||||
|
||||
##Usage
|
||||
|
||||
```javascript
|
||||
var htmlparser = require("htmlparser2");
|
||||
var parser = new htmlparser.Parser({
|
||||
onopentag: function(name, attribs){
|
||||
if(name === "script" && attribs.type === "text/javascript"){
|
||||
console.log("JS! Hooray!");
|
||||
}
|
||||
},
|
||||
ontext: function(text){
|
||||
console.log("-->", text);
|
||||
},
|
||||
onclosetag: function(tagname){
|
||||
if(tagname === "script"){
|
||||
console.log("That's it?!");
|
||||
}
|
||||
}
|
||||
});
|
||||
parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>';</ script>");
|
||||
parser.end();
|
||||
```
|
||||
|
||||
Output (simplified):
|
||||
|
||||
```javascript
|
||||
--> Xyz
|
||||
JS! Hooray!
|
||||
--> var foo = '<<bar>>';
|
||||
That's it?!
|
||||
```
|
||||
|
||||
Read more about the parser in the [wiki](https://github.com/fb55/htmlparser2/wiki/Parser-options).
|
||||
|
||||
##Get a DOM
|
||||
The `DomHandler` (known as `DefaultHandler` in the original `htmlparser` module) produces a DOM (document object model) that can be manipulated using the [`DomUtils`](https://github.com/fb55/DomUtils) helper.
|
||||
|
||||
The `DomHandler`, while still bundled with this module, was moved to its [own module](https://github.com/fb55/domhandler). Have a look at it for further information.
|
||||
|
||||
##Parsing RSS/RDF/Atom Feeds
|
||||
|
||||
```javascript
|
||||
new htmlparser.FeedHandler(function(<error> error, <object> feed){
|
||||
...
|
||||
});
|
||||
```
|
||||
|
||||
##Performance
|
||||
|
||||
After having some artificial benchmarks for some time, __@AndreasMadsen__ published his [`htmlparser-benchmark`](https://github.com/AndreasMadsen/htmlparser-benchmark), which benchmarks HTML parses based on real-world websites.
|
||||
|
||||
At the time of writing, the latest versions of all supported parsers show the following performance characteristics on [Travis CI](https://travis-ci.org/AndreasMadsen/htmlparser-benchmark/builds/10805007) (please note that Travis doesn't guarantee equal conditions for all tests):
|
||||
|
||||
```
|
||||
gumbo-parser : 34.9208 ms/file ± 21.4238
|
||||
html-parser : 24.8224 ms/file ± 15.8703
|
||||
html5 : 419.597 ms/file ± 264.265
|
||||
htmlparser : 60.0722 ms/file ± 384.844
|
||||
htmlparser2-dom: 12.0749 ms/file ± 6.49474
|
||||
htmlparser2 : 7.49130 ms/file ± 5.74368
|
||||
hubbub : 30.4980 ms/file ± 16.4682
|
||||
libxmljs : 14.1338 ms/file ± 18.6541
|
||||
parse5 : 22.0439 ms/file ± 15.3743
|
||||
sax : 49.6513 ms/file ± 26.6032
|
||||
```
|
||||
|
||||
##How is this different from [node-htmlparser](https://github.com/tautologistics/node-htmlparser)?
|
||||
This is a fork of the `htmlparser` module. The main difference is that this is intended to be used only with node (it runs on other platforms using [browserify](https://github.com/substack/node-browserify)). `htmlparser2` was rewritten multiple times and, while it maintains an API that's compatible with `htmlparser` in most cases, the projects don't share any code anymore.
|
||||
|
||||
The parser now provides a callback interface close to [sax.js](https://github.com/isaacs/sax-js) (originally targeted at [readabilitySAX](https://github.com/fb55/readabilitysax)). As a result, old handlers won't work anymore.
|
||||
|
||||
The `DefaultHandler` and the `RssHandler` were renamed to clarify their purpose (to `DomHandler` and `FeedHandler`). The old names are still available when requiring `htmlparser2`, so your code should work as expected.
|
55
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/CollectingHandler.js
generated
vendored
Normal file
55
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/CollectingHandler.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
module.exports = CollectingHandler;
|
||||
|
||||
function CollectingHandler(cbs){
|
||||
this._cbs = cbs || {};
|
||||
this.events = [];
|
||||
}
|
||||
|
||||
var EVENTS = require("./").EVENTS;
|
||||
Object.keys(EVENTS).forEach(function(name){
|
||||
if(EVENTS[name] === 0){
|
||||
name = "on" + name;
|
||||
CollectingHandler.prototype[name] = function(){
|
||||
this.events.push([name]);
|
||||
if(this._cbs[name]) this._cbs[name]();
|
||||
};
|
||||
} else if(EVENTS[name] === 1){
|
||||
name = "on" + name;
|
||||
CollectingHandler.prototype[name] = function(a){
|
||||
this.events.push([name, a]);
|
||||
if(this._cbs[name]) this._cbs[name](a);
|
||||
};
|
||||
} else if(EVENTS[name] === 2){
|
||||
name = "on" + name;
|
||||
CollectingHandler.prototype[name] = function(a, b){
|
||||
this.events.push([name, a, b]);
|
||||
if(this._cbs[name]) this._cbs[name](a, b);
|
||||
};
|
||||
} else {
|
||||
throw Error("wrong number of arguments");
|
||||
}
|
||||
});
|
||||
|
||||
CollectingHandler.prototype.onreset = function(){
|
||||
this.events = [];
|
||||
if(this._cbs.onreset) this._cbs.onreset();
|
||||
};
|
||||
|
||||
CollectingHandler.prototype.restart = function(){
|
||||
if(this._cbs.onreset) this._cbs.onreset();
|
||||
|
||||
for(var i = 0, len = this.events.length; i < len; i++){
|
||||
if(this._cbs[this.events[i][0]]){
|
||||
|
||||
var num = this.events[i].length;
|
||||
|
||||
if(num === 1){
|
||||
this._cbs[this.events[i][0]]();
|
||||
} else if(num === 2){
|
||||
this._cbs[this.events[i][0]](this.events[i][1]);
|
||||
} else {
|
||||
this._cbs[this.events[i][0]](this.events[i][1], this.events[i][2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
95
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/FeedHandler.js
generated
vendored
Normal file
95
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/FeedHandler.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
var index = require("./index.js"),
|
||||
DomHandler = index.DomHandler,
|
||||
DomUtils = index.DomUtils;
|
||||
|
||||
//TODO: make this a streamable handler
|
||||
function FeedHandler(callback, options){
|
||||
this.init(callback, options);
|
||||
}
|
||||
|
||||
require("util").inherits(FeedHandler, DomHandler);
|
||||
|
||||
FeedHandler.prototype.init = DomHandler;
|
||||
|
||||
function getElements(what, where){
|
||||
return DomUtils.getElementsByTagName(what, where, true);
|
||||
}
|
||||
function getOneElement(what, where){
|
||||
return DomUtils.getElementsByTagName(what, where, true, 1)[0];
|
||||
}
|
||||
function fetch(what, where, recurse){
|
||||
return DomUtils.getText(
|
||||
DomUtils.getElementsByTagName(what, where, recurse, 1)
|
||||
).trim();
|
||||
}
|
||||
|
||||
function addConditionally(obj, prop, what, where, recurse){
|
||||
var tmp = fetch(what, where, recurse);
|
||||
if(tmp) obj[prop] = tmp;
|
||||
}
|
||||
|
||||
var isValidFeed = function(value) {
|
||||
return value === "rss" || value === "feed" || value === "rdf:RDF";
|
||||
};
|
||||
|
||||
FeedHandler.prototype.onend = function() {
|
||||
var feed = {},
|
||||
feedRoot = getOneElement(isValidFeed, this.dom),
|
||||
tmp, childs;
|
||||
|
||||
if(feedRoot){
|
||||
if(feedRoot.name === "feed"){
|
||||
childs = feedRoot.children;
|
||||
|
||||
feed.type = "atom";
|
||||
addConditionally(feed, "id", "id", childs);
|
||||
addConditionally(feed, "title", "title", childs);
|
||||
if((tmp = getOneElement("link", childs)) && (tmp = tmp.attribs) && (tmp = tmp.href)) feed.link = tmp;
|
||||
addConditionally(feed, "description", "subtitle", childs);
|
||||
if((tmp = fetch("updated", childs))) feed.updated = new Date(tmp);
|
||||
addConditionally(feed, "author", "email", childs, true);
|
||||
|
||||
feed.items = getElements("entry", childs).map(function(item){
|
||||
var entry = {}, tmp;
|
||||
|
||||
item = item.children;
|
||||
|
||||
addConditionally(entry, "id", "id", item);
|
||||
addConditionally(entry, "title", "title", item);
|
||||
if((tmp = getOneElement("link", item)) && (tmp = tmp.attribs) && (tmp = tmp.href)) entry.link = tmp;
|
||||
addConditionally(entry, "description", "summary", item);
|
||||
if((tmp = fetch("updated", item))) entry.pubDate = new Date(tmp);
|
||||
return entry;
|
||||
});
|
||||
} else {
|
||||
childs = getOneElement("channel", feedRoot.children).children;
|
||||
|
||||
feed.type = feedRoot.name.substr(0, 3);
|
||||
feed.id = "";
|
||||
addConditionally(feed, "title", "title", childs);
|
||||
addConditionally(feed, "link", "link", childs);
|
||||
addConditionally(feed, "description", "description", childs);
|
||||
if((tmp = fetch("lastBuildDate", childs))) feed.updated = new Date(tmp);
|
||||
addConditionally(feed, "author", "managingEditor", childs, true);
|
||||
|
||||
feed.items = getElements("item", feedRoot.children).map(function(item){
|
||||
var entry = {}, tmp;
|
||||
|
||||
item = item.children;
|
||||
|
||||
addConditionally(entry, "id", "guid", item);
|
||||
addConditionally(entry, "title", "title", item);
|
||||
addConditionally(entry, "link", "link", item);
|
||||
addConditionally(entry, "description", "description", item);
|
||||
if((tmp = fetch("pubDate", item))) entry.pubDate = new Date(tmp);
|
||||
return entry;
|
||||
});
|
||||
}
|
||||
}
|
||||
this.dom = feed;
|
||||
DomHandler.prototype._handleCallback.call(
|
||||
this, feedRoot ? null : Error("couldn't find root of feed")
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = FeedHandler;
|
337
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/Parser.js
generated
vendored
Normal file
337
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/Parser.js
generated
vendored
Normal file
@@ -0,0 +1,337 @@
|
||||
var Tokenizer = require("./Tokenizer.js");
|
||||
|
||||
/*
|
||||
Options:
|
||||
|
||||
xmlMode: Special behavior for script/style tags (true by default)
|
||||
lowerCaseAttributeNames: call .toLowerCase for each attribute name (true if xmlMode is `false`)
|
||||
lowerCaseTags: call .toLowerCase for each tag name (true if xmlMode is `false`)
|
||||
*/
|
||||
|
||||
/*
|
||||
Callbacks:
|
||||
|
||||
oncdataend,
|
||||
oncdatastart,
|
||||
onclosetag,
|
||||
oncomment,
|
||||
oncommentend,
|
||||
onerror,
|
||||
onopentag,
|
||||
onprocessinginstruction,
|
||||
onreset,
|
||||
ontext
|
||||
*/
|
||||
|
||||
var formTags = {
|
||||
input: true,
|
||||
option: true,
|
||||
optgroup: true,
|
||||
select: true,
|
||||
button: true,
|
||||
datalist: true,
|
||||
textarea: true
|
||||
};
|
||||
|
||||
var openImpliesClose = {
|
||||
tr : { tr:true, th:true, td:true },
|
||||
th : { th:true },
|
||||
td : { thead:true, td:true },
|
||||
body : { head:true, link:true, script:true },
|
||||
li : { li:true },
|
||||
p : { p:true },
|
||||
select : formTags,
|
||||
input : formTags,
|
||||
output : formTags,
|
||||
button : formTags,
|
||||
datalist: formTags,
|
||||
textarea: formTags,
|
||||
option : { option:true },
|
||||
optgroup: { optgroup:true }
|
||||
};
|
||||
|
||||
var voidElements = {
|
||||
__proto__: null,
|
||||
area: true,
|
||||
base: true,
|
||||
basefont: true,
|
||||
br: true,
|
||||
col: true,
|
||||
command: true,
|
||||
embed: true,
|
||||
frame: true,
|
||||
hr: true,
|
||||
img: true,
|
||||
input: true,
|
||||
isindex: true,
|
||||
keygen: true,
|
||||
link: true,
|
||||
meta: true,
|
||||
param: true,
|
||||
source: true,
|
||||
track: true,
|
||||
wbr: true,
|
||||
|
||||
//common self closing svg elements
|
||||
path: true,
|
||||
circle: true,
|
||||
ellipse: true,
|
||||
line: true,
|
||||
rect: true,
|
||||
use: true
|
||||
};
|
||||
|
||||
var re_nameEnd = /\s|\//;
|
||||
|
||||
function Parser(cbs, options){
|
||||
this._options = options || {};
|
||||
this._cbs = cbs || {};
|
||||
|
||||
this._tagname = "";
|
||||
this._attribname = "";
|
||||
this._attribvalue = "";
|
||||
this._attribs = null;
|
||||
this._stack = [];
|
||||
|
||||
this.startIndex = 0;
|
||||
this.endIndex = null;
|
||||
|
||||
this._lowerCaseTagNames = "lowerCaseTags" in this._options ?
|
||||
!!this._options.lowerCaseTags :
|
||||
!this._options.xmlMode;
|
||||
this._lowerCaseAttributeNames = "lowerCaseAttributeNames" in this._options ?
|
||||
!!this._options.lowerCaseAttributeNames :
|
||||
!this._options.xmlMode;
|
||||
|
||||
this._tokenizer = new Tokenizer(this._options, this);
|
||||
}
|
||||
|
||||
require("util").inherits(Parser, require("events").EventEmitter);
|
||||
|
||||
Parser.prototype._updatePosition = function(initialOffset){
|
||||
if(this.endIndex === null){
|
||||
if(this._tokenizer._sectionStart <= initialOffset){
|
||||
this.startIndex = 0;
|
||||
} else {
|
||||
this.startIndex = this._tokenizer._sectionStart - initialOffset;
|
||||
}
|
||||
}
|
||||
else this.startIndex = this.endIndex + 1;
|
||||
this.endIndex = this._tokenizer._index;
|
||||
};
|
||||
|
||||
//Tokenizer event handlers
|
||||
Parser.prototype.ontext = function(data){
|
||||
this._updatePosition(1);
|
||||
this.endIndex--;
|
||||
|
||||
if(this._cbs.ontext) this._cbs.ontext(data);
|
||||
};
|
||||
|
||||
Parser.prototype.onopentagname = function(name){
|
||||
if(this._lowerCaseTagNames){
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
this._tagname = name;
|
||||
|
||||
if (!this._options.xmlMode && name in openImpliesClose) {
|
||||
for(
|
||||
var el;
|
||||
(el = this._stack[this._stack.length-1]) in openImpliesClose[name];
|
||||
this.onclosetag(el)
|
||||
);
|
||||
}
|
||||
|
||||
if(this._options.xmlMode || !(name in voidElements)){
|
||||
this._stack.push(name);
|
||||
}
|
||||
|
||||
if(this._cbs.onopentagname) this._cbs.onopentagname(name);
|
||||
if(this._cbs.onopentag) this._attribs = {};
|
||||
};
|
||||
|
||||
Parser.prototype.onopentagend = function(){
|
||||
this._updatePosition(1);
|
||||
|
||||
if(this._attribs){
|
||||
if(this._cbs.onopentag) this._cbs.onopentag(this._tagname, this._attribs);
|
||||
this._attribs = null;
|
||||
}
|
||||
|
||||
if(!this._options.xmlMode && this._cbs.onclosetag && this._tagname in voidElements){
|
||||
this._cbs.onclosetag(this._tagname);
|
||||
}
|
||||
|
||||
this._tagname = "";
|
||||
};
|
||||
|
||||
Parser.prototype.onclosetag = function(name){
|
||||
this._updatePosition(1);
|
||||
|
||||
if(this._lowerCaseTagNames){
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
if(this._stack.length && (!(name in voidElements) || this._options.xmlMode)){
|
||||
var pos = this._stack.lastIndexOf(name);
|
||||
if(pos !== -1){
|
||||
if(this._cbs.onclosetag){
|
||||
pos = this._stack.length - pos;
|
||||
while(pos--) this._cbs.onclosetag(this._stack.pop());
|
||||
}
|
||||
else this._stack.length = pos;
|
||||
} else if(name === "p" && !this._options.xmlMode){
|
||||
this.onopentagname(name);
|
||||
this._closeCurrentTag();
|
||||
}
|
||||
} else if(!this._options.xmlMode && (name === "br" || name === "p")){
|
||||
this.onopentagname(name);
|
||||
this._closeCurrentTag();
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onselfclosingtag = function(){
|
||||
if(this._options.xmlMode || this._options.recognizeSelfClosing){
|
||||
this._closeCurrentTag();
|
||||
} else {
|
||||
this.onopentagend();
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype._closeCurrentTag = function(){
|
||||
var name = this._tagname;
|
||||
|
||||
this.onopentagend();
|
||||
|
||||
//self-closing tags will be on the top of the stack
|
||||
//(cheaper check than in onclosetag)
|
||||
if(this._stack[this._stack.length-1] === name){
|
||||
if(this._cbs.onclosetag){
|
||||
this._cbs.onclosetag(name);
|
||||
}
|
||||
this._stack.pop();
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onattribname = function(name){
|
||||
if(this._lowerCaseAttributeNames){
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
this._attribname = name;
|
||||
};
|
||||
|
||||
Parser.prototype.onattribdata = function(value){
|
||||
this._attribvalue += value;
|
||||
};
|
||||
|
||||
Parser.prototype.onattribend = function(){
|
||||
if(this._cbs.onattribute) this._cbs.onattribute(this._attribname, this._attribvalue);
|
||||
if(
|
||||
this._attribs &&
|
||||
!Object.prototype.hasOwnProperty.call(this._attribs, this._attribname)
|
||||
){
|
||||
this._attribs[this._attribname] = this._attribvalue;
|
||||
}
|
||||
this._attribname = "";
|
||||
this._attribvalue = "";
|
||||
};
|
||||
|
||||
Parser.prototype._getInstructionName = function(value){
|
||||
var idx = value.search(re_nameEnd),
|
||||
name = idx < 0 ? value : value.substr(0, idx);
|
||||
|
||||
if(this._lowerCaseTagNames){
|
||||
name = name.toLowerCase();
|
||||
}
|
||||
|
||||
return name;
|
||||
};
|
||||
|
||||
Parser.prototype.ondeclaration = function(value){
|
||||
if(this._cbs.onprocessinginstruction){
|
||||
var name = this._getInstructionName(value);
|
||||
this._cbs.onprocessinginstruction("!" + name, "!" + value);
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onprocessinginstruction = function(value){
|
||||
if(this._cbs.onprocessinginstruction){
|
||||
var name = this._getInstructionName(value);
|
||||
this._cbs.onprocessinginstruction("?" + name, "?" + value);
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.oncomment = function(value){
|
||||
this._updatePosition(4);
|
||||
|
||||
if(this._cbs.oncomment) this._cbs.oncomment(value);
|
||||
if(this._cbs.oncommentend) this._cbs.oncommentend();
|
||||
};
|
||||
|
||||
Parser.prototype.oncdata = function(value){
|
||||
this._updatePosition(1);
|
||||
|
||||
if(this._options.xmlMode || this._options.recognizeCDATA){
|
||||
if(this._cbs.oncdatastart) this._cbs.oncdatastart();
|
||||
if(this._cbs.ontext) this._cbs.ontext(value);
|
||||
if(this._cbs.oncdataend) this._cbs.oncdataend();
|
||||
} else {
|
||||
this.oncomment("[CDATA[" + value + "]]");
|
||||
}
|
||||
};
|
||||
|
||||
Parser.prototype.onerror = function(err){
|
||||
if(this._cbs.onerror) this._cbs.onerror(err);
|
||||
};
|
||||
|
||||
Parser.prototype.onend = function(){
|
||||
if(this._cbs.onclosetag){
|
||||
for(
|
||||
var i = this._stack.length;
|
||||
i > 0;
|
||||
this._cbs.onclosetag(this._stack[--i])
|
||||
);
|
||||
}
|
||||
if(this._cbs.onend) this._cbs.onend();
|
||||
};
|
||||
|
||||
|
||||
//Resets the parser to a blank state, ready to parse a new HTML document
|
||||
Parser.prototype.reset = function(){
|
||||
if(this._cbs.onreset) this._cbs.onreset();
|
||||
this._tokenizer.reset();
|
||||
|
||||
this._tagname = "";
|
||||
this._attribname = "";
|
||||
this._attribs = null;
|
||||
this._stack = [];
|
||||
};
|
||||
|
||||
//Parses a complete HTML document and pushes it to the handler
|
||||
Parser.prototype.parseComplete = function(data){
|
||||
this.reset();
|
||||
this.end(data);
|
||||
};
|
||||
|
||||
Parser.prototype.write = function(chunk){
|
||||
this._tokenizer.write(chunk);
|
||||
};
|
||||
|
||||
Parser.prototype.end = function(chunk){
|
||||
this._tokenizer.end(chunk);
|
||||
};
|
||||
|
||||
Parser.prototype.pause = function(){
|
||||
this._tokenizer.pause();
|
||||
};
|
||||
|
||||
Parser.prototype.resume = function(){
|
||||
this._tokenizer.resume();
|
||||
};
|
||||
|
||||
//alias for backwards compat
|
||||
Parser.prototype.parseChunk = Parser.prototype.write;
|
||||
Parser.prototype.done = Parser.prototype.end;
|
||||
|
||||
module.exports = Parser;
|
27
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/ProxyHandler.js
generated
vendored
Normal file
27
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/ProxyHandler.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
module.exports = ProxyHandler;
|
||||
|
||||
function ProxyHandler(cbs){
|
||||
this._cbs = cbs || {};
|
||||
}
|
||||
|
||||
var EVENTS = require("./").EVENTS;
|
||||
Object.keys(EVENTS).forEach(function(name){
|
||||
if(EVENTS[name] === 0){
|
||||
name = "on" + name;
|
||||
ProxyHandler.prototype[name] = function(){
|
||||
if(this._cbs[name]) this._cbs[name]();
|
||||
};
|
||||
} else if(EVENTS[name] === 1){
|
||||
name = "on" + name;
|
||||
ProxyHandler.prototype[name] = function(a){
|
||||
if(this._cbs[name]) this._cbs[name](a);
|
||||
};
|
||||
} else if(EVENTS[name] === 2){
|
||||
name = "on" + name;
|
||||
ProxyHandler.prototype[name] = function(a, b){
|
||||
if(this._cbs[name]) this._cbs[name](a, b);
|
||||
};
|
||||
} else {
|
||||
throw Error("wrong number of arguments");
|
||||
}
|
||||
});
|
35
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/Stream.js
generated
vendored
Normal file
35
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/Stream.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
module.exports = Stream;
|
||||
|
||||
var Parser = require("./WritableStream.js");
|
||||
|
||||
function Stream(options){
|
||||
Parser.call(this, new Cbs(this), options);
|
||||
}
|
||||
|
||||
require("util").inherits(Stream, Parser);
|
||||
|
||||
Stream.prototype.readable = true;
|
||||
|
||||
function Cbs(scope){
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
var EVENTS = require("../").EVENTS;
|
||||
|
||||
Object.keys(EVENTS).forEach(function(name){
|
||||
if(EVENTS[name] === 0){
|
||||
Cbs.prototype["on" + name] = function(){
|
||||
this.scope.emit(name);
|
||||
};
|
||||
} else if(EVENTS[name] === 1){
|
||||
Cbs.prototype["on" + name] = function(a){
|
||||
this.scope.emit(name, a);
|
||||
};
|
||||
} else if(EVENTS[name] === 2){
|
||||
Cbs.prototype["on" + name] = function(a, b){
|
||||
this.scope.emit(name, a, b);
|
||||
};
|
||||
} else {
|
||||
throw Error("wrong number of arguments!");
|
||||
}
|
||||
});
|
897
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/Tokenizer.js
generated
vendored
Normal file
897
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/Tokenizer.js
generated
vendored
Normal file
@@ -0,0 +1,897 @@
|
||||
module.exports = Tokenizer;
|
||||
|
||||
var decodeCodePoint = require("entities/lib/decode_codepoint.js"),
|
||||
entityMap = require("entities/maps/entities.json"),
|
||||
legacyMap = require("entities/maps/legacy.json"),
|
||||
xmlMap = require("entities/maps/xml.json"),
|
||||
|
||||
i = 0,
|
||||
|
||||
TEXT = i++,
|
||||
BEFORE_TAG_NAME = i++, //after <
|
||||
IN_TAG_NAME = i++,
|
||||
IN_SELF_CLOSING_TAG = i++,
|
||||
BEFORE_CLOSING_TAG_NAME = i++,
|
||||
IN_CLOSING_TAG_NAME = i++,
|
||||
AFTER_CLOSING_TAG_NAME = i++,
|
||||
|
||||
//attributes
|
||||
BEFORE_ATTRIBUTE_NAME = i++,
|
||||
IN_ATTRIBUTE_NAME = i++,
|
||||
AFTER_ATTRIBUTE_NAME = i++,
|
||||
BEFORE_ATTRIBUTE_VALUE = i++,
|
||||
IN_ATTRIBUTE_VALUE_DQ = i++, // "
|
||||
IN_ATTRIBUTE_VALUE_SQ = i++, // '
|
||||
IN_ATTRIBUTE_VALUE_NQ = i++,
|
||||
|
||||
//declarations
|
||||
BEFORE_DECLARATION = i++, // !
|
||||
IN_DECLARATION = i++,
|
||||
|
||||
//processing instructions
|
||||
IN_PROCESSING_INSTRUCTION = i++, // ?
|
||||
|
||||
//comments
|
||||
BEFORE_COMMENT = i++,
|
||||
IN_COMMENT = i++,
|
||||
AFTER_COMMENT_1 = i++,
|
||||
AFTER_COMMENT_2 = i++,
|
||||
|
||||
//cdata
|
||||
BEFORE_CDATA_1 = i++, // [
|
||||
BEFORE_CDATA_2 = i++, // C
|
||||
BEFORE_CDATA_3 = i++, // D
|
||||
BEFORE_CDATA_4 = i++, // A
|
||||
BEFORE_CDATA_5 = i++, // T
|
||||
BEFORE_CDATA_6 = i++, // A
|
||||
IN_CDATA = i++, // [
|
||||
AFTER_CDATA_1 = i++, // ]
|
||||
AFTER_CDATA_2 = i++, // ]
|
||||
|
||||
//special tags
|
||||
BEFORE_SPECIAL = i++, //S
|
||||
BEFORE_SPECIAL_END = i++, //S
|
||||
|
||||
BEFORE_SCRIPT_1 = i++, //C
|
||||
BEFORE_SCRIPT_2 = i++, //R
|
||||
BEFORE_SCRIPT_3 = i++, //I
|
||||
BEFORE_SCRIPT_4 = i++, //P
|
||||
BEFORE_SCRIPT_5 = i++, //T
|
||||
AFTER_SCRIPT_1 = i++, //C
|
||||
AFTER_SCRIPT_2 = i++, //R
|
||||
AFTER_SCRIPT_3 = i++, //I
|
||||
AFTER_SCRIPT_4 = i++, //P
|
||||
AFTER_SCRIPT_5 = i++, //T
|
||||
|
||||
BEFORE_STYLE_1 = i++, //T
|
||||
BEFORE_STYLE_2 = i++, //Y
|
||||
BEFORE_STYLE_3 = i++, //L
|
||||
BEFORE_STYLE_4 = i++, //E
|
||||
AFTER_STYLE_1 = i++, //T
|
||||
AFTER_STYLE_2 = i++, //Y
|
||||
AFTER_STYLE_3 = i++, //L
|
||||
AFTER_STYLE_4 = i++, //E
|
||||
|
||||
BEFORE_ENTITY = i++, //&
|
||||
BEFORE_NUMERIC_ENTITY = i++, //#
|
||||
IN_NAMED_ENTITY = i++,
|
||||
IN_NUMERIC_ENTITY = i++,
|
||||
IN_HEX_ENTITY = i++, //X
|
||||
|
||||
j = 0,
|
||||
|
||||
SPECIAL_NONE = j++,
|
||||
SPECIAL_SCRIPT = j++,
|
||||
SPECIAL_STYLE = j++;
|
||||
|
||||
function whitespace(c){
|
||||
return c === " " || c === "\n" || c === "\t" || c === "\f" || c === "\r";
|
||||
}
|
||||
|
||||
function characterState(char, SUCCESS){
|
||||
return function(c){
|
||||
if(c === char) this._state = SUCCESS;
|
||||
};
|
||||
}
|
||||
|
||||
function ifElseState(upper, SUCCESS, FAILURE){
|
||||
var lower = upper.toLowerCase();
|
||||
|
||||
if(upper === lower){
|
||||
return function(c){
|
||||
if(c === lower){
|
||||
this._state = SUCCESS;
|
||||
} else {
|
||||
this._state = FAILURE;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return function(c){
|
||||
if(c === lower || c === upper){
|
||||
this._state = SUCCESS;
|
||||
} else {
|
||||
this._state = FAILURE;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function consumeSpecialNameChar(upper, NEXT_STATE){
|
||||
var lower = upper.toLowerCase();
|
||||
|
||||
return function(c){
|
||||
if(c === lower || c === upper){
|
||||
this._state = NEXT_STATE;
|
||||
} else {
|
||||
this._state = IN_TAG_NAME;
|
||||
this._index--; //consume the token again
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function Tokenizer(options, cbs){
|
||||
this._state = TEXT;
|
||||
this._buffer = "";
|
||||
this._sectionStart = 0;
|
||||
this._index = 0;
|
||||
this._baseState = TEXT;
|
||||
this._special = SPECIAL_NONE;
|
||||
this._cbs = cbs;
|
||||
this._running = true;
|
||||
this._ended = false;
|
||||
this._xmlMode = !!(options && options.xmlMode);
|
||||
this._decodeEntities = !!(options && options.decodeEntities);
|
||||
}
|
||||
|
||||
Tokenizer.prototype._stateText = function(c){
|
||||
if(c === "<"){
|
||||
if(this._index > this._sectionStart){
|
||||
this._cbs.ontext(this._getSection());
|
||||
}
|
||||
this._state = BEFORE_TAG_NAME;
|
||||
this._sectionStart = this._index;
|
||||
} else if(this._decodeEntities && this._special === SPECIAL_NONE && c === "&"){
|
||||
if(this._index > this._sectionStart){
|
||||
this._cbs.ontext(this._getSection());
|
||||
}
|
||||
this._baseState = TEXT;
|
||||
this._state = BEFORE_ENTITY;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeTagName = function(c){
|
||||
if(c === "/"){
|
||||
this._state = BEFORE_CLOSING_TAG_NAME;
|
||||
} else if(c === ">" || this._special !== SPECIAL_NONE || whitespace(c)) {
|
||||
this._state = TEXT;
|
||||
} else if(c === "!"){
|
||||
this._state = BEFORE_DECLARATION;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if(c === "?"){
|
||||
this._state = IN_PROCESSING_INSTRUCTION;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if(c === "<"){
|
||||
this._cbs.ontext(this._getSection());
|
||||
this._sectionStart = this._index;
|
||||
} else {
|
||||
this._state = (!this._xmlMode && (c === "s" || c === "S")) ?
|
||||
BEFORE_SPECIAL : IN_TAG_NAME;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInTagName = function(c){
|
||||
if(c === "/" || c === ">" || whitespace(c)){
|
||||
this._emitToken("onopentagname");
|
||||
this._state = BEFORE_ATTRIBUTE_NAME;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeCloseingTagName = function(c){
|
||||
if(whitespace(c));
|
||||
else if(c === ">"){
|
||||
this._state = TEXT;
|
||||
} else if(this._special !== SPECIAL_NONE){
|
||||
if(c === "s" || c === "S"){
|
||||
this._state = BEFORE_SPECIAL_END;
|
||||
} else {
|
||||
this._state = TEXT;
|
||||
this._index--;
|
||||
}
|
||||
} else {
|
||||
this._state = IN_CLOSING_TAG_NAME;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInCloseingTagName = function(c){
|
||||
if(c === ">" || whitespace(c)){
|
||||
this._emitToken("onclosetag");
|
||||
this._state = AFTER_CLOSING_TAG_NAME;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateAfterCloseingTagName = function(c){
|
||||
//skip everything until ">"
|
||||
if(c === ">"){
|
||||
this._state = TEXT;
|
||||
this._sectionStart = this._index + 1;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeAttributeName = function(c){
|
||||
if(c === ">"){
|
||||
this._cbs.onopentagend();
|
||||
this._state = TEXT;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if(c === "/"){
|
||||
this._state = IN_SELF_CLOSING_TAG;
|
||||
} else if(!whitespace(c)){
|
||||
this._state = IN_ATTRIBUTE_NAME;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInSelfClosingTag = function(c){
|
||||
if(c === ">"){
|
||||
this._cbs.onselfclosingtag();
|
||||
this._state = TEXT;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if(!whitespace(c)){
|
||||
this._state = BEFORE_ATTRIBUTE_NAME;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInAttributeName = function(c){
|
||||
if(c === "=" || c === "/" || c === ">" || whitespace(c)){
|
||||
this._cbs.onattribname(this._getSection());
|
||||
this._sectionStart = -1;
|
||||
this._state = AFTER_ATTRIBUTE_NAME;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateAfterAttributeName = function(c){
|
||||
if(c === "="){
|
||||
this._state = BEFORE_ATTRIBUTE_VALUE;
|
||||
} else if(c === "/" || c === ">"){
|
||||
this._cbs.onattribend();
|
||||
this._state = BEFORE_ATTRIBUTE_NAME;
|
||||
this._index--;
|
||||
} else if(!whitespace(c)){
|
||||
this._cbs.onattribend();
|
||||
this._state = IN_ATTRIBUTE_NAME;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeAttributeValue = function(c){
|
||||
if(c === "\""){
|
||||
this._state = IN_ATTRIBUTE_VALUE_DQ;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if(c === "'"){
|
||||
this._state = IN_ATTRIBUTE_VALUE_SQ;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if(!whitespace(c)){
|
||||
this._state = IN_ATTRIBUTE_VALUE_NQ;
|
||||
this._sectionStart = this._index;
|
||||
this._index--; //reconsume token
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInAttributeValueDoubleQuotes = function(c){
|
||||
if(c === "\""){
|
||||
this._emitToken("onattribdata");
|
||||
this._cbs.onattribend();
|
||||
this._state = BEFORE_ATTRIBUTE_NAME;
|
||||
} else if(this._decodeEntities && c === "&"){
|
||||
this._emitToken("onattribdata");
|
||||
this._baseState = this._state;
|
||||
this._state = BEFORE_ENTITY;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInAttributeValueSingleQuotes = function(c){
|
||||
if(c === "'"){
|
||||
this._emitToken("onattribdata");
|
||||
this._cbs.onattribend();
|
||||
this._state = BEFORE_ATTRIBUTE_NAME;
|
||||
} else if(this._decodeEntities && c === "&"){
|
||||
this._emitToken("onattribdata");
|
||||
this._baseState = this._state;
|
||||
this._state = BEFORE_ENTITY;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInAttributeValueNoQuotes = function(c){
|
||||
if(whitespace(c) || c === ">"){
|
||||
this._emitToken("onattribdata");
|
||||
this._cbs.onattribend();
|
||||
this._state = BEFORE_ATTRIBUTE_NAME;
|
||||
this._index--;
|
||||
} else if(this._decodeEntities && c === "&"){
|
||||
this._emitToken("onattribdata");
|
||||
this._baseState = this._state;
|
||||
this._state = BEFORE_ENTITY;
|
||||
this._sectionStart = this._index;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeDeclaration = function(c){
|
||||
this._state = c === "[" ? BEFORE_CDATA_1 :
|
||||
c === "-" ? BEFORE_COMMENT :
|
||||
IN_DECLARATION;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInDeclaration = function(c){
|
||||
if(c === ">"){
|
||||
this._cbs.ondeclaration(this._getSection());
|
||||
this._state = TEXT;
|
||||
this._sectionStart = this._index + 1;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInProcessingInstruction = function(c){
|
||||
if(c === ">"){
|
||||
this._cbs.onprocessinginstruction(this._getSection());
|
||||
this._state = TEXT;
|
||||
this._sectionStart = this._index + 1;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeComment = function(c){
|
||||
if(c === "-"){
|
||||
this._state = IN_COMMENT;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else {
|
||||
this._state = IN_DECLARATION;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInComment = function(c){
|
||||
if(c === "-") this._state = AFTER_COMMENT_1;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateAfterComment1 = function(c){
|
||||
if(c === "-"){
|
||||
this._state = AFTER_COMMENT_2;
|
||||
} else {
|
||||
this._state = IN_COMMENT;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateAfterComment2 = function(c){
|
||||
if(c === ">"){
|
||||
//remove 2 trailing chars
|
||||
this._cbs.oncomment(this._buffer.substring(this._sectionStart, this._index - 2));
|
||||
this._state = TEXT;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if(c !== "-"){
|
||||
this._state = IN_COMMENT;
|
||||
}
|
||||
// else: stay in AFTER_COMMENT_2 (`--->`)
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeCdata1 = ifElseState("C", BEFORE_CDATA_2, IN_DECLARATION);
|
||||
Tokenizer.prototype._stateBeforeCdata2 = ifElseState("D", BEFORE_CDATA_3, IN_DECLARATION);
|
||||
Tokenizer.prototype._stateBeforeCdata3 = ifElseState("A", BEFORE_CDATA_4, IN_DECLARATION);
|
||||
Tokenizer.prototype._stateBeforeCdata4 = ifElseState("T", BEFORE_CDATA_5, IN_DECLARATION);
|
||||
Tokenizer.prototype._stateBeforeCdata5 = ifElseState("A", BEFORE_CDATA_6, IN_DECLARATION);
|
||||
|
||||
Tokenizer.prototype._stateBeforeCdata6 = function(c){
|
||||
if(c === "["){
|
||||
this._state = IN_CDATA;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else {
|
||||
this._state = IN_DECLARATION;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInCdata = function(c){
|
||||
if(c === "]") this._state = AFTER_CDATA_1;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateAfterCdata1 = characterState("]", AFTER_CDATA_2);
|
||||
|
||||
Tokenizer.prototype._stateAfterCdata2 = function(c){
|
||||
if(c === ">"){
|
||||
//remove 2 trailing chars
|
||||
this._cbs.oncdata(this._buffer.substring(this._sectionStart, this._index - 2));
|
||||
this._state = TEXT;
|
||||
this._sectionStart = this._index + 1;
|
||||
} else if (c !== "]") {
|
||||
this._state = IN_CDATA;
|
||||
}
|
||||
//else: stay in AFTER_CDATA_2 (`]]]>`)
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeSpecial = function(c){
|
||||
if(c === "c" || c === "C"){
|
||||
this._state = BEFORE_SCRIPT_1;
|
||||
} else if(c === "t" || c === "T"){
|
||||
this._state = BEFORE_STYLE_1;
|
||||
} else {
|
||||
this._state = IN_TAG_NAME;
|
||||
this._index--; //consume the token again
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeSpecialEnd = function(c){
|
||||
if(this._special === SPECIAL_SCRIPT && (c === "c" || c === "C")){
|
||||
this._state = AFTER_SCRIPT_1;
|
||||
} else if(this._special === SPECIAL_STYLE && (c === "t" || c === "T")){
|
||||
this._state = AFTER_STYLE_1;
|
||||
}
|
||||
else this._state = TEXT;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeScript1 = consumeSpecialNameChar("R", BEFORE_SCRIPT_2);
|
||||
Tokenizer.prototype._stateBeforeScript2 = consumeSpecialNameChar("I", BEFORE_SCRIPT_3);
|
||||
Tokenizer.prototype._stateBeforeScript3 = consumeSpecialNameChar("P", BEFORE_SCRIPT_4);
|
||||
Tokenizer.prototype._stateBeforeScript4 = consumeSpecialNameChar("T", BEFORE_SCRIPT_5);
|
||||
|
||||
Tokenizer.prototype._stateBeforeScript5 = function(c){
|
||||
if(c === "/" || c === ">" || whitespace(c)){
|
||||
this._special = SPECIAL_SCRIPT;
|
||||
}
|
||||
this._state = IN_TAG_NAME;
|
||||
this._index--; //consume the token again
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateAfterScript1 = ifElseState("R", AFTER_SCRIPT_2, TEXT);
|
||||
Tokenizer.prototype._stateAfterScript2 = ifElseState("I", AFTER_SCRIPT_3, TEXT);
|
||||
Tokenizer.prototype._stateAfterScript3 = ifElseState("P", AFTER_SCRIPT_4, TEXT);
|
||||
Tokenizer.prototype._stateAfterScript4 = ifElseState("T", AFTER_SCRIPT_5, TEXT);
|
||||
|
||||
Tokenizer.prototype._stateAfterScript5 = function(c){
|
||||
if(c === ">" || whitespace(c)){
|
||||
this._special = SPECIAL_NONE;
|
||||
this._state = IN_CLOSING_TAG_NAME;
|
||||
this._sectionStart = this._index - 6;
|
||||
this._index--; //reconsume the token
|
||||
}
|
||||
else this._state = TEXT;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeStyle1 = consumeSpecialNameChar("Y", BEFORE_STYLE_2);
|
||||
Tokenizer.prototype._stateBeforeStyle2 = consumeSpecialNameChar("L", BEFORE_STYLE_3);
|
||||
Tokenizer.prototype._stateBeforeStyle3 = consumeSpecialNameChar("E", BEFORE_STYLE_4);
|
||||
|
||||
Tokenizer.prototype._stateBeforeStyle4 = function(c){
|
||||
if(c === "/" || c === ">" || whitespace(c)){
|
||||
this._special = SPECIAL_STYLE;
|
||||
}
|
||||
this._state = IN_TAG_NAME;
|
||||
this._index--; //consume the token again
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateAfterStyle1 = ifElseState("Y", AFTER_STYLE_2, TEXT);
|
||||
Tokenizer.prototype._stateAfterStyle2 = ifElseState("L", AFTER_STYLE_3, TEXT);
|
||||
Tokenizer.prototype._stateAfterStyle3 = ifElseState("E", AFTER_STYLE_4, TEXT);
|
||||
|
||||
Tokenizer.prototype._stateAfterStyle4 = function(c){
|
||||
if(c === ">" || whitespace(c)){
|
||||
this._special = SPECIAL_NONE;
|
||||
this._state = IN_CLOSING_TAG_NAME;
|
||||
this._sectionStart = this._index - 5;
|
||||
this._index--; //reconsume the token
|
||||
}
|
||||
else this._state = TEXT;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateBeforeEntity = ifElseState("#", BEFORE_NUMERIC_ENTITY, IN_NAMED_ENTITY);
|
||||
Tokenizer.prototype._stateBeforeNumericEntity = ifElseState("X", IN_HEX_ENTITY, IN_NUMERIC_ENTITY);
|
||||
|
||||
//for entities terminated with a semicolon
|
||||
Tokenizer.prototype._parseNamedEntityStrict = function(){
|
||||
//offset = 1
|
||||
if(this._sectionStart + 1 < this._index){
|
||||
var entity = this._buffer.substring(this._sectionStart + 1, this._index),
|
||||
map = this._xmlMode ? xmlMap : entityMap;
|
||||
|
||||
if(map.hasOwnProperty(entity)){
|
||||
this._emitPartial(map[entity]);
|
||||
this._sectionStart = this._index + 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//parses legacy entities (without trailing semicolon)
|
||||
Tokenizer.prototype._parseLegacyEntity = function(){
|
||||
var start = this._sectionStart + 1,
|
||||
limit = this._index - start;
|
||||
|
||||
if(limit > 6) limit = 6; //the max length of legacy entities is 6
|
||||
|
||||
while(limit >= 2){ //the min length of legacy entities is 2
|
||||
var entity = this._buffer.substr(start, limit);
|
||||
|
||||
if(legacyMap.hasOwnProperty(entity)){
|
||||
this._emitPartial(legacyMap[entity]);
|
||||
this._sectionStart += limit + 1;
|
||||
return;
|
||||
} else {
|
||||
limit--;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInNamedEntity = function(c){
|
||||
if(c === ";"){
|
||||
this._parseNamedEntityStrict();
|
||||
if(this._sectionStart + 1 < this._index && !this._xmlMode){
|
||||
this._parseLegacyEntity();
|
||||
}
|
||||
this._state = this._baseState;
|
||||
} else if((c < "a" || c > "z") && (c < "A" || c > "Z") && (c < "0" || c > "9")){
|
||||
if(this._xmlMode);
|
||||
else if(this._sectionStart + 1 === this._index);
|
||||
else if(this._baseState !== TEXT){
|
||||
if(c !== "="){
|
||||
this._parseNamedEntityStrict();
|
||||
}
|
||||
} else {
|
||||
this._parseLegacyEntity();
|
||||
}
|
||||
|
||||
this._state = this._baseState;
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._decodeNumericEntity = function(offset, base){
|
||||
var sectionStart = this._sectionStart + offset;
|
||||
|
||||
if(sectionStart !== this._index){
|
||||
//parse entity
|
||||
var entity = this._buffer.substring(sectionStart, this._index);
|
||||
var parsed = parseInt(entity, base);
|
||||
|
||||
this._emitPartial(decodeCodePoint(parsed));
|
||||
this._sectionStart = this._index;
|
||||
} else {
|
||||
this._sectionStart--;
|
||||
}
|
||||
|
||||
this._state = this._baseState;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInNumericEntity = function(c){
|
||||
if(c === ";"){
|
||||
this._decodeNumericEntity(2, 10);
|
||||
this._sectionStart++;
|
||||
} else if(c < "0" || c > "9"){
|
||||
if(!this._xmlMode){
|
||||
this._decodeNumericEntity(2, 10);
|
||||
} else {
|
||||
this._state = this._baseState;
|
||||
}
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._stateInHexEntity = function(c){
|
||||
if(c === ";"){
|
||||
this._decodeNumericEntity(3, 16);
|
||||
this._sectionStart++;
|
||||
} else if((c < "a" || c > "f") && (c < "A" || c > "F") && (c < "0" || c > "9")){
|
||||
if(!this._xmlMode){
|
||||
this._decodeNumericEntity(3, 16);
|
||||
} else {
|
||||
this._state = this._baseState;
|
||||
}
|
||||
this._index--;
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype._cleanup = function () {
|
||||
if(this._sectionStart < 0){
|
||||
this._buffer = "";
|
||||
this._index = 0;
|
||||
} else if(this._running){
|
||||
if(this._state === TEXT){
|
||||
if(this._sectionStart !== this._index){
|
||||
this._cbs.ontext(this._buffer.substr(this._sectionStart));
|
||||
}
|
||||
this._buffer = "";
|
||||
this._index = 0;
|
||||
} else if(this._sectionStart === this._index){
|
||||
//the section just started
|
||||
this._buffer = "";
|
||||
this._index = 0;
|
||||
} else {
|
||||
//remove everything unnecessary
|
||||
this._buffer = this._buffer.substr(this._sectionStart);
|
||||
this._index -= this._sectionStart;
|
||||
}
|
||||
|
||||
this._sectionStart = 0;
|
||||
}
|
||||
};
|
||||
|
||||
//TODO make events conditional
|
||||
Tokenizer.prototype.write = function(chunk){
|
||||
if(this._ended) this._cbs.onerror(Error(".write() after done!"));
|
||||
|
||||
this._buffer += chunk;
|
||||
this._parse();
|
||||
};
|
||||
|
||||
Tokenizer.prototype._parse = function(){
|
||||
while(this._index < this._buffer.length && this._running){
|
||||
var c = this._buffer.charAt(this._index);
|
||||
if(this._state === TEXT) {
|
||||
this._stateText(c);
|
||||
} else if(this._state === BEFORE_TAG_NAME){
|
||||
this._stateBeforeTagName(c);
|
||||
} else if(this._state === IN_TAG_NAME) {
|
||||
this._stateInTagName(c);
|
||||
} else if(this._state === BEFORE_CLOSING_TAG_NAME){
|
||||
this._stateBeforeCloseingTagName(c);
|
||||
} else if(this._state === IN_CLOSING_TAG_NAME){
|
||||
this._stateInCloseingTagName(c);
|
||||
} else if(this._state === AFTER_CLOSING_TAG_NAME){
|
||||
this._stateAfterCloseingTagName(c);
|
||||
} else if(this._state === IN_SELF_CLOSING_TAG){
|
||||
this._stateInSelfClosingTag(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* attributes
|
||||
*/
|
||||
else if(this._state === BEFORE_ATTRIBUTE_NAME){
|
||||
this._stateBeforeAttributeName(c);
|
||||
} else if(this._state === IN_ATTRIBUTE_NAME){
|
||||
this._stateInAttributeName(c);
|
||||
} else if(this._state === AFTER_ATTRIBUTE_NAME){
|
||||
this._stateAfterAttributeName(c);
|
||||
} else if(this._state === BEFORE_ATTRIBUTE_VALUE){
|
||||
this._stateBeforeAttributeValue(c);
|
||||
} else if(this._state === IN_ATTRIBUTE_VALUE_DQ){
|
||||
this._stateInAttributeValueDoubleQuotes(c);
|
||||
} else if(this._state === IN_ATTRIBUTE_VALUE_SQ){
|
||||
this._stateInAttributeValueSingleQuotes(c);
|
||||
} else if(this._state === IN_ATTRIBUTE_VALUE_NQ){
|
||||
this._stateInAttributeValueNoQuotes(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* declarations
|
||||
*/
|
||||
else if(this._state === BEFORE_DECLARATION){
|
||||
this._stateBeforeDeclaration(c);
|
||||
} else if(this._state === IN_DECLARATION){
|
||||
this._stateInDeclaration(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* processing instructions
|
||||
*/
|
||||
else if(this._state === IN_PROCESSING_INSTRUCTION){
|
||||
this._stateInProcessingInstruction(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* comments
|
||||
*/
|
||||
else if(this._state === BEFORE_COMMENT){
|
||||
this._stateBeforeComment(c);
|
||||
} else if(this._state === IN_COMMENT){
|
||||
this._stateInComment(c);
|
||||
} else if(this._state === AFTER_COMMENT_1){
|
||||
this._stateAfterComment1(c);
|
||||
} else if(this._state === AFTER_COMMENT_2){
|
||||
this._stateAfterComment2(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* cdata
|
||||
*/
|
||||
else if(this._state === BEFORE_CDATA_1){
|
||||
this._stateBeforeCdata1(c);
|
||||
} else if(this._state === BEFORE_CDATA_2){
|
||||
this._stateBeforeCdata2(c);
|
||||
} else if(this._state === BEFORE_CDATA_3){
|
||||
this._stateBeforeCdata3(c);
|
||||
} else if(this._state === BEFORE_CDATA_4){
|
||||
this._stateBeforeCdata4(c);
|
||||
} else if(this._state === BEFORE_CDATA_5){
|
||||
this._stateBeforeCdata5(c);
|
||||
} else if(this._state === BEFORE_CDATA_6){
|
||||
this._stateBeforeCdata6(c);
|
||||
} else if(this._state === IN_CDATA){
|
||||
this._stateInCdata(c);
|
||||
} else if(this._state === AFTER_CDATA_1){
|
||||
this._stateAfterCdata1(c);
|
||||
} else if(this._state === AFTER_CDATA_2){
|
||||
this._stateAfterCdata2(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* special tags
|
||||
*/
|
||||
else if(this._state === BEFORE_SPECIAL){
|
||||
this._stateBeforeSpecial(c);
|
||||
} else if(this._state === BEFORE_SPECIAL_END){
|
||||
this._stateBeforeSpecialEnd(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* script
|
||||
*/
|
||||
else if(this._state === BEFORE_SCRIPT_1){
|
||||
this._stateBeforeScript1(c);
|
||||
} else if(this._state === BEFORE_SCRIPT_2){
|
||||
this._stateBeforeScript2(c);
|
||||
} else if(this._state === BEFORE_SCRIPT_3){
|
||||
this._stateBeforeScript3(c);
|
||||
} else if(this._state === BEFORE_SCRIPT_4){
|
||||
this._stateBeforeScript4(c);
|
||||
} else if(this._state === BEFORE_SCRIPT_5){
|
||||
this._stateBeforeScript5(c);
|
||||
}
|
||||
|
||||
else if(this._state === AFTER_SCRIPT_1){
|
||||
this._stateAfterScript1(c);
|
||||
} else if(this._state === AFTER_SCRIPT_2){
|
||||
this._stateAfterScript2(c);
|
||||
} else if(this._state === AFTER_SCRIPT_3){
|
||||
this._stateAfterScript3(c);
|
||||
} else if(this._state === AFTER_SCRIPT_4){
|
||||
this._stateAfterScript4(c);
|
||||
} else if(this._state === AFTER_SCRIPT_5){
|
||||
this._stateAfterScript5(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* style
|
||||
*/
|
||||
else if(this._state === BEFORE_STYLE_1){
|
||||
this._stateBeforeStyle1(c);
|
||||
} else if(this._state === BEFORE_STYLE_2){
|
||||
this._stateBeforeStyle2(c);
|
||||
} else if(this._state === BEFORE_STYLE_3){
|
||||
this._stateBeforeStyle3(c);
|
||||
} else if(this._state === BEFORE_STYLE_4){
|
||||
this._stateBeforeStyle4(c);
|
||||
}
|
||||
|
||||
else if(this._state === AFTER_STYLE_1){
|
||||
this._stateAfterStyle1(c);
|
||||
} else if(this._state === AFTER_STYLE_2){
|
||||
this._stateAfterStyle2(c);
|
||||
} else if(this._state === AFTER_STYLE_3){
|
||||
this._stateAfterStyle3(c);
|
||||
} else if(this._state === AFTER_STYLE_4){
|
||||
this._stateAfterStyle4(c);
|
||||
}
|
||||
|
||||
/*
|
||||
* entities
|
||||
*/
|
||||
else if(this._state === BEFORE_ENTITY){
|
||||
this._stateBeforeEntity(c);
|
||||
} else if(this._state === BEFORE_NUMERIC_ENTITY){
|
||||
this._stateBeforeNumericEntity(c);
|
||||
} else if(this._state === IN_NAMED_ENTITY){
|
||||
this._stateInNamedEntity(c);
|
||||
} else if(this._state === IN_NUMERIC_ENTITY){
|
||||
this._stateInNumericEntity(c);
|
||||
} else if(this._state === IN_HEX_ENTITY){
|
||||
this._stateInHexEntity(c);
|
||||
}
|
||||
|
||||
else {
|
||||
this._cbs.onerror(Error("unknown _state"), this._state);
|
||||
}
|
||||
|
||||
this._index++;
|
||||
}
|
||||
|
||||
this._cleanup();
|
||||
};
|
||||
|
||||
Tokenizer.prototype.pause = function(){
|
||||
this._running = false;
|
||||
};
|
||||
Tokenizer.prototype.resume = function(){
|
||||
this._running = true;
|
||||
|
||||
if(this._index < this._buffer.length){
|
||||
this._parse();
|
||||
}
|
||||
if(this._ended){
|
||||
this._finish();
|
||||
}
|
||||
};
|
||||
|
||||
Tokenizer.prototype.end = function(chunk){
|
||||
if(this._ended) this._cbs.onerror(Error(".end() after done!"));
|
||||
if(chunk) this.write(chunk);
|
||||
|
||||
this._ended = true;
|
||||
|
||||
if(this._running) this._finish();
|
||||
};
|
||||
|
||||
Tokenizer.prototype._finish = function(){
|
||||
//if there is remaining data, emit it in a reasonable way
|
||||
if(this._sectionStart < this._index){
|
||||
this._handleTrailingData();
|
||||
}
|
||||
|
||||
this._cbs.onend();
|
||||
};
|
||||
|
||||
Tokenizer.prototype._handleTrailingData = function(){
|
||||
var data = this._buffer.substr(this._sectionStart);
|
||||
|
||||
if(this._state === IN_CDATA || this._state === AFTER_CDATA_1 || this._state === AFTER_CDATA_2){
|
||||
this._cbs.oncdata(data);
|
||||
} else if(this._state === IN_COMMENT || this._state === AFTER_COMMENT_1 || this._state === AFTER_COMMENT_2){
|
||||
this._cbs.oncomment(data);
|
||||
} else if(this._state === IN_NAMED_ENTITY && !this._xmlMode){
|
||||
this._parseLegacyEntity();
|
||||
if(this._sectionStart < this._index){
|
||||
this._state = this._baseState;
|
||||
this._handleTrailingData();
|
||||
}
|
||||
} else if(this._state === IN_NUMERIC_ENTITY && !this._xmlMode){
|
||||
this._decodeNumericEntity(2, 10);
|
||||
if(this._sectionStart < this._index){
|
||||
this._state = this._baseState;
|
||||
this._handleTrailingData();
|
||||
}
|
||||
} else if(this._state === IN_HEX_ENTITY && !this._xmlMode){
|
||||
this._decodeNumericEntity(3, 16);
|
||||
if(this._sectionStart < this._index){
|
||||
this._state = this._baseState;
|
||||
this._handleTrailingData();
|
||||
}
|
||||
} else if(
|
||||
this._state !== IN_TAG_NAME &&
|
||||
this._state !== BEFORE_ATTRIBUTE_NAME &&
|
||||
this._state !== BEFORE_ATTRIBUTE_VALUE &&
|
||||
this._state !== AFTER_ATTRIBUTE_NAME &&
|
||||
this._state !== IN_ATTRIBUTE_NAME &&
|
||||
this._state !== IN_ATTRIBUTE_VALUE_SQ &&
|
||||
this._state !== IN_ATTRIBUTE_VALUE_DQ &&
|
||||
this._state !== IN_ATTRIBUTE_VALUE_NQ &&
|
||||
this._state !== IN_CLOSING_TAG_NAME
|
||||
){
|
||||
this._cbs.ontext(data);
|
||||
}
|
||||
//else, ignore remaining data
|
||||
//TODO add a way to remove current tag
|
||||
};
|
||||
|
||||
Tokenizer.prototype.reset = function(){
|
||||
Tokenizer.call(this, {xmlMode: this._xmlMode, decodeEntities: this._decodeEntities}, this._cbs);
|
||||
};
|
||||
|
||||
Tokenizer.prototype._getSection = function(){
|
||||
return this._buffer.substring(this._sectionStart, this._index);
|
||||
};
|
||||
|
||||
Tokenizer.prototype._emitToken = function(name){
|
||||
this._cbs[name](this._getSection());
|
||||
this._sectionStart = -1;
|
||||
};
|
||||
|
||||
Tokenizer.prototype._emitPartial = function(value){
|
||||
if(this._baseState !== TEXT){
|
||||
this._cbs.onattribdata(value); //TODO implement the new event
|
||||
} else {
|
||||
this._cbs.ontext(value);
|
||||
}
|
||||
};
|
21
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/WritableStream.js
generated
vendored
Normal file
21
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/WritableStream.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = Stream;
|
||||
|
||||
var Parser = require("./Parser.js"),
|
||||
WritableStream = require("stream").Writable || require("readable-stream").Writable;
|
||||
|
||||
function Stream(cbs, options){
|
||||
var parser = this._parser = new Parser(cbs, options);
|
||||
|
||||
WritableStream.call(this, {decodeStrings: false});
|
||||
|
||||
this.once("finish", function(){
|
||||
parser.end();
|
||||
});
|
||||
}
|
||||
|
||||
require("util").inherits(Stream, WritableStream);
|
||||
|
||||
WritableStream.prototype._write = function(chunk, encoding, cb){
|
||||
this._parser.write(chunk);
|
||||
cb();
|
||||
};
|
68
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/index.js
generated
vendored
Normal file
68
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
var Parser = require("./Parser.js"),
|
||||
DomHandler = require("domhandler");
|
||||
|
||||
function defineProp(name, value){
|
||||
delete module.exports[name];
|
||||
module.exports[name] = value;
|
||||
return value;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
Parser: Parser,
|
||||
Tokenizer: require("./Tokenizer.js"),
|
||||
ElementType: require("domelementtype"),
|
||||
DomHandler: DomHandler,
|
||||
get FeedHandler(){
|
||||
return defineProp("FeedHandler", require("./FeedHandler.js"));
|
||||
},
|
||||
get Stream(){
|
||||
return defineProp("Stream", require("./Stream.js"));
|
||||
},
|
||||
get WritableStream(){
|
||||
return defineProp("WritableStream", require("./WritableStream.js"));
|
||||
},
|
||||
get ProxyHandler(){
|
||||
return defineProp("ProxyHandler", require("./ProxyHandler.js"));
|
||||
},
|
||||
get DomUtils(){
|
||||
return defineProp("DomUtils", require("domutils"));
|
||||
},
|
||||
get CollectingHandler(){
|
||||
return defineProp("CollectingHandler", require("./CollectingHandler.js"));
|
||||
},
|
||||
// For legacy support
|
||||
DefaultHandler: DomHandler,
|
||||
get RssHandler(){
|
||||
return defineProp("RssHandler", this.FeedHandler);
|
||||
},
|
||||
//helper methods
|
||||
parseDOM: function(data, options) {
|
||||
var handler = new DomHandler(options);
|
||||
new Parser(handler, options).end(data);
|
||||
return handler.dom;
|
||||
},
|
||||
parseFeed: function(feed, options){
|
||||
var handler = new module.exports.FeedHandler(options);
|
||||
new Parser(handler, options).end(feed);
|
||||
return handler.dom;
|
||||
},
|
||||
createDomStream: function(cb, options, elementCb){
|
||||
var handler = new DomHandler(cb, options, elementCb);
|
||||
return new Parser(handler, options);
|
||||
},
|
||||
// List of all events that the parser emits
|
||||
EVENTS: { /* Format: eventname: number of arguments */
|
||||
attribute: 2,
|
||||
cdatastart: 0,
|
||||
cdataend: 0,
|
||||
text: 1,
|
||||
processinginstruction: 2,
|
||||
comment: 1,
|
||||
commentend: 0,
|
||||
closetag: 1,
|
||||
opentag: 2,
|
||||
opentagname: 1,
|
||||
error: 1,
|
||||
end: 0
|
||||
}
|
||||
};
|
7
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/.travis.yml
generated
vendored
Normal file
7
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
- "0.10"
|
||||
- 0.11
|
||||
|
||||
script: npm run coveralls
|
11
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/LICENSE
generated
vendored
Normal file
11
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) Felix Böhm
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/index.js
generated
vendored
Normal file
31
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/index.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
var encode = require("./lib/encode.js"),
|
||||
decode = require("./lib/decode.js");
|
||||
|
||||
exports.decode = function(data, level){
|
||||
return (!level || level <= 0 ? decode.XML : decode.HTML)(data);
|
||||
};
|
||||
|
||||
exports.decodeStrict = function(data, level){
|
||||
return (!level || level <= 0 ? decode.XML : decode.HTMLStrict)(data);
|
||||
};
|
||||
|
||||
exports.encode = function(data, level){
|
||||
return (!level || level <= 0 ? encode.XML : encode.HTML)(data);
|
||||
};
|
||||
|
||||
exports.encodeXML = encode.XML;
|
||||
|
||||
exports.encodeHTML4 =
|
||||
exports.encodeHTML5 =
|
||||
exports.encodeHTML = encode.HTML;
|
||||
|
||||
exports.decodeXML =
|
||||
exports.decodeXMLStrict = decode.XML;
|
||||
|
||||
exports.decodeHTML4 =
|
||||
exports.decodeHTML5 =
|
||||
exports.decodeHTML = decode.HTML;
|
||||
|
||||
exports.decodeHTML4Strict =
|
||||
exports.decodeHTML5Strict =
|
||||
exports.decodeHTMLStrict = decode.HTMLStrict;
|
72
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/lib/decode.js
generated
vendored
Normal file
72
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/lib/decode.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
var entityMap = require("../maps/entities.json"),
|
||||
legacyMap = require("../maps/legacy.json"),
|
||||
xmlMap = require("../maps/xml.json"),
|
||||
decodeCodePoint = require("./decode_codepoint.js");
|
||||
|
||||
var decodeXMLStrict = getStrictDecoder(xmlMap),
|
||||
decodeHTMLStrict = getStrictDecoder(entityMap);
|
||||
|
||||
function getStrictDecoder(map){
|
||||
var keys = Object.keys(map).join("|"),
|
||||
replace = getReplacer(map);
|
||||
|
||||
keys += "|#[xX][\\da-fA-F]+|#\\d+";
|
||||
|
||||
var re = new RegExp("&(?:" + keys + ");", "g");
|
||||
|
||||
return function(str){
|
||||
return String(str).replace(re, replace);
|
||||
};
|
||||
}
|
||||
|
||||
var decodeHTML = (function(){
|
||||
var legacy = Object.keys(legacyMap)
|
||||
.sort(sorter);
|
||||
|
||||
var keys = Object.keys(entityMap)
|
||||
.sort(sorter);
|
||||
|
||||
for(var i = 0, j = 0; i < keys.length; i++){
|
||||
if(legacy[j] === keys[i]){
|
||||
keys[i] += ";?";
|
||||
j++;
|
||||
} else {
|
||||
keys[i] += ";";
|
||||
}
|
||||
}
|
||||
|
||||
var re = new RegExp("&(?:" + keys.join("|") + "|#[xX][\\da-fA-F]+;?|#\\d+;?)", "g"),
|
||||
replace = getReplacer(entityMap);
|
||||
|
||||
function replacer(str){
|
||||
if(str.substr(-1) !== ";") str += ";";
|
||||
return replace(str);
|
||||
}
|
||||
|
||||
//TODO consider creating a merged map
|
||||
return function(str){
|
||||
return String(str).replace(re, replacer);
|
||||
};
|
||||
}());
|
||||
|
||||
function sorter(a, b){
|
||||
return a < b ? 1 : -1;
|
||||
}
|
||||
|
||||
function getReplacer(map){
|
||||
return function replace(str){
|
||||
if(str.charAt(1) === "#"){
|
||||
if(str.charAt(2) === "X" || str.charAt(2) === "x"){
|
||||
return decodeCodePoint(parseInt(str.substr(3), 16));
|
||||
}
|
||||
return decodeCodePoint(parseInt(str.substr(2), 10));
|
||||
}
|
||||
return map[str.slice(1, -1)];
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
XML: decodeXMLStrict,
|
||||
HTML: decodeHTML,
|
||||
HTMLStrict: decodeHTMLStrict
|
||||
};
|
26
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/lib/decode_codepoint.js
generated
vendored
Normal file
26
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/lib/decode_codepoint.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var decodeMap = require("../maps/decode.json");
|
||||
|
||||
module.exports = decodeCodePoint;
|
||||
|
||||
// modified version of https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
|
||||
function decodeCodePoint(codePoint){
|
||||
|
||||
if((codePoint >= 0xD800 && codePoint <= 0xDFFF) || codePoint > 0x10FFFF){
|
||||
return "\uFFFD";
|
||||
}
|
||||
|
||||
if(codePoint in decodeMap){
|
||||
codePoint = decodeMap[codePoint];
|
||||
}
|
||||
|
||||
var output = "";
|
||||
|
||||
if(codePoint > 0xFFFF){
|
||||
codePoint -= 0x10000;
|
||||
output += String.fromCharCode(codePoint >>> 10 & 0x3FF | 0xD800);
|
||||
codePoint = 0xDC00 | codePoint & 0x3FF;
|
||||
}
|
||||
|
||||
output += String.fromCharCode(codePoint);
|
||||
return output;
|
||||
}
|
48
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/lib/encode.js
generated
vendored
Normal file
48
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/lib/encode.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
var inverseXML = getInverseObj(require("../maps/xml.json")),
|
||||
xmlReplacer = getInverseReplacer(inverseXML);
|
||||
|
||||
exports.XML = getInverse(inverseXML, xmlReplacer);
|
||||
|
||||
var inverseHTML = getInverseObj(require("../maps/entities.json")),
|
||||
htmlReplacer = getInverseReplacer(inverseHTML);
|
||||
|
||||
exports.HTML = getInverse(inverseHTML, htmlReplacer);
|
||||
|
||||
function getInverseObj(obj){
|
||||
return Object.keys(obj).sort().reduce(function(inverse, name){
|
||||
inverse[obj[name]] = "&" + name + ";";
|
||||
return inverse;
|
||||
}, {});
|
||||
}
|
||||
|
||||
function getInverseReplacer(inverse){
|
||||
return new RegExp("\\" + Object.keys(inverse).sort().join("|\\"), "g");
|
||||
}
|
||||
|
||||
var re_nonASCII = /[^\0-\x7F]/g,
|
||||
re_astralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||
|
||||
function nonUTF8Replacer(c){
|
||||
return "&#x" + c.charCodeAt(0).toString(16).toUpperCase() + ";";
|
||||
}
|
||||
|
||||
function astralReplacer(c){
|
||||
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||
var high = c.charCodeAt(0);
|
||||
var low = c.charCodeAt(1);
|
||||
var codePoint = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
|
||||
return "&#x" + codePoint.toString(16).toUpperCase() + ";";
|
||||
}
|
||||
|
||||
function getInverse(inverse, re){
|
||||
function func(name){
|
||||
return inverse[name];
|
||||
}
|
||||
|
||||
return function(data){
|
||||
return data
|
||||
.replace(re, func)
|
||||
.replace(re_astralSymbols, astralReplacer)
|
||||
.replace(re_nonASCII, nonUTF8Replacer);
|
||||
};
|
||||
}
|
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/decode.json
generated
vendored
Normal file
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/decode.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"0":65533,"128":8364,"130":8218,"131":402,"132":8222,"133":8230,"134":8224,"135":8225,"136":710,"137":8240,"138":352,"139":8249,"140":338,"142":381,"145":8216,"146":8217,"147":8220,"148":8221,"149":8226,"150":8211,"151":8212,"152":732,"153":8482,"154":353,"155":8250,"156":339,"158":382,"159":376}
|
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/entities.json
generated
vendored
Normal file
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/entities.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/legacy.json
generated
vendored
Normal file
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/legacy.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"Aacute":"\u00C1","aacute":"\u00E1","Acirc":"\u00C2","acirc":"\u00E2","acute":"\u00B4","AElig":"\u00C6","aelig":"\u00E6","Agrave":"\u00C0","agrave":"\u00E0","amp":"&","AMP":"&","Aring":"\u00C5","aring":"\u00E5","Atilde":"\u00C3","atilde":"\u00E3","Auml":"\u00C4","auml":"\u00E4","brvbar":"\u00A6","Ccedil":"\u00C7","ccedil":"\u00E7","cedil":"\u00B8","cent":"\u00A2","copy":"\u00A9","COPY":"\u00A9","curren":"\u00A4","deg":"\u00B0","divide":"\u00F7","Eacute":"\u00C9","eacute":"\u00E9","Ecirc":"\u00CA","ecirc":"\u00EA","Egrave":"\u00C8","egrave":"\u00E8","ETH":"\u00D0","eth":"\u00F0","Euml":"\u00CB","euml":"\u00EB","frac12":"\u00BD","frac14":"\u00BC","frac34":"\u00BE","gt":">","GT":">","Iacute":"\u00CD","iacute":"\u00ED","Icirc":"\u00CE","icirc":"\u00EE","iexcl":"\u00A1","Igrave":"\u00CC","igrave":"\u00EC","iquest":"\u00BF","Iuml":"\u00CF","iuml":"\u00EF","laquo":"\u00AB","lt":"<","LT":"<","macr":"\u00AF","micro":"\u00B5","middot":"\u00B7","nbsp":"\u00A0","not":"\u00AC","Ntilde":"\u00D1","ntilde":"\u00F1","Oacute":"\u00D3","oacute":"\u00F3","Ocirc":"\u00D4","ocirc":"\u00F4","Ograve":"\u00D2","ograve":"\u00F2","ordf":"\u00AA","ordm":"\u00BA","Oslash":"\u00D8","oslash":"\u00F8","Otilde":"\u00D5","otilde":"\u00F5","Ouml":"\u00D6","ouml":"\u00F6","para":"\u00B6","plusmn":"\u00B1","pound":"\u00A3","quot":"\"","QUOT":"\"","raquo":"\u00BB","reg":"\u00AE","REG":"\u00AE","sect":"\u00A7","shy":"\u00AD","sup1":"\u00B9","sup2":"\u00B2","sup3":"\u00B3","szlig":"\u00DF","THORN":"\u00DE","thorn":"\u00FE","times":"\u00D7","Uacute":"\u00DA","uacute":"\u00FA","Ucirc":"\u00DB","ucirc":"\u00FB","Ugrave":"\u00D9","ugrave":"\u00F9","uml":"\u00A8","Uuml":"\u00DC","uuml":"\u00FC","Yacute":"\u00DD","yacute":"\u00FD","yen":"\u00A5","yuml":"\u00FF"}
|
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/xml.json
generated
vendored
Normal file
1
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/maps/xml.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"amp":"&","apos":"'","gt":">","lt":"<","quot":"\""}
|
113
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/package.json
generated
vendored
Normal file
113
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/package.json
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "entities",
|
||||
"raw": "entities@1.0",
|
||||
"rawSpec": "1.0",
|
||||
"scope": null,
|
||||
"spec": ">=1.0.0 <1.1.0",
|
||||
"type": "range"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\htmlparser2"
|
||||
]
|
||||
],
|
||||
"_from": "entities@>=1.0.0 <1.1.0",
|
||||
"_id": "entities@1.0.0",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/gitbook-plugin-multipart/htmlparser2/entities",
|
||||
"_npmUser": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
},
|
||||
"_npmVersion": "1.4.4",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "entities",
|
||||
"raw": "entities@1.0",
|
||||
"rawSpec": "1.0",
|
||||
"scope": null,
|
||||
"spec": ">=1.0.0 <1.1.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gitbook-plugin-multipart/htmlparser2"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz",
|
||||
"_shasum": "b2987aa3821347fcde642b24fdfc9e4fb712bf26",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "entities@1.0",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\gitbook-plugin-multipart\\node_modules\\htmlparser2",
|
||||
"author": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "Felix Boehm"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fb55/node-entities/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Encode & decode XML/HTML entities with ease",
|
||||
"devDependencies": {
|
||||
"coveralls": "*",
|
||||
"istanbul": "*",
|
||||
"jshint": "2",
|
||||
"mocha": "1",
|
||||
"mocha-lcov-reporter": "*"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"dist": {
|
||||
"shasum": "b2987aa3821347fcde642b24fdfc9e4fb712bf26",
|
||||
"tarball": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz"
|
||||
},
|
||||
"homepage": "https://github.com/fb55/node-entities",
|
||||
"jshintConfig": {
|
||||
"eqeqeq": true,
|
||||
"eqnull": true,
|
||||
"freeze": true,
|
||||
"globals": {
|
||||
"describe": true,
|
||||
"it": true
|
||||
},
|
||||
"latedef": "nofunc",
|
||||
"noarg": true,
|
||||
"node": true,
|
||||
"nonbsp": true,
|
||||
"proto": true,
|
||||
"quotmark": "double",
|
||||
"smarttabs": true,
|
||||
"trailing": true,
|
||||
"undef": true,
|
||||
"unused": true
|
||||
},
|
||||
"keywords": [
|
||||
"html",
|
||||
"xml",
|
||||
"entity",
|
||||
"encoding"
|
||||
],
|
||||
"license": "BSD-like",
|
||||
"main": "./index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
}
|
||||
],
|
||||
"name": "entities",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/fb55/node-entities.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coveralls": "npm run lint && npm run lcov && (cat coverage/lcov.info | coveralls || exit 0)",
|
||||
"lcov": "istanbul cover _mocha --report lcovonly -- -R spec",
|
||||
"lint": "jshint index.js lib/*.js test/*.js",
|
||||
"test": "mocha && npm run lint"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
31
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/readme.md
generated
vendored
Normal file
31
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/readme.md
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
#entities [](https://npmjs.org/package/entities) [](https://npmjs.org/package/entities) [](http://travis-ci.org/fb55/node-entities) [](https://coveralls.io/r/fb55/node-entities)
|
||||
|
||||
En- & decoder for XML/HTML entities.
|
||||
|
||||
####Features:
|
||||
* Focussed on ___speed___
|
||||
* Supports three levels of entities: __XML__, __HTML4__ & __HTML5__
|
||||
* Supports _char code_ entities (eg. `U`)
|
||||
|
||||
##How to…
|
||||
|
||||
###…install `entities`
|
||||
|
||||
npm i entities
|
||||
|
||||
###…use `entities`
|
||||
|
||||
```javascript
|
||||
//encoding
|
||||
require("entities").encode(<str> data[, <int> level]);
|
||||
//decoding
|
||||
require("entities").decode(<str> data[, <int> level]);
|
||||
```
|
||||
|
||||
The `level` attribute indicates what level of entities should be decoded (0 = XML, 1 = HTML4 and 2 = HTML5). The default is 0 (read: XML).
|
||||
|
||||
There are also methods to access the level directly. Just append the name of the level to the action and you're ready to go (e.g. `encodeHTML4(data)`, `decodeXML(data)`).
|
||||
|
||||
---
|
||||
|
||||
License: BSD-like
|
2
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/test/mocha.opts
generated
vendored
Normal file
2
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/test/mocha.opts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
--check-leaks
|
||||
--reporter spec
|
150
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/test/test.js
generated
vendored
Normal file
150
node_modules/gitbook-plugin-multipart/node_modules/htmlparser2/node_modules/entities/test/test.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
var assert = require("assert"),
|
||||
path = require("path"),
|
||||
entities = require("../");
|
||||
|
||||
describe("Encode->decode test", function(){
|
||||
var testcases = [
|
||||
{
|
||||
input: "asdf & ÿ ü '",
|
||||
xml: "asdf & ÿ ü '",
|
||||
html: "asdf & ÿ ü '"
|
||||
}, {
|
||||
input: "&",
|
||||
xml: "&#38;",
|
||||
html: "&#38;"
|
||||
},
|
||||
];
|
||||
testcases.forEach(function(tc) {
|
||||
var encodedXML = entities.encodeXML(tc.input);
|
||||
it("should XML encode " + tc.input, function(){
|
||||
assert.equal(encodedXML, tc.xml);
|
||||
});
|
||||
it("should default to XML encode " + tc.input, function(){
|
||||
assert.equal(entities.encode(tc.input), tc.xml);
|
||||
});
|
||||
it("should XML decode " + encodedXML, function(){
|
||||
assert.equal(entities.decodeXML(encodedXML), tc.input);
|
||||
});
|
||||
it("should default to XML encode " + encodedXML, function(){
|
||||
assert.equal(entities.decode(encodedXML), tc.input);
|
||||
});
|
||||
it("should default strict to XML encode " + encodedXML, function(){
|
||||
assert.equal(entities.decodeStrict(encodedXML), tc.input);
|
||||
});
|
||||
|
||||
var encodedHTML5 = entities.encodeHTML5(tc.input);
|
||||
it("should HTML5 encode " + tc.input, function(){
|
||||
assert.equal(encodedHTML5, tc.html);
|
||||
});
|
||||
it("should HTML5 decode " + encodedHTML5, function(){
|
||||
assert.equal(entities.decodeHTML(encodedHTML5), tc.input);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Decode test", function(){
|
||||
var testcases = [
|
||||
{ input: "&amp;", output: "&" },
|
||||
{ input: "&#38;", output: "&" },
|
||||
{ input: "&#x26;", output: "&" },
|
||||
{ input: "&#X26;", output: "&" },
|
||||
{ input: "&#38;", output: "&" },
|
||||
{ input: "&#38;", output: "&" },
|
||||
{ input: "&#38;", output: "&" },
|
||||
{ input: ":", output: ":" },
|
||||
{ input: ":", output: ":" },
|
||||
{ input: ":", output: ":" },
|
||||
{ input: ":", output: ":" }
|
||||
];
|
||||
testcases.forEach(function(tc) {
|
||||
it("should XML decode " + tc.input, function(){
|
||||
assert.equal(entities.decodeXML(tc.input), tc.output);
|
||||
});
|
||||
it("should HTML4 decode " + tc.input, function(){
|
||||
assert.equal(entities.decodeHTML(tc.input), tc.output);
|
||||
});
|
||||
it("should HTML5 decode " + tc.input, function(){
|
||||
assert.equal(entities.decodeHTML(tc.input), tc.output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var levels = ["xml", "entities"];
|
||||
|
||||
describe("Documents", function(){
|
||||
levels
|
||||
.map(function(n){ return path.join("..", "maps", n); })
|
||||
.map(require)
|
||||
.forEach(function(doc, i){
|
||||
describe("Decode", function(){
|
||||
it(levels[i], function(){
|
||||
Object.keys(doc).forEach(function(e){
|
||||
for(var l = i; l < levels.length; l++){
|
||||
assert.equal(entities.decode("&" + e + ";", l), doc[e]);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Decode strict", function(){
|
||||
it(levels[i], function(){
|
||||
Object.keys(doc).forEach(function(e){
|
||||
for(var l = i; l < levels.length; l++){
|
||||
assert.equal(entities.decodeStrict("&" + e + ";", l), doc[e]);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Encode", function(){
|
||||
it(levels[i], function(){
|
||||
Object.keys(doc).forEach(function(e){
|
||||
for(var l = i; l < levels.length; l++){
|
||||
assert.equal(entities.decode(entities.encode(doc[e], l), l), doc[e]);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var legacy = require("../maps/legacy.json");
|
||||
|
||||
describe("Legacy", function(){
|
||||
it("should decode", runLegacy);
|
||||
});
|
||||
|
||||
function runLegacy(){
|
||||
Object.keys(legacy).forEach(function(e){
|
||||
assert.equal(entities.decodeHTML("&" + e), legacy[e]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var astral = {
|
||||
"1D306": "\uD834\uDF06",
|
||||
"1D11E": "\uD834\uDD1E"
|
||||
};
|
||||
|
||||
var astralSpecial = {
|
||||
"80": "\u20AC",
|
||||
"110000": "\uFFFD"
|
||||
};
|
||||
|
||||
|
||||
describe("Astral entities", function(){
|
||||
Object.keys(astral).forEach(function(c){
|
||||
it("should decode " + astral[c], function(){
|
||||
assert.equal(entities.decode("&#x" + c + ";"), astral[c]);
|
||||
});
|
||||
|
||||
it("should encode " + astral[c], function(){
|
||||
assert.equal(entities.encode(astral[c]), "&#x" + c + ";");
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(astralSpecial).forEach(function(c){
|
||||
it("special should decode \\u" + c, function(){
|
||||
assert.equal(entities.decode("&#x" + c + ";"), astralSpecial[c]);
|
||||
});
|
||||
});
|
||||
});
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user