gumbo-parser
Advanced tools
Comparing version 0.1.1 to 0.1.2
var bind = require("./build/Release/binding"); | ||
module.exports = function Gumbo() { | ||
var ret = bind.gumbo.apply(this, arguments); | ||
module.exports = function Gumbo(text, config) { | ||
config = config || {}; | ||
var ret = bind.gumbo.call(this, text, config); | ||
@@ -6,0 +7,0 @@ // extract the root tag from document resp |
{ | ||
"name": "gumbo-parser", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "Karl Westin <karl.westin@gmail.com>", | ||
@@ -19,3 +19,3 @@ "description": "Parsing HTML using google gumbo parser", | ||
"license": "MIT", | ||
"engines": { "node": ">=0.10" } | ||
"engines": { "node": ">=0.8" } | ||
} |
@@ -17,2 +17,12 @@ # Gumbo Parser | ||
You can also pass in the options | ||
gumbo(htmlstring, { | ||
// The tab-stop size, for computing positions in source code that uses tabs. | ||
// default: 8 | ||
tabStop: 8, | ||
// Whether or not to stop parsing when the first error is encountered. | ||
// default: false | ||
stopOnFirstError: true | ||
}); | ||
returns: | ||
@@ -48,3 +58,5 @@ | ||
hasDoctype true/false | ||
name: (string) Currently figuring this out | ||
name: (string) -> see below | ||
publicIdentifier (string) " | ||
systemIdentifier (string) " | ||
@@ -63,2 +75,13 @@ CommentNode | ||
### About html doctypes | ||
An html document will always have the `document.name` "html". | ||
If the document has anything else in the type, for example this html4 doctype: | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
the first part within quotation marks will end up in the `document.publicIdentifier`, | ||
and the second part will be in `document.systemIdentifier`. You can read more about this here: [http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#syntax-doctype](http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#syntax-doctype). | ||
### Build and test: | ||
@@ -70,1 +93,10 @@ ``` | ||
``` | ||
## Changes | ||
**0.1.2** Taking the (optional) options argument | ||
providing publicIdentifier and systemIdentifer for the doctype | ||
**0.1.1** Fix build on node 0.8 | ||
**0.1.0** Passing { document: document, root: root } instead of only root |
var gumbo = require("../node-gumbo"); | ||
var fs = require("fs"); | ||
var reader = require("./reader"); | ||
var assert = require("assert"); | ||
function tryParse(err, text) { | ||
if(err) { | ||
throw err; | ||
} | ||
console.log("Running tests..."); | ||
reader("/test.html", function(text) { | ||
console.log("Running: normal"); | ||
@@ -29,13 +26,27 @@ var output = gumbo(text); | ||
console.log("...done!"); | ||
}); | ||
} | ||
reader("/parse-error.html", function(text) { | ||
console.log("Running: stopOnFirstError"); | ||
// API changed between 0.8 and 0.10 | ||
var args = [__dirname + "/test.html"]; | ||
if(fs.readFile.length == 2) { | ||
args.push("utf-8", tryParse); | ||
} else { | ||
args.push({ encoding: "utf-8" }, tryParse); | ||
} | ||
var output = gumbo(text, { stopOnFirstError: true }); | ||
assert.equal(output.root, undefined); | ||
console.log("stopped on error when option is passed"); | ||
fs.readFile.apply(fs, args); | ||
var output2 = gumbo(text); | ||
assert.notEqual(output2.root, undefined); | ||
console.log("didn't stop on error by default"); | ||
console.log("...done!"); | ||
}); | ||
reader("/legacy-doctype.html", function(text) { | ||
console.log("Running: legacy doctypes"); | ||
var output = gumbo(text).document; | ||
assert(output.systemIdentifier, "system parameter is parsed"); | ||
assert(output.publicIdentifier, "public parameter is parsed"); | ||
console.log("added systemIdentifier and publicIdentifier"); | ||
console.log("...done!"); | ||
}); |
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
1843774
212
3465
99