Comparing version 3.0.1 to 3.0.2
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -824,3 +824,3 @@ /// <reference types="node" /> | ||
* | ||
* // Serializes the <body> element content. | ||
* // Serializes the <html> element content. | ||
* const str = parse5.serialize(document.childNodes[1]); | ||
@@ -847,8 +847,8 @@ * | ||
* | ||
* // Fetch the google.com content and obtain it's <body> node | ||
* http.get('http://google.com', res => { | ||
* // Fetch the page content and obtain it's <head> node | ||
* http.get('http://inikulin.github.io/parse5/', res => { | ||
* const parser = new parse5.ParserStream(); | ||
* | ||
* parser.once('finish', () => { | ||
* console.log(parser.document.childNodes[1].childNodes[1].tagName); //> 'body' | ||
* console.log(parser.document.childNodes[1].childNodes[0].tagName); //> 'head' | ||
* }); | ||
@@ -929,3 +929,3 @@ * | ||
* converter.once('finish', () => { | ||
* console.log(converter.document.childNodes[1].childNodes[1].tagName); //> 'body' | ||
* console.log(converter.document.childNodes[1].childNodes[0].tagName); //> 'head' | ||
* }); | ||
@@ -932,0 +932,0 @@ * |
@@ -11,53 +11,54 @@ 'use strict'; | ||
exports.assign = function (parser) { | ||
//NOTE: obtain Parser proto this way to avoid module circular references | ||
var parserProto = Object.getPrototypeOf(parser), | ||
treeAdapter = parser.treeAdapter, | ||
attachableElementLocation = null, | ||
lastFosterParentingLocation = null, | ||
currentToken = null; | ||
function setEndLocation(element, closingToken, treeAdapter) { | ||
var loc = element.__location; | ||
function setEndLocation(element, closingToken) { | ||
var loc = element.__location; | ||
if (!loc) | ||
return; | ||
if (!loc) | ||
return; | ||
if (!loc.startTag) { | ||
loc.startTag = { | ||
line: loc.line, | ||
col: loc.col, | ||
startOffset: loc.startOffset, | ||
endOffset: loc.endOffset | ||
}; | ||
if (loc.attrs) | ||
loc.startTag.attrs = loc.attrs; | ||
} | ||
if (!loc.startTag) { | ||
loc.startTag = { | ||
line: loc.line, | ||
col: loc.col, | ||
startOffset: loc.startOffset, | ||
endOffset: loc.endOffset | ||
}; | ||
if (closingToken.location) { | ||
var ctLocation = closingToken.location, | ||
tn = treeAdapter.getTagName(element), | ||
// NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing tag and | ||
// for cases like <td> <p> </td> - 'p' closes without a closing tag | ||
isClosingEndTag = closingToken.type === Tokenizer.END_TAG_TOKEN && | ||
tn === closingToken.tagName; | ||
if (isClosingEndTag) { | ||
loc.endTag = { | ||
line: ctLocation.line, | ||
col: ctLocation.col, | ||
startOffset: ctLocation.startOffset, | ||
endOffset: ctLocation.endOffset | ||
}; | ||
if (loc.attrs) | ||
loc.startTag.attrs = loc.attrs; | ||
} | ||
if (isClosingEndTag) | ||
loc.endOffset = ctLocation.endOffset; | ||
else | ||
loc.endOffset = ctLocation.startOffset; | ||
} | ||
} | ||
if (closingToken.location) { | ||
var ctLocation = closingToken.location, | ||
tn = treeAdapter.getTagName(element), | ||
// NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing tag and | ||
// for cases like <td> <p> </td> - 'p' closes without a closing tag | ||
isClosingEndTag = closingToken.type === Tokenizer.END_TAG_TOKEN && | ||
tn === closingToken.tagName; | ||
if (isClosingEndTag) { | ||
loc.endTag = { | ||
line: ctLocation.line, | ||
col: ctLocation.col, | ||
startOffset: ctLocation.startOffset, | ||
endOffset: ctLocation.endOffset | ||
}; | ||
} | ||
exports.assign = function (parser) { | ||
//NOTE: obtain Parser proto this way to avoid module circular references | ||
var parserProto = Object.getPrototypeOf(parser), | ||
treeAdapter = parser.treeAdapter, | ||
attachableElementLocation = null, | ||
lastFosterParentingLocation = null, | ||
currentToken = null; | ||
if (isClosingEndTag) | ||
loc.endOffset = ctLocation.endOffset; | ||
else | ||
loc.endOffset = ctLocation.startOffset; | ||
} | ||
else if (closingToken.type === Tokenizer.EOF_TOKEN) | ||
loc.endOffset = parser.tokenizer.preprocessor.sourcePos; | ||
} | ||
@@ -74,3 +75,3 @@ //NOTE: patch _bootstrap method | ||
parser.openElements.pop = function () { | ||
setEndLocation(this.current, currentToken, treeAdapter); | ||
setEndLocation(this.current, currentToken); | ||
OpenElementStack.prototype.pop.call(this); | ||
@@ -81,3 +82,3 @@ }; | ||
for (var i = this.stackTop; i > 0; i--) | ||
setEndLocation(this.items[i], currentToken, treeAdapter); | ||
setEndLocation(this.items[i], currentToken); | ||
@@ -88,3 +89,3 @@ OpenElementStack.prototype.popAllUpToHtmlElement.call(this); | ||
parser.openElements.remove = function (element) { | ||
setEndLocation(element, currentToken, treeAdapter); | ||
setEndLocation(element, currentToken); | ||
OpenElementStack.prototype.remove.call(this, element); | ||
@@ -94,3 +95,12 @@ }; | ||
parser._runParsingLoop = function (scriptHandler) { | ||
parserProto._runParsingLoop.call(this, scriptHandler); | ||
// NOTE: generate location info for elements | ||
// that remains on open element stack | ||
for (var i = parser.openElements.stackTop; i >= 0; i--) | ||
setEndLocation(parser.openElements.items[i], currentToken); | ||
}; | ||
//Token processing | ||
@@ -115,3 +125,3 @@ parser._processTokenInForeignContent = function (token) { | ||
if (this.treeAdapter.getTagName(element) === token.tagName) { | ||
setEndLocation(element, token, treeAdapter); | ||
setEndLocation(element, token); | ||
break; | ||
@@ -118,0 +128,0 @@ } |
@@ -43,3 +43,3 @@ 'use strict'; | ||
ParserStream.prototype._runParsingLoop = function () { | ||
this.parser._runParsingLoop(this.writeCallback, this._scriptHandler); | ||
this.parser.runParsingLoopForCurrentChunk(this.writeCallback, this._scriptHandler); | ||
}; | ||
@@ -46,0 +46,0 @@ |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "parse5", | ||
"description": "HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)", | ||
@@ -6,0 +6,0 @@ "contributors": "https://github.com/inikulin/parse5/graphs/contributors", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7232
354952