Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions lib/Pure-JavaScript-HTML5-Parser/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,43 @@
*
* This code is triple licensed using Apache Software License 2.0,
* Mozilla Public License or GNU Public License
*
*
* ////////////////////////////////////////////////////////////////////////////
*
*
* 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
*
*
* ////////////////////////////////////////////////////////////////////////////
*
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (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.mozilla.org/MPL/
*
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
*
* The Original Code is Simple HTML Parser.
*
*
* The Initial Developer of the Original Code is Erik Arvidsson.
* Portions created by Erik Arvidssson are Copyright (C) 2004. All Rights
* Reserved.
*
*
* ////////////////////////////////////////////////////////////////////////////
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Expand Down Expand Up @@ -107,15 +107,11 @@

var HTMLParser = this.HTMLParser = function (html, handler) {
var index, chars, match, stack = [], last = html;
stack.last = function () {
return this[this.length - 1];
};

while (html) {
chars = true;

// Make sure we're not in a script or style element
if (!stack.last() || !special[stack.last()]) {
if (!stack[stack.length - 1] || !special[stack[stack.length - 1]]) {

// Comment
if (html.indexOf("<!--") == 0) {
Expand Down Expand Up @@ -160,15 +156,15 @@
}

} else {
html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack[stack.length - 1] + "[^>]*>"), function (all, text) {
text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2");
if (handler.chars)
handler.chars(text);

return "";
});

parseEndTag("", stack.last());
parseEndTag("", stack[stack.length - 1]);
}

if (html == last)
Expand All @@ -183,12 +179,12 @@
tagName = tagName.toLowerCase();

if (block[tagName]) {
while (stack.last() && inline[stack.last()]) {
parseEndTag("", stack.last());
while (stack[stack.length - 1] && inline[stack[stack.length - 1]]) {
parseEndTag("", stack[stack.length - 1]);
}
}

if (closeSelf[tagName] && stack.last() == tagName) {
if (closeSelf[tagName] && stack[stack.length - 1] == tagName) {
parseEndTag("", tagName);
}

Expand Down