Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: node_modules/vulcanize/node_modules/whacko/node_modules/parse5/lib/simple_api/simple_api_parser.js

Issue 800513006: Added vulcanize under third_party/npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: node_modules/vulcanize/node_modules/whacko/node_modules/parse5/lib/simple_api/simple_api_parser.js
diff --git a/node_modules/vulcanize/node_modules/whacko/node_modules/parse5/lib/simple_api/simple_api_parser.js b/node_modules/vulcanize/node_modules/whacko/node_modules/parse5/lib/simple_api/simple_api_parser.js
new file mode 100644
index 0000000000000000000000000000000000000000..df7c58a58b8acf64dcc611dc2b4ec779146c3f31
--- /dev/null
+++ b/node_modules/vulcanize/node_modules/whacko/node_modules/parse5/lib/simple_api/simple_api_parser.js
@@ -0,0 +1,70 @@
+'use strict';
+
+var Tokenizer = require('../tokenization/tokenizer'),
+ TokenizerProxy = require('./tokenizer_proxy');
+
+//Skipping handler
+function skip() {
+ //NOTE: do nothing =)
+}
+
+//SimpleApiParser
+var SimpleApiParser = module.exports = function (handlers) {
+ this.handlers = {
+ doctype: handlers.doctype || skip,
+ startTag: handlers.startTag || skip,
+ endTag: handlers.endTag || skip,
+ text: handlers.text || skip,
+ comment: handlers.comment || skip
+ };
+};
+
+//API
+SimpleApiParser.prototype.parse = function (html) {
+ var token = null;
+
+ this._reset(html);
+
+ do {
+ token = this.tokenizerProxy.getNextToken();
+
+ if (token.type === Tokenizer.CHARACTER_TOKEN ||
+ token.type === Tokenizer.WHITESPACE_CHARACTER_TOKEN ||
+ token.type === Tokenizer.NULL_CHARACTER_TOKEN) {
+ this.pendingText = (this.pendingText || '') + token.chars;
+ }
+
+ else {
+ this._emitPendingText();
+ this._handleToken(token);
+ }
+ } while (token.type !== Tokenizer.EOF_TOKEN)
+};
+
+//Internals
+SimpleApiParser.prototype._handleToken = function (token) {
+ if (token.type === Tokenizer.START_TAG_TOKEN)
+ this.handlers.startTag(token.tagName, token.attrs, token.selfClosing);
+
+ else if (token.type === Tokenizer.END_TAG_TOKEN)
+ this.handlers.endTag(token.tagName);
+
+ else if (token.type === Tokenizer.COMMENT_TOKEN)
+ this.handlers.comment(token.data);
+
+ else if (token.type === Tokenizer.DOCTYPE_TOKEN)
+ this.handlers.doctype(token.name, token.publicId, token.systemId);
+
+};
+
+SimpleApiParser.prototype._reset = function (html) {
+ this.tokenizerProxy = new TokenizerProxy(html);
+ this.pendingText = null;
+};
+
+SimpleApiParser.prototype._emitPendingText = function () {
+ if (this.pendingText !== null) {
+ this.handlers.text(this.pendingText);
+ this.pendingText = null;
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698