├── .gitignore ├── LICENSE.html ├── LICENSE_files ├── css.css ├── css_002.css └── css_003.css ├── README.md ├── index.html ├── index.js ├── locale ├── en_US.json ├── index.css ├── index.html └── index.js ├── package.json ├── slowparse.js ├── src ├── CSSParser.js ├── DOMBuilder.js ├── DocumentFragment.js ├── HTMLParser.js ├── Node.js ├── ParseError.js ├── ParseErrorBuilders.js ├── Stream.js ├── checkMixedContent.js ├── index.js ├── shim │ └── errors.jquery.js └── voidHtmlElements.js ├── style.css ├── test.js └── test ├── node └── qunit-shim.js └── test-slowparse.js /.gitignore: -------------------------------------------------------------------------------- 1 | docs 2 | /node_modules/ 3 | -------------------------------------------------------------------------------- /LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 |means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
82 |means the combination of the Contributions of others (if any) 85 | used by a Contributor and that particular Contributor’s Contribution.
86 |means Covered Software of a particular Contributor.
89 |means Source Code Form to which the initial Contributor has 92 | attached the notice in Exhibit A, the Executable Form of such Source 93 | Code Form, and Modifications of such Source Code Form, in each case 94 | including portions thereof.
95 |means
98 |that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
that the Covered Software was made available under the terms of 101 | version 1.1 or earlier of the License, but not also under the terms of a 102 | Secondary License.
means any form of the work other than Source Code Form.
107 |means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
110 |means this document.
113 |means having the right to grant, to the maximum extent possible, 116 | whether at the time of the initial grant or subsequently, any and all of 117 | the rights conveyed by this License.
118 |means any of the following:
121 |any file in Source Code Form that results from an addition to, 123 | deletion from, or modification of the contents of Covered Software; or
any new file in Source Code Form that contains any Covered Software.
means any patent claim(s), including without limitation, method, 129 | process, and apparatus claims, in any patent Licensable by such 130 | Contributor that would be infringed, but for the grant of the License, 131 | by the making, using, selling, offering for sale, having made, import, 132 | or transfer of either its Contributions or its Contributor Version.
133 |means either the GNU General Public License, Version 2.0, the GNU 136 | Lesser General Public License, Version 2.1, the GNU Affero General 137 | Public License, Version 3.0, or any later versions of those licenses.
138 |means the form of the work preferred for making modifications.
141 |means an individual or a legal entity exercising rights under 144 | this License. For legal entities, “You” includes any entity that 145 | controls, is controlled by, or is under common control with You. For 146 | purposes of this definition, “control” means (a) the power, direct or 147 | indirect, to cause the direction or management of such entity, whether 148 | by contract or otherwise, or (b) ownership of more than fifty percent 149 | (50%) of the outstanding shares or beneficial ownership of such entity.
150 |Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
155 |under intellectual property rights (other than patent or 157 | trademark) Licensable by such Contributor to use, reproduce, make 158 | available, modify, display, perform, distribute, and otherwise exploit 159 | its Contributions, either on an unmodified basis, with Modifications, or 160 | as part of a Larger Work; and
under Patent Claims of such Contributor to make, use, sell, offer 162 | for sale, have made, import, and otherwise transfer either its 163 | Contributions or its Contributor Version.
The licenses granted in Section 2.1 with respect to any 167 | Contribution become effective for each Contribution on the date the 168 | Contributor first distributes such Contribution.
169 |The licenses granted in this Section 2 are the only rights 171 | granted under this License. No additional rights or licenses will be 172 | implied from the distribution or licensing of Covered Software under 173 | this License. Notwithstanding Section 2.1(b) above, no patent 174 | license is granted by a Contributor:
175 |for any code that a Contributor has removed from Covered Software; or
for infringements caused by: (i) Your and any other third party’s 178 | modifications of Covered Software, or (ii) the combination of its 179 | Contributions with other software (except as part of its Contributor 180 | Version); or
under Patent Claims infringed by Covered Software in the absence of its Contributions.
This License does not grant any rights in the trademarks, service 184 | marks, or logos of any Contributor (except as may be necessary to comply 185 | with the notice requirements in Section 3.4).
186 |No Contributor makes additional grants as a result of Your choice to 188 | distribute the Covered Software under a subsequent version of this 189 | License (see Section 10.2) or under the terms of a Secondary 190 | License (if permitted under the terms of Section 3.3).
191 |Each Contributor represents that the Contributor believes its 193 | Contributions are its original creation(s) or it has sufficient rights 194 | to grant the rights to its Contributions conveyed by this License.
195 |This License is not intended to limit any rights You have under 197 | applicable copyright doctrines of fair use, fair dealing, or other 198 | equivalents.
199 |Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1.
201 |All distribution of Covered Software in Source Code Form, including 204 | any Modifications that You create or to which You contribute, must be 205 | under the terms of this License. You must inform recipients that the 206 | Source Code Form of the Covered Software is governed by the terms of 207 | this License, and how they can obtain a copy of this License. You may 208 | not attempt to alter or restrict the recipients’ rights in the Source 209 | Code Form.
210 |If You distribute Covered Software in Executable Form then:
212 |such Covered Software must also be made available in Source Code 214 | Form, as described in Section 3.1, and You must inform recipients 215 | of the Executable Form how they can obtain a copy of such Source Code 216 | Form by reasonable means in a timely manner, at a charge no more than 217 | the cost of distribution to the recipient; and
You may distribute such Executable Form under the terms of this 219 | License, or sublicense it under different terms, provided that the 220 | license for the Executable Form does not attempt to limit or alter the 221 | recipients’ rights in the Source Code Form under this License.
You may create and distribute a Larger Work under terms of Your 225 | choice, provided that You also comply with the requirements of this 226 | License for the Covered Software. If the Larger Work is a combination of 227 | Covered Software with a work governed by one or more Secondary 228 | Licenses, and the Covered Software is not Incompatible With Secondary 229 | Licenses, this License permits You to additionally distribute such 230 | Covered Software under the terms of such Secondary License(s), so that 231 | the recipient of the Larger Work may, at their option, further 232 | distribute the Covered Software under the terms of either this License 233 | or such Secondary License(s).
234 |You may not remove or alter the substance of any license notices 236 | (including copyright notices, patent notices, disclaimers of warranty, 237 | or limitations of liability) contained within the Source Code Form of 238 | the Covered Software, except that You may alter any license notices to 239 | the extent required to remedy known factual inaccuracies.
240 |You may choose to offer, and to charge a fee for, warranty, support, 242 | indemnity or liability obligations to one or more recipients of Covered 243 | Software. However, You may do so only on Your own behalf, and not on 244 | behalf of any Contributor. You must make it absolutely clear that any 245 | such warranty, support, indemnity, or liability obligation is offered by 246 | You alone, and You hereby agree to indemnify every Contributor for any 247 | liability incurred by such Contributor as a result of warranty, support, 248 | indemnity or liability terms You offer. You may include additional 249 | disclaimers of warranty and limitations of liability specific to any 250 | jurisdiction.
251 |If it is impossible for You to comply with any of the terms of this 253 | License with respect to some or all of the Covered Software due to 254 | statute, judicial order, or regulation then You must: (a) comply with 255 | the terms of this License to the maximum extent possible; and (b) 256 | describe the limitations and the code they affect. Such description must 257 | be placed in a text file included with all distributions of the Covered 258 | Software under this License. Except to the extent prohibited by statute 259 | or regulation, such description must be sufficiently detailed for a 260 | recipient of ordinary skill to be able to understand it.
261 |5.1. The rights granted under this License will terminate 263 | automatically if You fail to comply with any of its terms. However, if 264 | You become compliant, then the rights granted under this License from a 265 | particular Contributor are reinstated (a) provisionally, unless and 266 | until such Contributor explicitly and finally terminates Your grants, 267 | and (b) on an ongoing basis, if such Contributor fails to notify You of 268 | the non-compliance by some reasonable means prior to 60 days after You 269 | have come back into compliance. Moreover, Your grants from a particular 270 | Contributor are reinstated on an ongoing basis if such Contributor 271 | notifies You of the non-compliance by some reasonable means, this is the 272 | first time You have received notice of non-compliance with this License 273 | from such Contributor, and You become compliant prior to 30 days after 274 | Your receipt of the notice.
275 |5.2. If You initiate litigation against any entity by asserting a 276 | patent infringement claim (excluding declaratory judgment actions, 277 | counter-claims, and cross-claims) alleging that a Contributor Version 278 | directly or indirectly infringes any patent, then the rights granted to 279 | You by any and all Contributors for the Covered Software under 280 | Section 2.1 of this License shall terminate.
281 |5.3. In the event of termination under Sections 5.1 or 5.2 282 | above, all end user license agreements (excluding distributors and 283 | resellers) which have been validly granted by You or Your distributors 284 | under this License prior to termination shall survive termination.
285 |Covered Software is provided under this License on an “as is” 287 | basis, without warranty of any kind, either expressed, implied, or 288 | statutory, including, without limitation, warranties that the Covered 289 | Software is free of defects, merchantable, fit for a particular purpose 290 | or non-infringing. The entire risk as to the quality and performance of 291 | the Covered Software is with You. Should any Covered Software prove 292 | defective in any respect, You (not any Contributor) assume the cost of 293 | any necessary servicing, repair, or correction. This disclaimer of 294 | warranty constitutes an essential part of this License. No use of any 295 | Covered Software is authorized under this License except under this 296 | disclaimer.
297 |Under no circumstances and under no legal theory, whether tort 299 | (including negligence), contract, or otherwise, shall any Contributor, 300 | or anyone who distributes Covered Software as permitted above, be liable 301 | to You for any direct, indirect, special, incidental, or consequential 302 | damages of any character including, without limitation, damages for lost 303 | profits, loss of goodwill, work stoppage, computer failure or 304 | malfunction, or any and all other commercial damages or losses, even if 305 | such party shall have been informed of the possibility of such damages. 306 | This limitation of liability shall not apply to liability for death or 307 | personal injury resulting from such party’s negligence to the extent 308 | applicable law prohibits such limitation. Some jurisdictions do not 309 | allow the exclusion or limitation of incidental or consequential 310 | damages, so this exclusion and limitation may not apply to You.
311 |Any litigation relating to this License may be brought only in the 313 | courts of a jurisdiction where the defendant maintains its principal 314 | place of business and such litigation shall be governed by laws of that 315 | jurisdiction, without reference to its conflict-of-law provisions. 316 | Nothing in this Section shall prevent a party’s ability to bring 317 | cross-claims or counter-claims.
318 |This License represents the complete agreement concerning the subject 320 | matter hereof. If any provision of this License is held to be 321 | unenforceable, such provision shall be reformed only to the extent 322 | necessary to make it enforceable. Any law or regulation which provides 323 | that the language of a contract shall be construed against the drafter 324 | shall not be used to construe this License against a Contributor.
325 |Mozilla Foundation is the license steward. Except as provided in 328 | Section 10.3, no one other than the license steward has the right 329 | to modify or publish new versions of this License. Each version will be 330 | given a distinguishing version number.
331 |You may distribute the Covered Software under the terms of the 333 | version of the License under which You originally received the Covered 334 | Software, or under the terms of any subsequent version published by the 335 | license steward.
336 |If you create software not governed by this License, and you want to 338 | create a new license for such software, you may create and use a 339 | modified version of this License if you rename the license and remove 340 | any references to the name of the license steward (except to note that 341 | such modified license differs from this License).
342 |If You choose to distribute Source Code Form that is Incompatible 344 | With Secondary Licenses under the terms of this version of the License, 345 | the notice described in Exhibit B of this License must be attached.
346 |348 |352 |This Source Code Form is subject to the terms of the Mozilla Public 349 | License, v. 2.0. If a copy of the MPL was not distributed with this 350 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
351 |
If it is not possible or desirable to put the notice in a particular 353 | file, then You may include the notice in a location (such as a LICENSE 354 | file in a relevant directory) where a recipient would be likely to look 355 | for such a notice.
356 |You may add additional accurate notices of copyright ownership.
357 |359 |361 | 362 | 363 | -------------------------------------------------------------------------------- /LICENSE_files/css.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Droid Sans Mono'; 3 | font-style: normal; 4 | font-weight: normal; 5 | src: local('Droid Sans Mono'), local('DroidSansMono'), url('http://themes.googleusercontent.com/static/fonts/droidsansmono/v4/ns-m2xQYezAtqh7ai59hJaH0X__W3S3MJL29bc5CWfs.woff') format('woff'); 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE_files/css_002.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Crimson Text'; 3 | font-style: normal; 4 | font-weight: normal; 5 | src: local('Crimson Text'), local('CrimsonText-Roman'), url('http://themes.googleusercontent.com/static/fonts/crimsontext/v3/3IFMwfRa07i-auYR-B-zNaRDOzjiPcYnFooOUGCOsRk.woff') format('woff'); 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE_files/css_003.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Lora'; 3 | font-style: normal; 4 | font-weight: normal; 5 | src: local('Lora'), url('http://themes.googleusercontent.com/static/fonts/lora/v5/nAKwuw6_dIh5kwvpj3ShNfesZW2xOQ-xsNqO47m55DA.woff') format('woff'); 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Slowparse, a friendlier HTML5 parser 2 | 3 | Slowparse is an experimental JavaScript-based HTML5 parser born out of Mozilla Webmaking initiatives. A live demo of Slowparse can be found over at http://mozilla.github.io/slowparse 4 | 5 | ## Installing Slowparse 6 | 7 | The Slowparse library can be used both in the browser and in environments that support commonjs requirements such as Node.js, by respectively including it as a script resource: 8 | ``` 9 | 10 | ``` 11 | or as module import, by installing it using npm: 12 | ``` 13 | $> npm install slowparse 14 | ``` 15 | After installing, Slowparse can then be required into your code like any other module: 16 | ``` 17 | var Slowparse = require("slowparse"); 18 | ``` 19 | 20 | ## Using Slowparse 21 | 22 | To use Slowparse, call its `.HTML` function: 23 | 24 | ``` 25 | var result = Slowparse.HTML(document, '... html source here ...', options); 26 | ``` 27 | 28 | This function takes a DOM context as first argument, and HTML5 source code as second argument. The `options` object is optional, and if used can contain: 29 | 30 | ### options.errorDetectors 31 | 32 | This is an array of "additional parsers" that will be called as 'detector(html, domBuilder.fragment)` when no errors are found by Slowparse. These can be useful when you have additional constraints on what HTML source is permitted in your own software that cannot or should not be dealt with by Slowparse itself. 33 | 34 | This is mostly a convenience construction, and using it is equivalent to doing an `if (!result.error)` test and running the input through your own, additional parsers if no errors we found. 35 | 36 | ### options.disallowActiveAttributes 37 | 38 | This option can be either `true` or `false`, and when `true` will blank out attributes when it sees any that start with `on` such as `onclick`, `onload`, etc. 39 | 40 | This means the DOM formed during the Slowparse run is a tiny bit more secure, although you will still be responsible for checking for potentially harmful active content (Slowparse is not a security tool, and should not be used as such). 41 | 42 | ### Validating HTML 43 | 44 | Slowparse accepts both full HTML5 documents (starting at `` and ending in `This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.
360 |