123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- 'use strict';
- function Token(type, tag, nesting) {
-
- this.type = type;
-
- this.tag = tag;
-
- this.attrs = null;
-
- this.map = null;
-
- this.nesting = nesting;
-
- this.level = 0;
-
- this.children = null;
-
- this.content = '';
-
- this.markup = '';
-
- this.info = '';
-
- this.meta = null;
-
- this.block = false;
-
- this.hidden = false;
- }
- Token.prototype.attrIndex = function attrIndex(name) {
- var attrs, i, len;
- if (!this.attrs) { return -1; }
- attrs = this.attrs;
- for (i = 0, len = attrs.length; i < len; i++) {
- if (attrs[i][0] === name) { return i; }
- }
- return -1;
- };
- Token.prototype.attrPush = function attrPush(attrData) {
- if (this.attrs) {
- this.attrs.push(attrData);
- } else {
- this.attrs = [ attrData ];
- }
- };
- Token.prototype.attrSet = function attrSet(name, value) {
- var idx = this.attrIndex(name),
- attrData = [ name, value ];
- if (idx < 0) {
- this.attrPush(attrData);
- } else {
- this.attrs[idx] = attrData;
- }
- };
- Token.prototype.attrGet = function attrGet(name) {
- var idx = this.attrIndex(name), value = null;
- if (idx >= 0) {
- value = this.attrs[idx][1];
- }
- return value;
- };
- Token.prototype.attrJoin = function attrJoin(name, value) {
- var idx = this.attrIndex(name);
- if (idx < 0) {
- this.attrPush([ name, value ]);
- } else {
- this.attrs[idx][1] = this.attrs[idx][1] + ' ' + value;
- }
- };
- module.exports = Token;
|