Skip to content
This repository was archived by the owner on Jan 23, 2020. It is now read-only.

Commit 8566e91

Browse files
committed
Merge pull request #21 from neraliu/strict-context-parser
porting strict context parser to context parser
2 parents 61bd774 + 09c3d45 commit 8566e91

File tree

8 files changed

+1073
-113
lines changed

8 files changed

+1073
-113
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
HTML5 Context Parser
22
====================
3-
43
HTML5 Context Parser is a robust and small footprint HTML5 context parser that parses HTML 5 web pages and reports the execution context of each character seen.
54

5+
[![npm version][npm-badge]][npm]
6+
[![dependency status][dep-badge]][dep-status]
7+
8+
[npm]: https://www.npmjs.org/package/context-parser
9+
[npm-badge]: https://img.shields.io/npm/v/context-parser.svg?style=flat-square
10+
[dep-status]: https://david-dm.org/yahoo/context-parser
11+
[dep-badge]: https://img.shields.io/david/yahoo/context-parser.svg?style=flat-square
12+
613
## Overview
714

815
### Execution Context

bin/context-dump

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,36 @@ Debug.enable(progname);
1414
var Parser = require("../src/context-parser").Parser,
1515
debug = Debug(progname),
1616
fs = require('fs'),
17-
file,
18-
noofargs = 0,
19-
parser = new Parser();
17+
file,
18+
enableInputPreProcessing = false, enableCanonicalization = false, enableIEConditionalComments = false, enableStateTracking = true,
19+
noofargs = 0;
2020

2121
process.argv.forEach(function(val, index) {
2222
++noofargs;
2323
if (index === 2) {
2424
file = val;
25+
} else if (index === 3) {
26+
enableInputPreProcessing = val === "1"? true:false;
27+
} else if (index === 4) {
28+
enableCanonicalization = val === "1"? true:false;
2529
}
2630
});
2731

32+
var config = {
33+
enableInputPreProcessing: enableInputPreProcessing,
34+
enableCanonicalization: enableCanonicalization,
35+
enableIEConditionalComments: enableIEConditionalComments,
36+
enableStateTracking: enableStateTracking
37+
},
38+
parser = new Parser(config);
39+
2840
Parser.prototype.printCharWithState = function() {
2941
var len = this.states.length;
3042
debug('{ statesSize: '+len+' }');
3143
for(var i=0;i<len;i++) {
32-
var c = this.bytes[i];
44+
var c = this.buffer[i];
3345
var s = this.states[i];
34-
var t = this.symbols[i];
46+
var t = this.symbol[i];
3547

3648
if (i === 0) {
3749
debug('{ ch: 0, state: '+s+', symbol: 0 }');
@@ -49,7 +61,7 @@ Debug.enable(progname);
4961
return 0;
5062
};
5163

52-
if (noofargs === 3) {
64+
if (noofargs <= 5) {
5365
if (fs.existsSync(file)) {
5466
var data = fs.readFileSync(file, 'utf-8');
5567
parser.contextualize(data, data.length);
@@ -60,8 +72,8 @@ Debug.enable(progname);
6072
process.exit(1);
6173
}
6274
} else {
63-
console.log("Usage: context-dump <any html file>");
75+
console.log("Usage: context-dump <html file> <input preprocessing:0|1> <canonicalization:0|1>");
6476
process.exit(1);
6577
}
6678

67-
}).call(this);
79+
}).call(this);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "context-parser",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"licenses": [
55
{
66
"type": "BSD",
@@ -29,8 +29,8 @@
2929
"clean": "grunt clean",
3030
"test": "grunt test"
3131
},
32-
"dependencies": {},
3332
"devDependencies": {
33+
"chai": "^2.3.0",
3434
"debug": "^2.*",
3535
"expect.js": "^0.3.1",
3636
"grunt": "^0.4.5",

0 commit comments

Comments
 (0)