lib/action/selectItem.js
function makePossibleRangesHTML(source, tokens, offset) {
		offset = offset || 0;
		var result = [];
		var attrStart = -1, attrName = '', attrValue = '', attrValueRange, tagName;
		tokens.forEach(function(tok) {
			switch (tok.type) {
				case 'tag':
					tagName = source.substring(tok.start, tok.end);
					if (/^<[\w\:\-]/.test(tagName)) {
						// add tag name
						result.push(range({
							start: tok.start + 1, 
							end: tok.end
						}));
					}
					break;
				case 'attribute':
					attrStart = tok.start;
					attrName = source.substring(tok.start, tok.end);
					break;
					
				case 'string':
					// attribute value
					// push full attribute first
					result.push(range(attrStart, tok.end - attrStart));
					
					attrValueRange = range(tok);
					attrValue = attrValueRange.substring(source);
					
					// is this a quoted attribute?
					if (isQuote(attrValue.charAt(0)))
						attrValueRange.start++;
					
					if (isQuote(attrValue.charAt(attrValue.length - 1)))
						attrValueRange.end--;
					
					result.push(attrValueRange);
					
					if (attrName == 'class') {
						result = result.concat(classNameRanges(attrValueRange.substring(source), attrValueRange.start));
					}
					
					break;
			}
		});
		
		// offset ranges
		result = result.filter(function(item) {
			if (item.length()) {
				item.shift(offset);
				return true;
			}
		});

		// remove duplicates
		return utils.unique(result, function(item) {
			return item.toString();
		});
	}
function makePossibleRangesHTML(source, tokens, offset) {
		offset = offset || 0;
		var result = [];
		var attrStart = -1, attrName = '', attrValue = '', attrValueRange, tagName;
		tokens.forEach(function(tok) {
			switch (tok.type) {
				case 'tag':
					tagName = source.substring(tok.start, tok.end);
					if (/^<[\w\:\-]/.test(tagName)) {
						// add tag name
						result.push(range({
							start: tok.start + 1, 
							end: tok.end
						}));
					}
					break;
				case 'attribute':
					attrStart = tok.start;
					attrName = source.substring(tok.start, tok.end);
					break;
					
				case 'string':
					// attribute value
					// push full attribute first
					result.push(range(attrStart, tok.end - attrStart));
					
					attrValueRange = range(tok);
					attrValue = attrValueRange.substring(source);
					
					// is this a quoted attribute?
					if (isQuote(attrValue.charAt(0)))
						attrValueRange.start++;
					
					if (isQuote(attrValue.charAt(attrValue.length - 1)))
						attrValueRange.end--;
					
					result.push(attrValueRange);
					
					if (attrName == 'class') {
						result = result.concat(classNameRanges(attrValueRange.substring(source), attrValueRange.start));
					}
					
					break;
			}
		});
		
		// offset ranges
		result = result.filter(function(item) {
			if (item.length()) {
				item.shift(offset);
				return true;
			}
		});

		// remove duplicates
		return utils.unique(result, function(item) {
			return item.toString();
		});
	}
function makePossibleRangesHTML ( source , tokens , offset ) { offset = offset || 0 ; var result = [ ] ; var attrStart = - 1 , attrName = '' , attrValue = '' , attrValueRange , tagName ; tokens . forEach ( function ( tok ) { switch ( tok . type ) { case 'tag' : tagName = source . substring ( tok . start , tok . end ) ; if ( / ^<[\w\:\-] / . test ( tagName ) ) { // add tag name result . push ( range ( { start : tok . start + 1 , end : tok . end } ) ) ; } break ; case 'attribute' : attrStart = tok . start ; attrName = source . substring ( tok . start , tok . end ) ; break ; case 'string' : // attribute value // push full attribute first result . push ( range ( attrStart , tok . end - attrStart ) ) ; attrValueRange = range ( tok ) ; attrValue = attrValueRange . substring ( source ) ; // is this a quoted attribute? if ( isQuote ( attrValue . charAt ( 0 ) ) ) attrValueRange . start ++ ; if ( isQuote ( attrValue . charAt ( attrValue . length - 1 ) ) ) attrValueRange . end -- ; result . push ( attrValueRange ) ; if ( attrName == 'class' ) { result = result . concat ( classNameRanges ( attrValueRange . substring ( source ) , attrValueRange . start ) ) ; } break ; } } ) ; // offset ranges result = result . filter ( function ( item ) { if ( item . length ( ) ) { item . shift ( offset ) ; return true ; } } ) ; // remove duplicates return utils . unique ( result , function ( item ) { return item . toString ( ) ; } ) ; }
Creates possible selection ranges for HTML tag
@param {String} source Original HTML source for tokens
@param {Array} tokens List of HTML tokens
@returns {Array}
Creates possible selection ranges for HTML tag