id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
11,200
emmetio/emmet
lib/utils/cssSections.js
function(content, pos, sanitize) { if (sanitize) { content = this.sanitize(content); } var stream = stringStream(content); stream.start = stream.pos = pos; var stack = [], ranges = []; var ch; while (ch = stream.next()) { if (ch == '{') { stack.push(stream.pos - 1); } else if (ch == '}') { if (!stack.length) { throw 'Invalid source structure (check for curly braces)'; } ranges.push(range.create2(stack.pop(), stream.pos)); if (!stack.length) { return ranges; } } else { stream.skipQuoted(); } } return ranges; }
javascript
function(content, pos, sanitize) { if (sanitize) { content = this.sanitize(content); } var stream = stringStream(content); stream.start = stream.pos = pos; var stack = [], ranges = []; var ch; while (ch = stream.next()) { if (ch == '{') { stack.push(stream.pos - 1); } else if (ch == '}') { if (!stack.length) { throw 'Invalid source structure (check for curly braces)'; } ranges.push(range.create2(stack.pop(), stream.pos)); if (!stack.length) { return ranges; } } else { stream.skipQuoted(); } } return ranges; }
[ "function", "(", "content", ",", "pos", ",", "sanitize", ")", "{", "if", "(", "sanitize", ")", "{", "content", "=", "this", ".", "sanitize", "(", "content", ")", ";", "}", "var", "stream", "=", "stringStream", "(", "content", ")", ";", "stream", ".", "start", "=", "stream", ".", "pos", "=", "pos", ";", "var", "stack", "=", "[", "]", ",", "ranges", "=", "[", "]", ";", "var", "ch", ";", "while", "(", "ch", "=", "stream", ".", "next", "(", ")", ")", "{", "if", "(", "ch", "==", "'{'", ")", "{", "stack", ".", "push", "(", "stream", ".", "pos", "-", "1", ")", ";", "}", "else", "if", "(", "ch", "==", "'}'", ")", "{", "if", "(", "!", "stack", ".", "length", ")", "{", "throw", "'Invalid source structure (check for curly braces)'", ";", "}", "ranges", ".", "push", "(", "range", ".", "create2", "(", "stack", ".", "pop", "(", ")", ",", "stream", ".", "pos", ")", ")", ";", "if", "(", "!", "stack", ".", "length", ")", "{", "return", "ranges", ";", "}", "}", "else", "{", "stream", ".", "skipQuoted", "(", ")", ";", "}", "}", "return", "ranges", ";", "}" ]
Matches curly braces content right after given position @param {String} content CSS content. Must not contain comments! @param {Number} pos Search start position @return {Range}
[ "Matches", "curly", "braces", "content", "right", "after", "given", "position" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/cssSections.js#L268-L294
11,201
emmetio/emmet
lib/utils/cssSections.js
function(content, pos, sanitize) { if (sanitize) { content = this.sanitize(content); } var skipString = function() { var quote = content.charAt(pos); if (quote == '"' || quote == "'") { while (--pos >= 0) { if (content.charAt(pos) == quote && content.charAt(pos - 1) != '\\') { break; } } return true; } return false; }; // find CSS selector var ch; var endPos = pos; while (--pos >= 0) { if (skipString()) continue; ch = content.charAt(pos); if (ch == ')') { // looks like it’s a preprocessor thing, // most likely a mixin arguments list, e.g. // .mixin (@arg1; @arg2) {...} while (--pos >= 0) { if (skipString()) continue; if (content.charAt(pos) == '(') { break; } } continue; } if (ch == '{' || ch == '}' || ch == ';') { pos++; break; } } if (pos < 0) { pos = 0; } var selector = content.substring(pos, endPos); // trim whitespace from matched selector var m = selector.replace(reSpace, ' ').match(reSpaceTrim); if (m) { pos += m[1].length; endPos -= m[2].length; } return range.create2(pos, endPos); }
javascript
function(content, pos, sanitize) { if (sanitize) { content = this.sanitize(content); } var skipString = function() { var quote = content.charAt(pos); if (quote == '"' || quote == "'") { while (--pos >= 0) { if (content.charAt(pos) == quote && content.charAt(pos - 1) != '\\') { break; } } return true; } return false; }; // find CSS selector var ch; var endPos = pos; while (--pos >= 0) { if (skipString()) continue; ch = content.charAt(pos); if (ch == ')') { // looks like it’s a preprocessor thing, // most likely a mixin arguments list, e.g. // .mixin (@arg1; @arg2) {...} while (--pos >= 0) { if (skipString()) continue; if (content.charAt(pos) == '(') { break; } } continue; } if (ch == '{' || ch == '}' || ch == ';') { pos++; break; } } if (pos < 0) { pos = 0; } var selector = content.substring(pos, endPos); // trim whitespace from matched selector var m = selector.replace(reSpace, ' ').match(reSpaceTrim); if (m) { pos += m[1].length; endPos -= m[2].length; } return range.create2(pos, endPos); }
[ "function", "(", "content", ",", "pos", ",", "sanitize", ")", "{", "if", "(", "sanitize", ")", "{", "content", "=", "this", ".", "sanitize", "(", "content", ")", ";", "}", "var", "skipString", "=", "function", "(", ")", "{", "var", "quote", "=", "content", ".", "charAt", "(", "pos", ")", ";", "if", "(", "quote", "==", "'\"'", "||", "quote", "==", "\"'\"", ")", "{", "while", "(", "--", "pos", ">=", "0", ")", "{", "if", "(", "content", ".", "charAt", "(", "pos", ")", "==", "quote", "&&", "content", ".", "charAt", "(", "pos", "-", "1", ")", "!=", "'\\\\'", ")", "{", "break", ";", "}", "}", "return", "true", ";", "}", "return", "false", ";", "}", ";", "// find CSS selector", "var", "ch", ";", "var", "endPos", "=", "pos", ";", "while", "(", "--", "pos", ">=", "0", ")", "{", "if", "(", "skipString", "(", ")", ")", "continue", ";", "ch", "=", "content", ".", "charAt", "(", "pos", ")", ";", "if", "(", "ch", "==", "')'", ")", "{", "// looks like it’s a preprocessor thing,", "// most likely a mixin arguments list, e.g.", "// .mixin (@arg1; @arg2) {...}", "while", "(", "--", "pos", ">=", "0", ")", "{", "if", "(", "skipString", "(", ")", ")", "continue", ";", "if", "(", "content", ".", "charAt", "(", "pos", ")", "==", "'('", ")", "{", "break", ";", "}", "}", "continue", ";", "}", "if", "(", "ch", "==", "'{'", "||", "ch", "==", "'}'", "||", "ch", "==", "';'", ")", "{", "pos", "++", ";", "break", ";", "}", "}", "if", "(", "pos", "<", "0", ")", "{", "pos", "=", "0", ";", "}", "var", "selector", "=", "content", ".", "substring", "(", "pos", ",", "endPos", ")", ";", "// trim whitespace from matched selector", "var", "m", "=", "selector", ".", "replace", "(", "reSpace", ",", "' '", ")", ".", "match", "(", "reSpaceTrim", ")", ";", "if", "(", "m", ")", "{", "pos", "+=", "m", "[", "1", "]", ".", "length", ";", "endPos", "-=", "m", "[", "2", "]", ".", "length", ";", "}", "return", "range", ".", "create2", "(", "pos", ",", "endPos", ")", ";", "}" ]
Extracts CSS selector from CSS document from given position. The selector is located by moving backward from given position which means that passed position must point to the end of selector @param {String} content CSS source @param {Number} pos Search position @param {Boolean} sanitize Sanitize CSS source before processing. Off by default and assumes that CSS must be comment-free already (for performance) @return {Range}
[ "Extracts", "CSS", "selector", "from", "CSS", "document", "from", "given", "position", ".", "The", "selector", "is", "located", "by", "moving", "backward", "from", "given", "position", "which", "means", "that", "passed", "position", "must", "point", "to", "the", "end", "of", "selector" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/cssSections.js#L308-L368
11,202
emmetio/emmet
lib/utils/cssSections.js
function(content, pos, isBackward) { // possible case: editor reported that current syntax is // CSS, but it’s actually a HTML document (either `style` tag or attribute) var offset = 0; var subrange = this.styleTagRange(content, pos); if (subrange) { offset = subrange.start; pos -= subrange.start; content = subrange.substring(content); } var rules = this.findAllRules(content); var ctxRule = this.matchEnclosingRule(rules, pos); if (ctxRule) { return ctxRule.shift(offset); } for (var i = 0, il = rules.length; i < il; i++) { if (rules[i].start > pos) { return rules[isBackward && i > 0 ? i - 1 : i].shift(offset); } } }
javascript
function(content, pos, isBackward) { // possible case: editor reported that current syntax is // CSS, but it’s actually a HTML document (either `style` tag or attribute) var offset = 0; var subrange = this.styleTagRange(content, pos); if (subrange) { offset = subrange.start; pos -= subrange.start; content = subrange.substring(content); } var rules = this.findAllRules(content); var ctxRule = this.matchEnclosingRule(rules, pos); if (ctxRule) { return ctxRule.shift(offset); } for (var i = 0, il = rules.length; i < il; i++) { if (rules[i].start > pos) { return rules[isBackward && i > 0 ? i - 1 : i].shift(offset); } } }
[ "function", "(", "content", ",", "pos", ",", "isBackward", ")", "{", "// possible case: editor reported that current syntax is", "// CSS, but it’s actually a HTML document (either `style` tag or attribute)", "var", "offset", "=", "0", ";", "var", "subrange", "=", "this", ".", "styleTagRange", "(", "content", ",", "pos", ")", ";", "if", "(", "subrange", ")", "{", "offset", "=", "subrange", ".", "start", ";", "pos", "-=", "subrange", ".", "start", ";", "content", "=", "subrange", ".", "substring", "(", "content", ")", ";", "}", "var", "rules", "=", "this", ".", "findAllRules", "(", "content", ")", ";", "var", "ctxRule", "=", "this", ".", "matchEnclosingRule", "(", "rules", ",", "pos", ")", ";", "if", "(", "ctxRule", ")", "{", "return", "ctxRule", ".", "shift", "(", "offset", ")", ";", "}", "for", "(", "var", "i", "=", "0", ",", "il", "=", "rules", ".", "length", ";", "i", "<", "il", ";", "i", "++", ")", "{", "if", "(", "rules", "[", "i", "]", ".", "start", ">", "pos", ")", "{", "return", "rules", "[", "isBackward", "&&", "i", ">", "0", "?", "i", "-", "1", ":", "i", "]", ".", "shift", "(", "offset", ")", ";", "}", "}", "}" ]
Locates CSS rule next or before given position @param {String} content CSS content @param {Number} pos Search start position @param {Boolean} isBackward Search backward (find previous rule insteaf of next one) @return {Range}
[ "Locates", "CSS", "rule", "next", "or", "before", "given", "position" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/cssSections.js#L396-L419
11,203
emmetio/emmet
lib/utils/cssSections.js
function(range, ctx) { while (ctx && ctx.range) { if (ctx.range.contains(range)) { return ctx.addChild(range); } ctx = ctx.parent; } // if we are here then given range is a top-level section return root.addChild(range); }
javascript
function(range, ctx) { while (ctx && ctx.range) { if (ctx.range.contains(range)) { return ctx.addChild(range); } ctx = ctx.parent; } // if we are here then given range is a top-level section return root.addChild(range); }
[ "function", "(", "range", ",", "ctx", ")", "{", "while", "(", "ctx", "&&", "ctx", ".", "range", ")", "{", "if", "(", "ctx", ".", "range", ".", "contains", "(", "range", ")", ")", "{", "return", "ctx", ".", "addChild", "(", "range", ")", ";", "}", "ctx", "=", "ctx", ".", "parent", ";", "}", "// if we are here then given range is a top-level section", "return", "root", ".", "addChild", "(", "range", ")", ";", "}" ]
rules are sorted in order they appear in CSS source so we can optimize their nesting routine
[ "rules", "are", "sorted", "in", "order", "they", "appear", "in", "CSS", "source", "so", "we", "can", "optimize", "their", "nesting", "routine" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/cssSections.js#L474-L485
11,204
emmetio/emmet
lib/utils/cssSections.js
function(rule) { var offset = rule.valueRange(true).start; var nestedSections = this.findAllRules(rule.valueRange().substring(rule.source)); nestedSections.forEach(function(section) { section.start += offset; section.end += offset; section._selectorEnd += offset; section._contentStart += offset; }); return nestedSections; }
javascript
function(rule) { var offset = rule.valueRange(true).start; var nestedSections = this.findAllRules(rule.valueRange().substring(rule.source)); nestedSections.forEach(function(section) { section.start += offset; section.end += offset; section._selectorEnd += offset; section._contentStart += offset; }); return nestedSections; }
[ "function", "(", "rule", ")", "{", "var", "offset", "=", "rule", ".", "valueRange", "(", "true", ")", ".", "start", ";", "var", "nestedSections", "=", "this", ".", "findAllRules", "(", "rule", ".", "valueRange", "(", ")", ".", "substring", "(", "rule", ".", "source", ")", ")", ";", "nestedSections", ".", "forEach", "(", "function", "(", "section", ")", "{", "section", ".", "start", "+=", "offset", ";", "section", ".", "end", "+=", "offset", ";", "section", ".", "_selectorEnd", "+=", "offset", ";", "section", ".", "_contentStart", "+=", "offset", ";", "}", ")", ";", "return", "nestedSections", ";", "}" ]
Returns ranges for all nested sections, available in given CSS rule @param {CSSEditContainer} rule @return {Array}
[ "Returns", "ranges", "for", "all", "nested", "sections", "available", "in", "given", "CSS", "rule" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/cssSections.js#L501-L511
11,205
emmetio/emmet
lib/assets/elements.js
function(name, factory) { var that = this; factories[name] = function() { var elem = factory.apply(that, arguments); if (elem) elem.type = name; return elem; }; }
javascript
function(name, factory) { var that = this; factories[name] = function() { var elem = factory.apply(that, arguments); if (elem) elem.type = name; return elem; }; }
[ "function", "(", "name", ",", "factory", ")", "{", "var", "that", "=", "this", ";", "factories", "[", "name", "]", "=", "function", "(", ")", "{", "var", "elem", "=", "factory", ".", "apply", "(", "that", ",", "arguments", ")", ";", "if", "(", "elem", ")", "elem", ".", "type", "=", "name", ";", "return", "elem", ";", "}", ";", "}" ]
Create new element factory @param {String} name Element identifier @param {Function} factory Function that produces element of specified type. The object generated by this factory is automatically augmented with <code>type</code> property pointing to element <code>name</code> @memberOf elements
[ "Create", "new", "element", "factory" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/elements.js#L30-L39
11,206
emmetio/emmet
lib/assets/elements.js
function(name) { var args = [].slice.call(arguments, 1); var factory = this.get(name); return factory ? factory.apply(this, args) : null; }
javascript
function(name) { var args = [].slice.call(arguments, 1); var factory = this.get(name); return factory ? factory.apply(this, args) : null; }
[ "function", "(", "name", ")", "{", "var", "args", "=", "[", "]", ".", "slice", ".", "call", "(", "arguments", ",", "1", ")", ";", "var", "factory", "=", "this", ".", "get", "(", "name", ")", ";", "return", "factory", "?", "factory", ".", "apply", "(", "this", ",", "args", ")", ":", "null", ";", "}" ]
Creates new element with specified type @param {String} name @returns {Object}
[ "Creates", "new", "element", "with", "specified", "type" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/elements.js#L55-L59
11,207
emmetio/emmet
lib/assets/preferences.js
function(name, value, description) { var prefs = name; if (typeof name === 'string') { prefs = {}; prefs[name] = { value: value, description: description }; } Object.keys(prefs).forEach(function(k) { var v = prefs[k]; defaults[k] = isValueObj(v) ? v : {value: v}; }); }
javascript
function(name, value, description) { var prefs = name; if (typeof name === 'string') { prefs = {}; prefs[name] = { value: value, description: description }; } Object.keys(prefs).forEach(function(k) { var v = prefs[k]; defaults[k] = isValueObj(v) ? v : {value: v}; }); }
[ "function", "(", "name", ",", "value", ",", "description", ")", "{", "var", "prefs", "=", "name", ";", "if", "(", "typeof", "name", "===", "'string'", ")", "{", "prefs", "=", "{", "}", ";", "prefs", "[", "name", "]", "=", "{", "value", ":", "value", ",", "description", ":", "description", "}", ";", "}", "Object", ".", "keys", "(", "prefs", ")", ".", "forEach", "(", "function", "(", "k", ")", "{", "var", "v", "=", "prefs", "[", "k", "]", ";", "defaults", "[", "k", "]", "=", "isValueObj", "(", "v", ")", "?", "v", ":", "{", "value", ":", "v", "}", ";", "}", ")", ";", "}" ]
Creates new preference item with default value @param {String} name Preference name. You can also pass object with many options @param {Object} value Preference default value @param {String} description Item textual description @memberOf preferences
[ "Creates", "new", "preference", "item", "with", "default", "value" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/preferences.js#L48-L62
11,208
emmetio/emmet
lib/assets/preferences.js
function(name) { var val = this.get(name); if (typeof val === 'undefined' || val === null || val === '') { return null; } val = val.split(',').map(utils.trim); if (!val.length) { return null; } return val; }
javascript
function(name) { var val = this.get(name); if (typeof val === 'undefined' || val === null || val === '') { return null; } val = val.split(',').map(utils.trim); if (!val.length) { return null; } return val; }
[ "function", "(", "name", ")", "{", "var", "val", "=", "this", ".", "get", "(", "name", ")", ";", "if", "(", "typeof", "val", "===", "'undefined'", "||", "val", "===", "null", "||", "val", "===", "''", ")", "{", "return", "null", ";", "}", "val", "=", "val", ".", "split", "(", "','", ")", ".", "map", "(", "utils", ".", "trim", ")", ";", "if", "(", "!", "val", ".", "length", ")", "{", "return", "null", ";", "}", "return", "val", ";", "}" ]
Returns comma-separated preference value as array of values @param {String} name @returns {Array} Returns <code>undefined</code> if preference is not defined, <code>null</code> if string cannot be converted to array
[ "Returns", "comma", "-", "separated", "preference", "value", "as", "array", "of", "values" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/preferences.js#L132-L144
11,209
emmetio/emmet
lib/assets/preferences.js
function(name) { var result = {}; this.getArray(name).forEach(function(val) { var parts = val.split(':'); result[parts[0]] = parts[1]; }); return result; }
javascript
function(name) { var result = {}; this.getArray(name).forEach(function(val) { var parts = val.split(':'); result[parts[0]] = parts[1]; }); return result; }
[ "function", "(", "name", ")", "{", "var", "result", "=", "{", "}", ";", "this", ".", "getArray", "(", "name", ")", ".", "forEach", "(", "function", "(", "val", ")", "{", "var", "parts", "=", "val", ".", "split", "(", "':'", ")", ";", "result", "[", "parts", "[", "0", "]", "]", "=", "parts", "[", "1", "]", ";", "}", ")", ";", "return", "result", ";", "}" ]
Returns comma and colon-separated preference value as dictionary @param {String} name @returns {Object}
[ "Returns", "comma", "and", "colon", "-", "separated", "preference", "value", "as", "dictionary" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/preferences.js#L151-L159
11,210
emmetio/emmet
lib/assets/preferences.js
function() { return Object.keys(defaults).sort().map(function(key) { return { name: key, value: this.get(key), type: typeof defaults[key].value, description: defaults[key].description }; }, this); }
javascript
function() { return Object.keys(defaults).sort().map(function(key) { return { name: key, value: this.get(key), type: typeof defaults[key].value, description: defaults[key].description }; }, this); }
[ "function", "(", ")", "{", "return", "Object", ".", "keys", "(", "defaults", ")", ".", "sort", "(", ")", ".", "map", "(", "function", "(", "key", ")", "{", "return", "{", "name", ":", "key", ",", "value", ":", "this", ".", "get", "(", "key", ")", ",", "type", ":", "typeof", "defaults", "[", "key", "]", ".", "value", ",", "description", ":", "defaults", "[", "key", "]", ".", "description", "}", ";", "}", ",", "this", ")", ";", "}" ]
Returns sorted list of all available properties @returns {Array}
[ "Returns", "sorted", "list", "of", "all", "available", "properties" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/preferences.js#L194-L203
11,211
emmetio/emmet
lib/assets/preferences.js
function(json) { Object.keys(json).forEach(function(key) { this.set(key, json[key]); }, this); }
javascript
function(json) { Object.keys(json).forEach(function(key) { this.set(key, json[key]); }, this); }
[ "function", "(", "json", ")", "{", "Object", ".", "keys", "(", "json", ")", ".", "forEach", "(", "function", "(", "key", ")", "{", "this", ".", "set", "(", "key", ",", "json", "[", "key", "]", ")", ";", "}", ",", "this", ")", ";", "}" ]
Loads user-defined preferences from JSON @param {Object} json @returns
[ "Loads", "user", "-", "defined", "preferences", "from", "JSON" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/preferences.js#L210-L214
11,212
emmetio/emmet
lib/parser/processor/pastedContent.js
insertPastedContent
function insertPastedContent(node, content, overwrite) { var nodesWithPlaceholders = node.findAll(function(item) { return hasOutputPlaceholder(item); }); if (hasOutputPlaceholder(node)) nodesWithPlaceholders.unshift(node); if (nodesWithPlaceholders.length) { nodesWithPlaceholders.forEach(function(item) { item.content = replaceOutputPlaceholders(item.content, content); item._attributes.forEach(function(attr) { attr.value = replaceOutputPlaceholders(attr.value, content); }); }); } else { // on output placeholders in subtree, insert content in the deepest // child node var deepest = node.deepestChild() || node; if (overwrite) { deepest.content = content; } else { deepest.content = abbrUtils.insertChildContent(deepest.content, content); } } }
javascript
function insertPastedContent(node, content, overwrite) { var nodesWithPlaceholders = node.findAll(function(item) { return hasOutputPlaceholder(item); }); if (hasOutputPlaceholder(node)) nodesWithPlaceholders.unshift(node); if (nodesWithPlaceholders.length) { nodesWithPlaceholders.forEach(function(item) { item.content = replaceOutputPlaceholders(item.content, content); item._attributes.forEach(function(attr) { attr.value = replaceOutputPlaceholders(attr.value, content); }); }); } else { // on output placeholders in subtree, insert content in the deepest // child node var deepest = node.deepestChild() || node; if (overwrite) { deepest.content = content; } else { deepest.content = abbrUtils.insertChildContent(deepest.content, content); } } }
[ "function", "insertPastedContent", "(", "node", ",", "content", ",", "overwrite", ")", "{", "var", "nodesWithPlaceholders", "=", "node", ".", "findAll", "(", "function", "(", "item", ")", "{", "return", "hasOutputPlaceholder", "(", "item", ")", ";", "}", ")", ";", "if", "(", "hasOutputPlaceholder", "(", "node", ")", ")", "nodesWithPlaceholders", ".", "unshift", "(", "node", ")", ";", "if", "(", "nodesWithPlaceholders", ".", "length", ")", "{", "nodesWithPlaceholders", ".", "forEach", "(", "function", "(", "item", ")", "{", "item", ".", "content", "=", "replaceOutputPlaceholders", "(", "item", ".", "content", ",", "content", ")", ";", "item", ".", "_attributes", ".", "forEach", "(", "function", "(", "attr", ")", "{", "attr", ".", "value", "=", "replaceOutputPlaceholders", "(", "attr", ".", "value", ",", "content", ")", ";", "}", ")", ";", "}", ")", ";", "}", "else", "{", "// on output placeholders in subtree, insert content in the deepest", "// child node", "var", "deepest", "=", "node", ".", "deepestChild", "(", ")", "||", "node", ";", "if", "(", "overwrite", ")", "{", "deepest", ".", "content", "=", "content", ";", "}", "else", "{", "deepest", ".", "content", "=", "abbrUtils", ".", "insertChildContent", "(", "deepest", ".", "content", ",", "content", ")", ";", "}", "}", "}" ]
Insert pasted content into correct positions of parsed node @param {AbbreviationNode} node @param {String} content @param {Boolean} overwrite Overwrite node content if no value placeholders found instead of appending to existing content
[ "Insert", "pasted", "content", "into", "correct", "positions", "of", "parsed", "node" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/processor/pastedContent.js#L86-L111
11,213
emmetio/emmet
lib/filter/format.js
shouldAddLineBreak
function shouldAddLineBreak(node, profile) { if (profile.tag_nl === true || abbrUtils.isBlock(node)) return true; if (!node.parent || !profile.inline_break) return false; // check if there are required amount of adjacent inline element return shouldFormatInline(node.parent, profile); }
javascript
function shouldAddLineBreak(node, profile) { if (profile.tag_nl === true || abbrUtils.isBlock(node)) return true; if (!node.parent || !profile.inline_break) return false; // check if there are required amount of adjacent inline element return shouldFormatInline(node.parent, profile); }
[ "function", "shouldAddLineBreak", "(", "node", ",", "profile", ")", "{", "if", "(", "profile", ".", "tag_nl", "===", "true", "||", "abbrUtils", ".", "isBlock", "(", "node", ")", ")", "return", "true", ";", "if", "(", "!", "node", ".", "parent", "||", "!", "profile", ".", "inline_break", ")", "return", "false", ";", "// check if there are required amount of adjacent inline element", "return", "shouldFormatInline", "(", "node", ".", "parent", ",", "profile", ")", ";", "}" ]
Check if a newline should be added before element @param {AbbreviationNode} node @param {OutputProfile} profile @return {Boolean}
[ "Check", "if", "a", "newline", "should", "be", "added", "before", "element" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/filter/format.js#L65-L74
11,214
emmetio/emmet
lib/filter/format.js
shouldBreakInsideInline
function shouldBreakInsideInline(node, profile) { var hasBlockElems = node.children.some(function(child) { if (abbrUtils.isSnippet(child)) return false; return !abbrUtils.isInline(child); }); if (!hasBlockElems) { return shouldFormatInline(node, profile); } return true; }
javascript
function shouldBreakInsideInline(node, profile) { var hasBlockElems = node.children.some(function(child) { if (abbrUtils.isSnippet(child)) return false; return !abbrUtils.isInline(child); }); if (!hasBlockElems) { return shouldFormatInline(node, profile); } return true; }
[ "function", "shouldBreakInsideInline", "(", "node", ",", "profile", ")", "{", "var", "hasBlockElems", "=", "node", ".", "children", ".", "some", "(", "function", "(", "child", ")", "{", "if", "(", "abbrUtils", ".", "isSnippet", "(", "child", ")", ")", "return", "false", ";", "return", "!", "abbrUtils", ".", "isInline", "(", "child", ")", ";", "}", ")", ";", "if", "(", "!", "hasBlockElems", ")", "{", "return", "shouldFormatInline", "(", "node", ",", "profile", ")", ";", "}", "return", "true", ";", "}" ]
Check if we should add line breaks inside inline element @param {AbbreviationNode} node @param {OutputProfile} profile @return {Boolean}
[ "Check", "if", "we", "should", "add", "line", "breaks", "inside", "inline", "element" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/filter/format.js#L127-L140
11,215
emmetio/emmet
lib/action/incrementDecrement.js
intLength
function intLength(num) { num = num.replace(/^\-/, ''); if (~num.indexOf('.')) { return num.split('.')[0].length; } return num.length; }
javascript
function intLength(num) { num = num.replace(/^\-/, ''); if (~num.indexOf('.')) { return num.split('.')[0].length; } return num.length; }
[ "function", "intLength", "(", "num", ")", "{", "num", "=", "num", ".", "replace", "(", "/", "^\\-", "/", ",", "''", ")", ";", "if", "(", "~", "num", ".", "indexOf", "(", "'.'", ")", ")", "{", "return", "num", ".", "split", "(", "'.'", ")", "[", "0", "]", ".", "length", ";", "}", "return", "num", ".", "length", ";", "}" ]
Returns length of integer part of number @param {String} num
[ "Returns", "length", "of", "integer", "part", "of", "number" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/incrementDecrement.js#L18-L25
11,216
emmetio/emmet
lib/editTree/css.js
consumeSingleProperty
function consumeSingleProperty(it, text) { var name, value, end; var token = it.current(); if (!token) { return null; } // skip whitespace var ws = {'white': 1, 'line': 1, 'comment': 1}; while ((token = it.current())) { if (!(token.type in ws)) { break; } it.next(); } if (!it.hasNext()) { return null; } // consume property name token = it.current(); name = range(token.start, token.value); var isAtProperty = token.value.charAt(0) == '@'; while (token = it.next()) { name.end = token.end; if (token.type == ':' || token.type == 'white') { name.end = token.start; it.next(); if (token.type == ':' || isAtProperty) { // XXX I really ashame of this hardcode, but I need // to stop parsing if this is an SCSS mixin call, // for example: @include border-radius(10px) break; } } else if (token.type == ';' || token.type == 'line') { // there’s no value, looks like a mixin // or a special use case: // user is writing a new property or abbreviation name.end = token.start; value = range(token.start, 0); it.next(); break; } } token = it.current(); if (!value && token) { if (token.type == 'line') { lastNewline = token; } // consume value value = range(token.start, token.value); var lastNewline; while ((token = it.next())) { value.end = token.end; if (token.type == 'line') { lastNewline = token; } else if (token.type == '}' || token.type == ';') { value.end = token.start; if (token.type == ';') { end = range(token.start, token.value); } it.next(); break; } else if (token.type == ':' && lastNewline) { // A special case: // user is writing a value before existing // property, but didn’t inserted closing semi-colon. // In this case, limit value range to previous // newline value.end = lastNewline.start; it._i = it.tokens.indexOf(lastNewline); break; } } } if (!value) { value = range(name.end, 0); } return { name: trimWhitespaceInRange(name, text), value: trimWhitespaceInRange(value, text, WHITESPACE_REMOVE_FROM_START | (end ? WHITESPACE_REMOVE_FROM_END : 0)), end: end || range(value.end, 0) }; }
javascript
function consumeSingleProperty(it, text) { var name, value, end; var token = it.current(); if (!token) { return null; } // skip whitespace var ws = {'white': 1, 'line': 1, 'comment': 1}; while ((token = it.current())) { if (!(token.type in ws)) { break; } it.next(); } if (!it.hasNext()) { return null; } // consume property name token = it.current(); name = range(token.start, token.value); var isAtProperty = token.value.charAt(0) == '@'; while (token = it.next()) { name.end = token.end; if (token.type == ':' || token.type == 'white') { name.end = token.start; it.next(); if (token.type == ':' || isAtProperty) { // XXX I really ashame of this hardcode, but I need // to stop parsing if this is an SCSS mixin call, // for example: @include border-radius(10px) break; } } else if (token.type == ';' || token.type == 'line') { // there’s no value, looks like a mixin // or a special use case: // user is writing a new property or abbreviation name.end = token.start; value = range(token.start, 0); it.next(); break; } } token = it.current(); if (!value && token) { if (token.type == 'line') { lastNewline = token; } // consume value value = range(token.start, token.value); var lastNewline; while ((token = it.next())) { value.end = token.end; if (token.type == 'line') { lastNewline = token; } else if (token.type == '}' || token.type == ';') { value.end = token.start; if (token.type == ';') { end = range(token.start, token.value); } it.next(); break; } else if (token.type == ':' && lastNewline) { // A special case: // user is writing a value before existing // property, but didn’t inserted closing semi-colon. // In this case, limit value range to previous // newline value.end = lastNewline.start; it._i = it.tokens.indexOf(lastNewline); break; } } } if (!value) { value = range(name.end, 0); } return { name: trimWhitespaceInRange(name, text), value: trimWhitespaceInRange(value, text, WHITESPACE_REMOVE_FROM_START | (end ? WHITESPACE_REMOVE_FROM_END : 0)), end: end || range(value.end, 0) }; }
[ "function", "consumeSingleProperty", "(", "it", ",", "text", ")", "{", "var", "name", ",", "value", ",", "end", ";", "var", "token", "=", "it", ".", "current", "(", ")", ";", "if", "(", "!", "token", ")", "{", "return", "null", ";", "}", "// skip whitespace", "var", "ws", "=", "{", "'white'", ":", "1", ",", "'line'", ":", "1", ",", "'comment'", ":", "1", "}", ";", "while", "(", "(", "token", "=", "it", ".", "current", "(", ")", ")", ")", "{", "if", "(", "!", "(", "token", ".", "type", "in", "ws", ")", ")", "{", "break", ";", "}", "it", ".", "next", "(", ")", ";", "}", "if", "(", "!", "it", ".", "hasNext", "(", ")", ")", "{", "return", "null", ";", "}", "// consume property name", "token", "=", "it", ".", "current", "(", ")", ";", "name", "=", "range", "(", "token", ".", "start", ",", "token", ".", "value", ")", ";", "var", "isAtProperty", "=", "token", ".", "value", ".", "charAt", "(", "0", ")", "==", "'@'", ";", "while", "(", "token", "=", "it", ".", "next", "(", ")", ")", "{", "name", ".", "end", "=", "token", ".", "end", ";", "if", "(", "token", ".", "type", "==", "':'", "||", "token", ".", "type", "==", "'white'", ")", "{", "name", ".", "end", "=", "token", ".", "start", ";", "it", ".", "next", "(", ")", ";", "if", "(", "token", ".", "type", "==", "':'", "||", "isAtProperty", ")", "{", "// XXX I really ashame of this hardcode, but I need", "// to stop parsing if this is an SCSS mixin call,", "// for example: @include border-radius(10px)", "break", ";", "}", "}", "else", "if", "(", "token", ".", "type", "==", "';'", "||", "token", ".", "type", "==", "'line'", ")", "{", "// there’s no value, looks like a mixin", "// or a special use case:", "// user is writing a new property or abbreviation", "name", ".", "end", "=", "token", ".", "start", ";", "value", "=", "range", "(", "token", ".", "start", ",", "0", ")", ";", "it", ".", "next", "(", ")", ";", "break", ";", "}", "}", "token", "=", "it", ".", "current", "(", ")", ";", "if", "(", "!", "value", "&&", "token", ")", "{", "if", "(", "token", ".", "type", "==", "'line'", ")", "{", "lastNewline", "=", "token", ";", "}", "// consume value", "value", "=", "range", "(", "token", ".", "start", ",", "token", ".", "value", ")", ";", "var", "lastNewline", ";", "while", "(", "(", "token", "=", "it", ".", "next", "(", ")", ")", ")", "{", "value", ".", "end", "=", "token", ".", "end", ";", "if", "(", "token", ".", "type", "==", "'line'", ")", "{", "lastNewline", "=", "token", ";", "}", "else", "if", "(", "token", ".", "type", "==", "'}'", "||", "token", ".", "type", "==", "';'", ")", "{", "value", ".", "end", "=", "token", ".", "start", ";", "if", "(", "token", ".", "type", "==", "';'", ")", "{", "end", "=", "range", "(", "token", ".", "start", ",", "token", ".", "value", ")", ";", "}", "it", ".", "next", "(", ")", ";", "break", ";", "}", "else", "if", "(", "token", ".", "type", "==", "':'", "&&", "lastNewline", ")", "{", "// A special case: ", "// user is writing a value before existing", "// property, but didn’t inserted closing semi-colon.", "// In this case, limit value range to previous", "// newline", "value", ".", "end", "=", "lastNewline", ".", "start", ";", "it", ".", "_i", "=", "it", ".", "tokens", ".", "indexOf", "(", "lastNewline", ")", ";", "break", ";", "}", "}", "}", "if", "(", "!", "value", ")", "{", "value", "=", "range", "(", "name", ".", "end", ",", "0", ")", ";", "}", "return", "{", "name", ":", "trimWhitespaceInRange", "(", "name", ",", "text", ")", ",", "value", ":", "trimWhitespaceInRange", "(", "value", ",", "text", ",", "WHITESPACE_REMOVE_FROM_START", "|", "(", "end", "?", "WHITESPACE_REMOVE_FROM_END", ":", "0", ")", ")", ",", "end", ":", "end", "||", "range", "(", "value", ".", "end", ",", "0", ")", "}", ";", "}" ]
Consumes CSS property and value from current token iterator state. Offsets iterator pointer into token that can be used for next value consmption @param {TokenIterator} it @param {String} text @return {Object} Object with `name` and `value` properties ar ranges. Value range can be zero-length.
[ "Consumes", "CSS", "property", "and", "value", "from", "current", "token", "iterator", "state", ".", "Offsets", "iterator", "pointer", "into", "token", "that", "can", "be", "used", "for", "next", "value", "consmption" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L70-L158
11,217
emmetio/emmet
lib/editTree/css.js
findParts
function findParts(str) { /** @type StringStream */ var stream = stringStream.create(str); var ch; var result = []; var sep = /[\s\u00a0,;]/; var add = function() { stream.next(); result.push(range(stream.start, stream.current())); stream.start = stream.pos; }; // skip whitespace stream.eatSpace(); stream.start = stream.pos; while ((ch = stream.next())) { if (ch == '"' || ch == "'") { stream.next(); if (!stream.skipTo(ch)) break; add(); } else if (ch == '(') { // function found, may have nested function stream.backUp(1); if (!stream.skipToPair('(', ')')) break; stream.backUp(1); add(); } else { if (sep.test(ch)) { result.push(range(stream.start, stream.current().length - 1)); stream.eatWhile(sep); stream.start = stream.pos; } } } add(); return utils.unique(result.filter(function(item) { return !!item.length(); })); }
javascript
function findParts(str) { /** @type StringStream */ var stream = stringStream.create(str); var ch; var result = []; var sep = /[\s\u00a0,;]/; var add = function() { stream.next(); result.push(range(stream.start, stream.current())); stream.start = stream.pos; }; // skip whitespace stream.eatSpace(); stream.start = stream.pos; while ((ch = stream.next())) { if (ch == '"' || ch == "'") { stream.next(); if (!stream.skipTo(ch)) break; add(); } else if (ch == '(') { // function found, may have nested function stream.backUp(1); if (!stream.skipToPair('(', ')')) break; stream.backUp(1); add(); } else { if (sep.test(ch)) { result.push(range(stream.start, stream.current().length - 1)); stream.eatWhile(sep); stream.start = stream.pos; } } } add(); return utils.unique(result.filter(function(item) { return !!item.length(); })); }
[ "function", "findParts", "(", "str", ")", "{", "/** @type StringStream */", "var", "stream", "=", "stringStream", ".", "create", "(", "str", ")", ";", "var", "ch", ";", "var", "result", "=", "[", "]", ";", "var", "sep", "=", "/", "[\\s\\u00a0,;]", "/", ";", "var", "add", "=", "function", "(", ")", "{", "stream", ".", "next", "(", ")", ";", "result", ".", "push", "(", "range", "(", "stream", ".", "start", ",", "stream", ".", "current", "(", ")", ")", ")", ";", "stream", ".", "start", "=", "stream", ".", "pos", ";", "}", ";", "// skip whitespace", "stream", ".", "eatSpace", "(", ")", ";", "stream", ".", "start", "=", "stream", ".", "pos", ";", "while", "(", "(", "ch", "=", "stream", ".", "next", "(", ")", ")", ")", "{", "if", "(", "ch", "==", "'\"'", "||", "ch", "==", "\"'\"", ")", "{", "stream", ".", "next", "(", ")", ";", "if", "(", "!", "stream", ".", "skipTo", "(", "ch", ")", ")", "break", ";", "add", "(", ")", ";", "}", "else", "if", "(", "ch", "==", "'('", ")", "{", "// function found, may have nested function", "stream", ".", "backUp", "(", "1", ")", ";", "if", "(", "!", "stream", ".", "skipToPair", "(", "'('", ",", "')'", ")", ")", "break", ";", "stream", ".", "backUp", "(", "1", ")", ";", "add", "(", ")", ";", "}", "else", "{", "if", "(", "sep", ".", "test", "(", "ch", ")", ")", "{", "result", ".", "push", "(", "range", "(", "stream", ".", "start", ",", "stream", ".", "current", "(", ")", ".", "length", "-", "1", ")", ")", ";", "stream", ".", "eatWhile", "(", "sep", ")", ";", "stream", ".", "start", "=", "stream", ".", "pos", ";", "}", "}", "}", "add", "(", ")", ";", "return", "utils", ".", "unique", "(", "result", ".", "filter", "(", "function", "(", "item", ")", "{", "return", "!", "!", "item", ".", "length", "(", ")", ";", "}", ")", ")", ";", "}" ]
Finds parts of complex CSS value @param {String} str @returns {Array} Returns list of <code>Range</code>'s
[ "Finds", "parts", "of", "complex", "CSS", "value" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L165-L207
11,218
emmetio/emmet
lib/editTree/css.js
consumeProperties
function consumeProperties(node, source, offset) { var list = extractPropertiesFromSource(source, offset); list.forEach(function(property) { node._children.push(new CSSEditElement(node, editTree.createToken(property.name.start, property.nameText), editTree.createToken(property.value.start, property.valueText), editTree.createToken(property.end.start, property.endText) )); }); }
javascript
function consumeProperties(node, source, offset) { var list = extractPropertiesFromSource(source, offset); list.forEach(function(property) { node._children.push(new CSSEditElement(node, editTree.createToken(property.name.start, property.nameText), editTree.createToken(property.value.start, property.valueText), editTree.createToken(property.end.start, property.endText) )); }); }
[ "function", "consumeProperties", "(", "node", ",", "source", ",", "offset", ")", "{", "var", "list", "=", "extractPropertiesFromSource", "(", "source", ",", "offset", ")", ";", "list", ".", "forEach", "(", "function", "(", "property", ")", "{", "node", ".", "_children", ".", "push", "(", "new", "CSSEditElement", "(", "node", ",", "editTree", ".", "createToken", "(", "property", ".", "name", ".", "start", ",", "property", ".", "nameText", ")", ",", "editTree", ".", "createToken", "(", "property", ".", "value", ".", "start", ",", "property", ".", "valueText", ")", ",", "editTree", ".", "createToken", "(", "property", ".", "end", ".", "start", ",", "property", ".", "endText", ")", ")", ")", ";", "}", ")", ";", "}" ]
Parses CSS properties from given CSS source and adds them to CSSEditContainer node @param {CSSEditContainer} node @param {String} source CSS source @param {Number} offset Offset of properties subset from original source
[ "Parses", "CSS", "properties", "from", "given", "CSS", "source", "and", "adds", "them", "to", "CSSEditContainer", "node" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L216-L226
11,219
emmetio/emmet
lib/editTree/css.js
extractPropertiesFromSource
function extractPropertiesFromSource(source, offset) { offset = offset || 0; source = source.replace(reSpaceEnd, ''); var out = []; if (!source) { return out; } var tokens = cssParser.parse(source); var it = tokenIterator.create(tokens); var property; while ((property = consumeSingleProperty(it, source))) { out.push({ nameText: property.name.substring(source), name: property.name.shift(offset), valueText: property.value.substring(source), value: property.value.shift(offset), endText: property.end.substring(source), end: property.end.shift(offset) }); } return out; }
javascript
function extractPropertiesFromSource(source, offset) { offset = offset || 0; source = source.replace(reSpaceEnd, ''); var out = []; if (!source) { return out; } var tokens = cssParser.parse(source); var it = tokenIterator.create(tokens); var property; while ((property = consumeSingleProperty(it, source))) { out.push({ nameText: property.name.substring(source), name: property.name.shift(offset), valueText: property.value.substring(source), value: property.value.shift(offset), endText: property.end.substring(source), end: property.end.shift(offset) }); } return out; }
[ "function", "extractPropertiesFromSource", "(", "source", ",", "offset", ")", "{", "offset", "=", "offset", "||", "0", ";", "source", "=", "source", ".", "replace", "(", "reSpaceEnd", ",", "''", ")", ";", "var", "out", "=", "[", "]", ";", "if", "(", "!", "source", ")", "{", "return", "out", ";", "}", "var", "tokens", "=", "cssParser", ".", "parse", "(", "source", ")", ";", "var", "it", "=", "tokenIterator", ".", "create", "(", "tokens", ")", ";", "var", "property", ";", "while", "(", "(", "property", "=", "consumeSingleProperty", "(", "it", ",", "source", ")", ")", ")", "{", "out", ".", "push", "(", "{", "nameText", ":", "property", ".", "name", ".", "substring", "(", "source", ")", ",", "name", ":", "property", ".", "name", ".", "shift", "(", "offset", ")", ",", "valueText", ":", "property", ".", "value", ".", "substring", "(", "source", ")", ",", "value", ":", "property", ".", "value", ".", "shift", "(", "offset", ")", ",", "endText", ":", "property", ".", "end", ".", "substring", "(", "source", ")", ",", "end", ":", "property", ".", "end", ".", "shift", "(", "offset", ")", "}", ")", ";", "}", "return", "out", ";", "}" ]
Parses given CSS source and returns list of ranges of located CSS properties. Normally, CSS source must contain properties only, it must be, for example, a content of CSS selector or text between nested CSS sections @param {String} source CSS source @param {Number} offset Offset of properties subset from original source. Used to provide proper ranges of locates items
[ "Parses", "given", "CSS", "source", "and", "returns", "list", "of", "ranges", "of", "located", "CSS", "properties", ".", "Normally", "CSS", "source", "must", "contain", "properties", "only", "it", "must", "be", "for", "example", "a", "content", "of", "CSS", "selector", "or", "text", "between", "nested", "CSS", "sections" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L237-L264
11,220
emmetio/emmet
lib/editTree/css.js
function(name, value, pos) { var list = this.list(); var start = this._positions.contentStart; var styles = utils.pick(this.options, 'styleBefore', 'styleSeparator'); if (typeof pos === 'undefined') { pos = list.length; } /** @type CSSEditProperty */ var donor = list[pos]; if (donor) { start = donor.fullRange().start; } else if ((donor = list[pos - 1])) { // make sure that donor has terminating semicolon donor.end(';'); start = donor.range().end; } if (donor) { styles = utils.pick(donor, 'styleBefore', 'styleSeparator'); } var nameToken = editTree.createToken(start + styles.styleBefore.length, name); var valueToken = editTree.createToken(nameToken.end + styles.styleSeparator.length, value); var property = new CSSEditElement(this, nameToken, valueToken, editTree.createToken(valueToken.end, ';')); utils.extend(property, styles); // write new property into the source this._updateSource(property.styleBefore + property.toString(), start); // insert new property this._children.splice(pos, 0, property); return property; }
javascript
function(name, value, pos) { var list = this.list(); var start = this._positions.contentStart; var styles = utils.pick(this.options, 'styleBefore', 'styleSeparator'); if (typeof pos === 'undefined') { pos = list.length; } /** @type CSSEditProperty */ var donor = list[pos]; if (donor) { start = donor.fullRange().start; } else if ((donor = list[pos - 1])) { // make sure that donor has terminating semicolon donor.end(';'); start = donor.range().end; } if (donor) { styles = utils.pick(donor, 'styleBefore', 'styleSeparator'); } var nameToken = editTree.createToken(start + styles.styleBefore.length, name); var valueToken = editTree.createToken(nameToken.end + styles.styleSeparator.length, value); var property = new CSSEditElement(this, nameToken, valueToken, editTree.createToken(valueToken.end, ';')); utils.extend(property, styles); // write new property into the source this._updateSource(property.styleBefore + property.toString(), start); // insert new property this._children.splice(pos, 0, property); return property; }
[ "function", "(", "name", ",", "value", ",", "pos", ")", "{", "var", "list", "=", "this", ".", "list", "(", ")", ";", "var", "start", "=", "this", ".", "_positions", ".", "contentStart", ";", "var", "styles", "=", "utils", ".", "pick", "(", "this", ".", "options", ",", "'styleBefore'", ",", "'styleSeparator'", ")", ";", "if", "(", "typeof", "pos", "===", "'undefined'", ")", "{", "pos", "=", "list", ".", "length", ";", "}", "/** @type CSSEditProperty */", "var", "donor", "=", "list", "[", "pos", "]", ";", "if", "(", "donor", ")", "{", "start", "=", "donor", ".", "fullRange", "(", ")", ".", "start", ";", "}", "else", "if", "(", "(", "donor", "=", "list", "[", "pos", "-", "1", "]", ")", ")", "{", "// make sure that donor has terminating semicolon", "donor", ".", "end", "(", "';'", ")", ";", "start", "=", "donor", ".", "range", "(", ")", ".", "end", ";", "}", "if", "(", "donor", ")", "{", "styles", "=", "utils", ".", "pick", "(", "donor", ",", "'styleBefore'", ",", "'styleSeparator'", ")", ";", "}", "var", "nameToken", "=", "editTree", ".", "createToken", "(", "start", "+", "styles", ".", "styleBefore", ".", "length", ",", "name", ")", ";", "var", "valueToken", "=", "editTree", ".", "createToken", "(", "nameToken", ".", "end", "+", "styles", ".", "styleSeparator", ".", "length", ",", "value", ")", ";", "var", "property", "=", "new", "CSSEditElement", "(", "this", ",", "nameToken", ",", "valueToken", ",", "editTree", ".", "createToken", "(", "valueToken", ".", "end", ",", "';'", ")", ")", ";", "utils", ".", "extend", "(", "property", ",", "styles", ")", ";", "// write new property into the source", "this", ".", "_updateSource", "(", "property", ".", "styleBefore", "+", "property", ".", "toString", "(", ")", ",", "start", ")", ";", "// insert new property", "this", ".", "_children", ".", "splice", "(", "pos", ",", "0", ",", "property", ")", ";", "return", "property", ";", "}" ]
Adds new CSS property @param {String} name Property name @param {String} value Property value @param {Number} pos Position at which to insert new property. By default the property is inserted at the end of rule @returns {CSSEditProperty}
[ "Adds", "new", "CSS", "property" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L392-L429
11,221
emmetio/emmet
lib/editTree/css.js
function(isAbsolute) { var parts = findParts(this.value()); if (isAbsolute) { var offset = this.valuePosition(true); parts.forEach(function(p) { p.shift(offset); }); } return parts; }
javascript
function(isAbsolute) { var parts = findParts(this.value()); if (isAbsolute) { var offset = this.valuePosition(true); parts.forEach(function(p) { p.shift(offset); }); } return parts; }
[ "function", "(", "isAbsolute", ")", "{", "var", "parts", "=", "findParts", "(", "this", ".", "value", "(", ")", ")", ";", "if", "(", "isAbsolute", ")", "{", "var", "offset", "=", "this", ".", "valuePosition", "(", "true", ")", ";", "parts", ".", "forEach", "(", "function", "(", "p", ")", "{", "p", ".", "shift", "(", "offset", ")", ";", "}", ")", ";", "}", "return", "parts", ";", "}" ]
Returns ranges of complex value parts @returns {Array} Returns <code>null</code> if value is not complex
[ "Returns", "ranges", "of", "complex", "value", "parts" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L450-L460
11,222
emmetio/emmet
lib/editTree/css.js
function(val) { var isUpdating = typeof val !== 'undefined'; var allItems = this.parent.list(); if (isUpdating && this.isIncomplete()) { var self = this; var donor = utils.find(allItems, function(item) { return item !== self && !item.isIncomplete(); }); this.styleSeparator = donor ? donor.styleSeparator : this.parent.options.styleSeparator; this.parent._updateSource(this.styleSeparator, range(this.valueRange().start, 0)); } var value = this.constructor.__super__.value.apply(this, arguments); if (isUpdating) { // make sure current property has terminating semi-colon // if it’s not the last one var ix = allItems.indexOf(this); if (ix !== allItems.length - 1 && !this.end()) { this.end(';'); } } return value; }
javascript
function(val) { var isUpdating = typeof val !== 'undefined'; var allItems = this.parent.list(); if (isUpdating && this.isIncomplete()) { var self = this; var donor = utils.find(allItems, function(item) { return item !== self && !item.isIncomplete(); }); this.styleSeparator = donor ? donor.styleSeparator : this.parent.options.styleSeparator; this.parent._updateSource(this.styleSeparator, range(this.valueRange().start, 0)); } var value = this.constructor.__super__.value.apply(this, arguments); if (isUpdating) { // make sure current property has terminating semi-colon // if it’s not the last one var ix = allItems.indexOf(this); if (ix !== allItems.length - 1 && !this.end()) { this.end(';'); } } return value; }
[ "function", "(", "val", ")", "{", "var", "isUpdating", "=", "typeof", "val", "!==", "'undefined'", ";", "var", "allItems", "=", "this", ".", "parent", ".", "list", "(", ")", ";", "if", "(", "isUpdating", "&&", "this", ".", "isIncomplete", "(", ")", ")", "{", "var", "self", "=", "this", ";", "var", "donor", "=", "utils", ".", "find", "(", "allItems", ",", "function", "(", "item", ")", "{", "return", "item", "!==", "self", "&&", "!", "item", ".", "isIncomplete", "(", ")", ";", "}", ")", ";", "this", ".", "styleSeparator", "=", "donor", "?", "donor", ".", "styleSeparator", ":", "this", ".", "parent", ".", "options", ".", "styleSeparator", ";", "this", ".", "parent", ".", "_updateSource", "(", "this", ".", "styleSeparator", ",", "range", "(", "this", ".", "valueRange", "(", ")", ".", "start", ",", "0", ")", ")", ";", "}", "var", "value", "=", "this", ".", "constructor", ".", "__super__", ".", "value", ".", "apply", "(", "this", ",", "arguments", ")", ";", "if", "(", "isUpdating", ")", "{", "// make sure current property has terminating semi-colon", "// if it’s not the last one", "var", "ix", "=", "allItems", ".", "indexOf", "(", "this", ")", ";", "if", "(", "ix", "!==", "allItems", ".", "length", "-", "1", "&&", "!", "this", ".", "end", "(", ")", ")", "{", "this", ".", "end", "(", "';'", ")", ";", "}", "}", "return", "value", ";", "}" ]
Sets of gets element value. When setting value, this implementation will ensure that your have proper name-value separator @param {String} val New element value. If not passed, current value is returned @returns {String}
[ "Sets", "of", "gets", "element", "value", ".", "When", "setting", "value", "this", "implementation", "will", "ensure", "that", "your", "have", "proper", "name", "-", "value", "separator" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L470-L495
11,223
emmetio/emmet
lib/editTree/css.js
function(css, pos) { var cssProp = null; /** @type EditContainer */ var cssRule = typeof css === 'string' ? this.parseFromPosition(css, pos, true) : css; if (cssRule) { cssProp = cssRule.itemFromPosition(pos, true); if (!cssProp) { // in case user just started writing CSS property // and didn't include semicolon–try another approach cssProp = utils.find(cssRule.list(), function(elem) { return elem.range(true).end == pos; }); } } return cssProp; }
javascript
function(css, pos) { var cssProp = null; /** @type EditContainer */ var cssRule = typeof css === 'string' ? this.parseFromPosition(css, pos, true) : css; if (cssRule) { cssProp = cssRule.itemFromPosition(pos, true); if (!cssProp) { // in case user just started writing CSS property // and didn't include semicolon–try another approach cssProp = utils.find(cssRule.list(), function(elem) { return elem.range(true).end == pos; }); } } return cssProp; }
[ "function", "(", "css", ",", "pos", ")", "{", "var", "cssProp", "=", "null", ";", "/** @type EditContainer */", "var", "cssRule", "=", "typeof", "css", "===", "'string'", "?", "this", ".", "parseFromPosition", "(", "css", ",", "pos", ",", "true", ")", ":", "css", ";", "if", "(", "cssRule", ")", "{", "cssProp", "=", "cssRule", ".", "itemFromPosition", "(", "pos", ",", "true", ")", ";", "if", "(", "!", "cssProp", ")", "{", "// in case user just started writing CSS property", "// and didn't include semicolon–try another approach", "cssProp", "=", "utils", ".", "find", "(", "cssRule", ".", "list", "(", ")", ",", "function", "(", "elem", ")", "{", "return", "elem", ".", "range", "(", "true", ")", ".", "end", "==", "pos", ";", "}", ")", ";", "}", "}", "return", "cssProp", ";", "}" ]
Locates CSS property in given CSS code fragment under specified character position @param {String} css CSS code or parsed CSSEditContainer @param {Number} pos Character position where to search CSS property @return {CSSEditElement}
[ "Locates", "CSS", "property", "in", "given", "CSS", "code", "fragment", "under", "specified", "character", "position" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/css.js#L577-L593
11,224
emmetio/emmet
lib/assets/range.js
function(range) { if (this.overlap(range)) { var start = Math.max(range.start, this.start); var end = Math.min(range.end, this.end); return new Range(start, end - start); } return null; }
javascript
function(range) { if (this.overlap(range)) { var start = Math.max(range.start, this.start); var end = Math.min(range.end, this.end); return new Range(start, end - start); } return null; }
[ "function", "(", "range", ")", "{", "if", "(", "this", ".", "overlap", "(", "range", ")", ")", "{", "var", "start", "=", "Math", ".", "max", "(", "range", ".", "start", ",", "this", ".", "start", ")", ";", "var", "end", "=", "Math", ".", "min", "(", "range", ".", "end", ",", "this", ".", "end", ")", ";", "return", "new", "Range", "(", "start", ",", "end", "-", "start", ")", ";", "}", "return", "null", ";", "}" ]
Finds intersection of two ranges @param {Range} range @returns {Range} <code>null</code> if ranges does not overlap
[ "Finds", "intersection", "of", "two", "ranges" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/range.js#L93-L101
11,225
emmetio/emmet
lib/assets/range.js
function(loc, left, right) { var a, b; if (loc instanceof Range) { a = loc.start; b = loc.end; } else { a = b = loc; } return cmp(this.start, a, left || '<=') && cmp(this.end, b, right || '>'); }
javascript
function(loc, left, right) { var a, b; if (loc instanceof Range) { a = loc.start; b = loc.end; } else { a = b = loc; } return cmp(this.start, a, left || '<=') && cmp(this.end, b, right || '>'); }
[ "function", "(", "loc", ",", "left", ",", "right", ")", "{", "var", "a", ",", "b", ";", "if", "(", "loc", "instanceof", "Range", ")", "{", "a", "=", "loc", ".", "start", ";", "b", "=", "loc", ".", "end", ";", "}", "else", "{", "a", "=", "b", "=", "loc", ";", "}", "return", "cmp", "(", "this", ".", "start", ",", "a", ",", "left", "||", "'<='", ")", "&&", "cmp", "(", "this", ".", "end", ",", "b", ",", "right", "||", "'>'", ")", ";", "}" ]
Low-level comparision method @param {Number} loc @param {String} left Left comparison operator @param {String} right Right comaprison operator
[ "Low", "-", "level", "comparision", "method" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/range.js#L153-L163
11,226
emmetio/emmet
lib/utils/common.js
function(strings) { var lengths = strings.map(function(s) { return typeof s === 'string' ? s.length : +s; }); var max = lengths.reduce(function(prev, cur) { return typeof prev === 'undefined' ? cur : Math.max(prev, cur); }); return lengths.map(function(l) { var pad = max - l; return pad ? this.repeatString(' ', pad) : ''; }, this); }
javascript
function(strings) { var lengths = strings.map(function(s) { return typeof s === 'string' ? s.length : +s; }); var max = lengths.reduce(function(prev, cur) { return typeof prev === 'undefined' ? cur : Math.max(prev, cur); }); return lengths.map(function(l) { var pad = max - l; return pad ? this.repeatString(' ', pad) : ''; }, this); }
[ "function", "(", "strings", ")", "{", "var", "lengths", "=", "strings", ".", "map", "(", "function", "(", "s", ")", "{", "return", "typeof", "s", "===", "'string'", "?", "s", ".", "length", ":", "+", "s", ";", "}", ")", ";", "var", "max", "=", "lengths", ".", "reduce", "(", "function", "(", "prev", ",", "cur", ")", "{", "return", "typeof", "prev", "===", "'undefined'", "?", "cur", ":", "Math", ".", "max", "(", "prev", ",", "cur", ")", ";", "}", ")", ";", "return", "lengths", ".", "map", "(", "function", "(", "l", ")", "{", "var", "pad", "=", "max", "-", "l", ";", "return", "pad", "?", "this", ".", "repeatString", "(", "' '", ",", "pad", ")", ":", "''", ";", "}", ",", "this", ")", ";", "}" ]
Returns list of paddings that should be used to align passed string @param {Array} strings @returns {Array}
[ "Returns", "list", "of", "paddings", "that", "should", "be", "used", "to", "align", "passed", "string" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/common.js#L117-L129
11,227
emmetio/emmet
lib/utils/common.js
function(text, pad) { var result = []; var lines = this.splitByLines(text); var nl = '\n'; result.push(lines[0]); for (var j = 1; j < lines.length; j++) result.push(nl + pad + lines[j]); return result.join(''); }
javascript
function(text, pad) { var result = []; var lines = this.splitByLines(text); var nl = '\n'; result.push(lines[0]); for (var j = 1; j < lines.length; j++) result.push(nl + pad + lines[j]); return result.join(''); }
[ "function", "(", "text", ",", "pad", ")", "{", "var", "result", "=", "[", "]", ";", "var", "lines", "=", "this", ".", "splitByLines", "(", "text", ")", ";", "var", "nl", "=", "'\\n'", ";", "result", ".", "push", "(", "lines", "[", "0", "]", ")", ";", "for", "(", "var", "j", "=", "1", ";", "j", "<", "lines", ".", "length", ";", "j", "++", ")", "result", ".", "push", "(", "nl", "+", "pad", "+", "lines", "[", "j", "]", ")", ";", "return", "result", ".", "join", "(", "''", ")", ";", "}" ]
Indents text with padding @param {String} text Text to indent @param {String} pad Padding size (number) or padding itself (string) @return {String}
[ "Indents", "text", "with", "padding" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/common.js#L137-L147
11,228
emmetio/emmet
lib/utils/common.js
function(str, pad) { var padding = ''; var il = str.length; while (pad > il++) padding += '0'; return padding + str; }
javascript
function(str, pad) { var padding = ''; var il = str.length; while (pad > il++) padding += '0'; return padding + str; }
[ "function", "(", "str", ",", "pad", ")", "{", "var", "padding", "=", "''", ";", "var", "il", "=", "str", ".", "length", ";", "while", "(", "pad", ">", "il", "++", ")", "padding", "+=", "'0'", ";", "return", "padding", "+", "str", ";", "}" ]
Pad string with zeroes @param {String} str String to pad @param {Number} pad Desired string length @return {String}
[ "Pad", "string", "with", "zeroes" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/common.js#L155-L161
11,229
emmetio/emmet
lib/utils/common.js
function(text, pad) { var lines = this.splitByLines(text); var pl = pad.length; for (var i = 0, il = lines.length, line; i < il; i++) { line = lines[i]; if (line.substr(0, pl) === pad) { lines[i] = line.substr(pl); } } return lines.join('\n'); }
javascript
function(text, pad) { var lines = this.splitByLines(text); var pl = pad.length; for (var i = 0, il = lines.length, line; i < il; i++) { line = lines[i]; if (line.substr(0, pl) === pad) { lines[i] = line.substr(pl); } } return lines.join('\n'); }
[ "function", "(", "text", ",", "pad", ")", "{", "var", "lines", "=", "this", ".", "splitByLines", "(", "text", ")", ";", "var", "pl", "=", "pad", ".", "length", ";", "for", "(", "var", "i", "=", "0", ",", "il", "=", "lines", ".", "length", ",", "line", ";", "i", "<", "il", ";", "i", "++", ")", "{", "line", "=", "lines", "[", "i", "]", ";", "if", "(", "line", ".", "substr", "(", "0", ",", "pl", ")", "===", "pad", ")", "{", "lines", "[", "i", "]", "=", "line", ".", "substr", "(", "pl", ")", ";", "}", "}", "return", "lines", ".", "join", "(", "'\\n'", ")", ";", "}" ]
Removes padding at the beginning of each text's line @param {String} text @param {String} pad
[ "Removes", "padding", "at", "the", "beginning", "of", "each", "text", "s", "line" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/common.js#L168-L179
11,230
emmetio/emmet
lib/utils/common.js
function(content, ranges, ch, noRepeat) { if (ranges.length) { var offset = 0, fragments = []; ranges.forEach(function(r) { var repl = noRepeat ? ch : this.repeatString(ch, r[1] - r[0]); fragments.push(content.substring(offset, r[0]), repl); offset = r[1]; }, this); content = fragments.join('') + content.substring(offset); } return content; }
javascript
function(content, ranges, ch, noRepeat) { if (ranges.length) { var offset = 0, fragments = []; ranges.forEach(function(r) { var repl = noRepeat ? ch : this.repeatString(ch, r[1] - r[0]); fragments.push(content.substring(offset, r[0]), repl); offset = r[1]; }, this); content = fragments.join('') + content.substring(offset); } return content; }
[ "function", "(", "content", ",", "ranges", ",", "ch", ",", "noRepeat", ")", "{", "if", "(", "ranges", ".", "length", ")", "{", "var", "offset", "=", "0", ",", "fragments", "=", "[", "]", ";", "ranges", ".", "forEach", "(", "function", "(", "r", ")", "{", "var", "repl", "=", "noRepeat", "?", "ch", ":", "this", ".", "repeatString", "(", "ch", ",", "r", "[", "1", "]", "-", "r", "[", "0", "]", ")", ";", "fragments", ".", "push", "(", "content", ".", "substring", "(", "offset", ",", "r", "[", "0", "]", ")", ",", "repl", ")", ";", "offset", "=", "r", "[", "1", "]", ";", "}", ",", "this", ")", ";", "content", "=", "fragments", ".", "join", "(", "''", ")", "+", "content", ".", "substring", "(", "offset", ")", ";", "}", "return", "content", ";", "}" ]
Fills substrings in `content`, defined by given ranges, wich `ch` character @param {String} content @param {Array} ranges @return {String}
[ "Fills", "substrings", "in", "content", "defined", "by", "given", "ranges", "wich", "ch", "character" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/common.js#L412-L425
11,231
emmetio/emmet
lib/utils/common.js
function(text, start, end) { var rng = range.create(start, end); var reSpace = /[\s\n\r\u00a0]/; // narrow down selection until first non-space character while (rng.start < rng.end) { if (!reSpace.test(text.charAt(rng.start))) break; rng.start++; } while (rng.end > rng.start) { rng.end--; if (!reSpace.test(text.charAt(rng.end))) { rng.end++; break; } } return rng; }
javascript
function(text, start, end) { var rng = range.create(start, end); var reSpace = /[\s\n\r\u00a0]/; // narrow down selection until first non-space character while (rng.start < rng.end) { if (!reSpace.test(text.charAt(rng.start))) break; rng.start++; } while (rng.end > rng.start) { rng.end--; if (!reSpace.test(text.charAt(rng.end))) { rng.end++; break; } } return rng; }
[ "function", "(", "text", ",", "start", ",", "end", ")", "{", "var", "rng", "=", "range", ".", "create", "(", "start", ",", "end", ")", ";", "var", "reSpace", "=", "/", "[\\s\\n\\r\\u00a0]", "/", ";", "// narrow down selection until first non-space character", "while", "(", "rng", ".", "start", "<", "rng", ".", "end", ")", "{", "if", "(", "!", "reSpace", ".", "test", "(", "text", ".", "charAt", "(", "rng", ".", "start", ")", ")", ")", "break", ";", "rng", ".", "start", "++", ";", "}", "while", "(", "rng", ".", "end", ">", "rng", ".", "start", ")", "{", "rng", ".", "end", "--", ";", "if", "(", "!", "reSpace", ".", "test", "(", "text", ".", "charAt", "(", "rng", ".", "end", ")", ")", ")", "{", "rng", ".", "end", "++", ";", "break", ";", "}", "}", "return", "rng", ";", "}" ]
Narrows down text range, adjusting selection to non-space characters @param {String} text @param {Number} start Starting range in <code>text</code> where slection should be adjusted. Can also be any object that is accepted by <code>Range</code> class @return {Range}
[ "Narrows", "down", "text", "range", "adjusting", "selection", "to", "non", "-", "space", "characters" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/common.js#L435-L456
11,232
emmetio/emmet
lib/assets/tabStops.js
function(node, offset) { var maxNum = 0; var options = { tabstop: function(data) { var group = parseInt(data.group, 10); if (group > maxNum) maxNum = group; if (data.placeholder) return '${' + (group + offset) + ':' + data.placeholder + '}'; else return '${' + (group + offset) + '}'; } }; ['start', 'end', 'content'].forEach(function(p) { node[p] = this.processText(node[p], options); }, this); return maxNum; }
javascript
function(node, offset) { var maxNum = 0; var options = { tabstop: function(data) { var group = parseInt(data.group, 10); if (group > maxNum) maxNum = group; if (data.placeholder) return '${' + (group + offset) + ':' + data.placeholder + '}'; else return '${' + (group + offset) + '}'; } }; ['start', 'end', 'content'].forEach(function(p) { node[p] = this.processText(node[p], options); }, this); return maxNum; }
[ "function", "(", "node", ",", "offset", ")", "{", "var", "maxNum", "=", "0", ";", "var", "options", "=", "{", "tabstop", ":", "function", "(", "data", ")", "{", "var", "group", "=", "parseInt", "(", "data", ".", "group", ",", "10", ")", ";", "if", "(", "group", ">", "maxNum", ")", "maxNum", "=", "group", ";", "if", "(", "data", ".", "placeholder", ")", "return", "'${'", "+", "(", "group", "+", "offset", ")", "+", "':'", "+", "data", ".", "placeholder", "+", "'}'", ";", "else", "return", "'${'", "+", "(", "group", "+", "offset", ")", "+", "'}'", ";", "}", "}", ";", "[", "'start'", ",", "'end'", ",", "'content'", "]", ".", "forEach", "(", "function", "(", "p", ")", "{", "node", "[", "p", "]", "=", "this", ".", "processText", "(", "node", "[", "p", "]", ",", "options", ")", ";", "}", ",", "this", ")", ";", "return", "maxNum", ";", "}" ]
Upgrades tabstops in output node in order to prevent naming conflicts @param {AbbreviationNode} node @param {Number} offset Tab index offset @returns {Number} Maximum tabstop index in element
[ "Upgrades", "tabstops", "in", "output", "node", "in", "order", "to", "prevent", "naming", "conflicts" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/tabStops.js#L223-L242
11,233
emmetio/emmet
lib/assets/tabStops.js
function(text, node, type) { var maxNum = 0; var that = this; var tsOptions = { tabstop: function(data) { var group = parseInt(data.group, 10); if (group === 0) return '${0}'; if (group > maxNum) maxNum = group; if (data.placeholder) { // respect nested placeholders var ix = group + tabstopIndex; var placeholder = that.processText(data.placeholder, tsOptions); return '${' + ix + ':' + placeholder + '}'; } else { return '${' + (group + tabstopIndex) + '}'; } } }; // upgrade tabstops text = this.processText(text, tsOptions); // resolve variables text = this.replaceVariables(text, this.variablesResolver(node)); tabstopIndex += maxNum + 1; return text; }
javascript
function(text, node, type) { var maxNum = 0; var that = this; var tsOptions = { tabstop: function(data) { var group = parseInt(data.group, 10); if (group === 0) return '${0}'; if (group > maxNum) maxNum = group; if (data.placeholder) { // respect nested placeholders var ix = group + tabstopIndex; var placeholder = that.processText(data.placeholder, tsOptions); return '${' + ix + ':' + placeholder + '}'; } else { return '${' + (group + tabstopIndex) + '}'; } } }; // upgrade tabstops text = this.processText(text, tsOptions); // resolve variables text = this.replaceVariables(text, this.variablesResolver(node)); tabstopIndex += maxNum + 1; return text; }
[ "function", "(", "text", ",", "node", ",", "type", ")", "{", "var", "maxNum", "=", "0", ";", "var", "that", "=", "this", ";", "var", "tsOptions", "=", "{", "tabstop", ":", "function", "(", "data", ")", "{", "var", "group", "=", "parseInt", "(", "data", ".", "group", ",", "10", ")", ";", "if", "(", "group", "===", "0", ")", "return", "'${0}'", ";", "if", "(", "group", ">", "maxNum", ")", "maxNum", "=", "group", ";", "if", "(", "data", ".", "placeholder", ")", "{", "// respect nested placeholders", "var", "ix", "=", "group", "+", "tabstopIndex", ";", "var", "placeholder", "=", "that", ".", "processText", "(", "data", ".", "placeholder", ",", "tsOptions", ")", ";", "return", "'${'", "+", "ix", "+", "':'", "+", "placeholder", "+", "'}'", ";", "}", "else", "{", "return", "'${'", "+", "(", "group", "+", "tabstopIndex", ")", "+", "'}'", ";", "}", "}", "}", ";", "// upgrade tabstops", "text", "=", "this", ".", "processText", "(", "text", ",", "tsOptions", ")", ";", "// resolve variables", "text", "=", "this", ".", "replaceVariables", "(", "text", ",", "this", ".", "variablesResolver", "(", "node", ")", ")", ";", "tabstopIndex", "+=", "maxNum", "+", "1", ";", "return", "text", ";", "}" ]
Output processor for abbreviation parser that will upgrade tabstops of parsed node in order to prevent tabstop index conflicts
[ "Output", "processor", "for", "abbreviation", "parser", "that", "will", "upgrade", "tabstops", "of", "parsed", "node", "in", "order", "to", "prevent", "tabstop", "index", "conflicts" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/tabStops.js#L336-L366
11,234
emmetio/emmet
lib/filter/html.js
makeAttributesString
function makeAttributesString(node, profile) { var attrQuote = profile.attributeQuote(); var cursor = profile.cursor(); return node.attributeList().map(function(a) { var isBoolean = profile.isBoolean(a.name, a.value); var attrName = profile.attributeName(a.name); var attrValue = isBoolean ? attrName : a.value; if (isBoolean && profile.allowCompactBoolean()) { return ' ' + attrName; } return ' ' + attrName + '=' + attrQuote + (attrValue || cursor) + attrQuote; }).join(''); }
javascript
function makeAttributesString(node, profile) { var attrQuote = profile.attributeQuote(); var cursor = profile.cursor(); return node.attributeList().map(function(a) { var isBoolean = profile.isBoolean(a.name, a.value); var attrName = profile.attributeName(a.name); var attrValue = isBoolean ? attrName : a.value; if (isBoolean && profile.allowCompactBoolean()) { return ' ' + attrName; } return ' ' + attrName + '=' + attrQuote + (attrValue || cursor) + attrQuote; }).join(''); }
[ "function", "makeAttributesString", "(", "node", ",", "profile", ")", "{", "var", "attrQuote", "=", "profile", ".", "attributeQuote", "(", ")", ";", "var", "cursor", "=", "profile", ".", "cursor", "(", ")", ";", "return", "node", ".", "attributeList", "(", ")", ".", "map", "(", "function", "(", "a", ")", "{", "var", "isBoolean", "=", "profile", ".", "isBoolean", "(", "a", ".", "name", ",", "a", ".", "value", ")", ";", "var", "attrName", "=", "profile", ".", "attributeName", "(", "a", ".", "name", ")", ";", "var", "attrValue", "=", "isBoolean", "?", "attrName", ":", "a", ".", "value", ";", "if", "(", "isBoolean", "&&", "profile", ".", "allowCompactBoolean", "(", ")", ")", "{", "return", "' '", "+", "attrName", ";", "}", "return", "' '", "+", "attrName", "+", "'='", "+", "attrQuote", "+", "(", "attrValue", "||", "cursor", ")", "+", "attrQuote", ";", "}", ")", ".", "join", "(", "''", ")", ";", "}" ]
Creates HTML attributes string from tag according to profile settings @param {AbbreviationNode} node @param {OutputProfile} profile
[ "Creates", "HTML", "attributes", "string", "from", "tag", "according", "to", "profile", "settings" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/filter/html.js#L21-L34
11,235
emmetio/emmet
lib/utils/action.js
function(str) { var curOffset = str.length; var startIndex = -1; var groupCount = 0; var braceCount = 0; var textCount = 0; while (true) { curOffset--; if (curOffset < 0) { // moved to the beginning of the line startIndex = 0; break; } var ch = str.charAt(curOffset); if (ch == ']') { braceCount++; } else if (ch == '[') { if (!braceCount) { // unexpected brace startIndex = curOffset + 1; break; } braceCount--; } else if (ch == '}') { textCount++; } else if (ch == '{') { if (!textCount) { // unexpected brace startIndex = curOffset + 1; break; } textCount--; } else if (ch == ')') { groupCount++; } else if (ch == '(') { if (!groupCount) { // unexpected brace startIndex = curOffset + 1; break; } groupCount--; } else { if (braceCount || textCount) // respect all characters inside attribute sets or text nodes continue; else if (!abbreviationParser.isAllowedChar(ch) || (ch == '>' && utils.endsWithTag(str.substring(0, curOffset + 1)))) { // found stop symbol startIndex = curOffset + 1; break; } } } if (startIndex != -1 && !textCount && !braceCount && !groupCount) // found something, remove some invalid symbols from the // beginning and return abbreviation return str.substring(startIndex).replace(/^[\*\+\>\^]+/, ''); else return ''; }
javascript
function(str) { var curOffset = str.length; var startIndex = -1; var groupCount = 0; var braceCount = 0; var textCount = 0; while (true) { curOffset--; if (curOffset < 0) { // moved to the beginning of the line startIndex = 0; break; } var ch = str.charAt(curOffset); if (ch == ']') { braceCount++; } else if (ch == '[') { if (!braceCount) { // unexpected brace startIndex = curOffset + 1; break; } braceCount--; } else if (ch == '}') { textCount++; } else if (ch == '{') { if (!textCount) { // unexpected brace startIndex = curOffset + 1; break; } textCount--; } else if (ch == ')') { groupCount++; } else if (ch == '(') { if (!groupCount) { // unexpected brace startIndex = curOffset + 1; break; } groupCount--; } else { if (braceCount || textCount) // respect all characters inside attribute sets or text nodes continue; else if (!abbreviationParser.isAllowedChar(ch) || (ch == '>' && utils.endsWithTag(str.substring(0, curOffset + 1)))) { // found stop symbol startIndex = curOffset + 1; break; } } } if (startIndex != -1 && !textCount && !braceCount && !groupCount) // found something, remove some invalid symbols from the // beginning and return abbreviation return str.substring(startIndex).replace(/^[\*\+\>\^]+/, ''); else return ''; }
[ "function", "(", "str", ")", "{", "var", "curOffset", "=", "str", ".", "length", ";", "var", "startIndex", "=", "-", "1", ";", "var", "groupCount", "=", "0", ";", "var", "braceCount", "=", "0", ";", "var", "textCount", "=", "0", ";", "while", "(", "true", ")", "{", "curOffset", "--", ";", "if", "(", "curOffset", "<", "0", ")", "{", "// moved to the beginning of the line", "startIndex", "=", "0", ";", "break", ";", "}", "var", "ch", "=", "str", ".", "charAt", "(", "curOffset", ")", ";", "if", "(", "ch", "==", "']'", ")", "{", "braceCount", "++", ";", "}", "else", "if", "(", "ch", "==", "'['", ")", "{", "if", "(", "!", "braceCount", ")", "{", "// unexpected brace", "startIndex", "=", "curOffset", "+", "1", ";", "break", ";", "}", "braceCount", "--", ";", "}", "else", "if", "(", "ch", "==", "'}'", ")", "{", "textCount", "++", ";", "}", "else", "if", "(", "ch", "==", "'{'", ")", "{", "if", "(", "!", "textCount", ")", "{", "// unexpected brace", "startIndex", "=", "curOffset", "+", "1", ";", "break", ";", "}", "textCount", "--", ";", "}", "else", "if", "(", "ch", "==", "')'", ")", "{", "groupCount", "++", ";", "}", "else", "if", "(", "ch", "==", "'('", ")", "{", "if", "(", "!", "groupCount", ")", "{", "// unexpected brace", "startIndex", "=", "curOffset", "+", "1", ";", "break", ";", "}", "groupCount", "--", ";", "}", "else", "{", "if", "(", "braceCount", "||", "textCount", ")", "// respect all characters inside attribute sets or text nodes", "continue", ";", "else", "if", "(", "!", "abbreviationParser", ".", "isAllowedChar", "(", "ch", ")", "||", "(", "ch", "==", "'>'", "&&", "utils", ".", "endsWithTag", "(", "str", ".", "substring", "(", "0", ",", "curOffset", "+", "1", ")", ")", ")", ")", "{", "// found stop symbol", "startIndex", "=", "curOffset", "+", "1", ";", "break", ";", "}", "}", "}", "if", "(", "startIndex", "!=", "-", "1", "&&", "!", "textCount", "&&", "!", "braceCount", "&&", "!", "groupCount", ")", "// found something, remove some invalid symbols from the ", "// beginning and return abbreviation", "return", "str", ".", "substring", "(", "startIndex", ")", ".", "replace", "(", "/", "^[\\*\\+\\>\\^]+", "/", ",", "''", ")", ";", "else", "return", "''", ";", "}" ]
Extracts abbreviations from text stream, starting from the end @param {String} str @return {String} Abbreviation or empty string @memberOf emmet.actionUtils
[ "Extracts", "abbreviations", "from", "text", "stream", "starting", "from", "the", "end" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/action.js#L37-L96
11,236
emmetio/emmet
lib/utils/action.js
function(stream) { var pngMagicNum = "\211PNG\r\n\032\n", jpgMagicNum = "\377\330", gifMagicNum = "GIF8", pos = 0, nextByte = function() { return stream.charCodeAt(pos++); }; if (stream.substr(0, 8) === pngMagicNum) { // PNG. Easy peasy. pos = stream.indexOf('IHDR') + 4; return { width: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte(), height: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte() }; } else if (stream.substr(0, 4) === gifMagicNum) { pos = 6; return { width: nextByte() | (nextByte() << 8), height: nextByte() | (nextByte() << 8) }; } else if (stream.substr(0, 2) === jpgMagicNum) { pos = 2; var l = stream.length; while (pos < l) { if (nextByte() != 0xFF) return; var marker = nextByte(); if (marker == 0xDA) break; var size = (nextByte() << 8) | nextByte(); if (marker >= 0xC0 && marker <= 0xCF && !(marker & 0x4) && !(marker & 0x8)) { pos += 1; return { height: (nextByte() << 8) | nextByte(), width: (nextByte() << 8) | nextByte() }; } else { pos += size - 2; } } } }
javascript
function(stream) { var pngMagicNum = "\211PNG\r\n\032\n", jpgMagicNum = "\377\330", gifMagicNum = "GIF8", pos = 0, nextByte = function() { return stream.charCodeAt(pos++); }; if (stream.substr(0, 8) === pngMagicNum) { // PNG. Easy peasy. pos = stream.indexOf('IHDR') + 4; return { width: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte(), height: (nextByte() << 24) | (nextByte() << 16) | (nextByte() << 8) | nextByte() }; } else if (stream.substr(0, 4) === gifMagicNum) { pos = 6; return { width: nextByte() | (nextByte() << 8), height: nextByte() | (nextByte() << 8) }; } else if (stream.substr(0, 2) === jpgMagicNum) { pos = 2; var l = stream.length; while (pos < l) { if (nextByte() != 0xFF) return; var marker = nextByte(); if (marker == 0xDA) break; var size = (nextByte() << 8) | nextByte(); if (marker >= 0xC0 && marker <= 0xCF && !(marker & 0x4) && !(marker & 0x8)) { pos += 1; return { height: (nextByte() << 8) | nextByte(), width: (nextByte() << 8) | nextByte() }; } else { pos += size - 2; } } } }
[ "function", "(", "stream", ")", "{", "var", "pngMagicNum", "=", "\"\\211PNG\\r\\n\\032\\n\"", ",", "jpgMagicNum", "=", "\"\\377\\330\"", ",", "gifMagicNum", "=", "\"GIF8\"", ",", "pos", "=", "0", ",", "nextByte", "=", "function", "(", ")", "{", "return", "stream", ".", "charCodeAt", "(", "pos", "++", ")", ";", "}", ";", "if", "(", "stream", ".", "substr", "(", "0", ",", "8", ")", "===", "pngMagicNum", ")", "{", "// PNG. Easy peasy.", "pos", "=", "stream", ".", "indexOf", "(", "'IHDR'", ")", "+", "4", ";", "return", "{", "width", ":", "(", "nextByte", "(", ")", "<<", "24", ")", "|", "(", "nextByte", "(", ")", "<<", "16", ")", "|", "(", "nextByte", "(", ")", "<<", "8", ")", "|", "nextByte", "(", ")", ",", "height", ":", "(", "nextByte", "(", ")", "<<", "24", ")", "|", "(", "nextByte", "(", ")", "<<", "16", ")", "|", "(", "nextByte", "(", ")", "<<", "8", ")", "|", "nextByte", "(", ")", "}", ";", "}", "else", "if", "(", "stream", ".", "substr", "(", "0", ",", "4", ")", "===", "gifMagicNum", ")", "{", "pos", "=", "6", ";", "return", "{", "width", ":", "nextByte", "(", ")", "|", "(", "nextByte", "(", ")", "<<", "8", ")", ",", "height", ":", "nextByte", "(", ")", "|", "(", "nextByte", "(", ")", "<<", "8", ")", "}", ";", "}", "else", "if", "(", "stream", ".", "substr", "(", "0", ",", "2", ")", "===", "jpgMagicNum", ")", "{", "pos", "=", "2", ";", "var", "l", "=", "stream", ".", "length", ";", "while", "(", "pos", "<", "l", ")", "{", "if", "(", "nextByte", "(", ")", "!=", "0xFF", ")", "return", ";", "var", "marker", "=", "nextByte", "(", ")", ";", "if", "(", "marker", "==", "0xDA", ")", "break", ";", "var", "size", "=", "(", "nextByte", "(", ")", "<<", "8", ")", "|", "nextByte", "(", ")", ";", "if", "(", "marker", ">=", "0xC0", "&&", "marker", "<=", "0xCF", "&&", "!", "(", "marker", "&", "0x4", ")", "&&", "!", "(", "marker", "&", "0x8", ")", ")", "{", "pos", "+=", "1", ";", "return", "{", "height", ":", "(", "nextByte", "(", ")", "<<", "8", ")", "|", "nextByte", "(", ")", ",", "width", ":", "(", "nextByte", "(", ")", "<<", "8", ")", "|", "nextByte", "(", ")", "}", ";", "}", "else", "{", "pos", "+=", "size", "-", "2", ";", "}", "}", "}", "}" ]
Gets image size from image byte stream. @author http://romeda.org/rePublish/ @param {String} stream Image byte stream (use <code>IEmmetFile.read()</code>) @return {Object} Object with <code>width</code> and <code>height</code> properties
[ "Gets", "image", "size", "from", "image", "byte", "stream", "." ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/action.js#L104-L154
11,237
emmetio/emmet
lib/utils/action.js
function(editor, pos) { var allowedSyntaxes = {'html': 1, 'xml': 1, 'xsl': 1, 'jsx': 1}; var syntax = editor.getSyntax(); if (syntax in allowedSyntaxes) { var content = editor.getContent(); if (typeof pos === 'undefined') { pos = editor.getCaretPos(); } var tag = htmlMatcher.find(content, pos); if (tag && tag.type == 'tag') { var startTag = tag.open; var contextNode = { name: startTag.name, attributes: [], match: tag }; // parse attributes var tagTree = xmlEditTree.parse(startTag.range.substring(content)); if (tagTree) { contextNode.attributes = tagTree.getAll().map(function(item) { return { name: item.name(), value: item.value() }; }); } return contextNode; } } return null; }
javascript
function(editor, pos) { var allowedSyntaxes = {'html': 1, 'xml': 1, 'xsl': 1, 'jsx': 1}; var syntax = editor.getSyntax(); if (syntax in allowedSyntaxes) { var content = editor.getContent(); if (typeof pos === 'undefined') { pos = editor.getCaretPos(); } var tag = htmlMatcher.find(content, pos); if (tag && tag.type == 'tag') { var startTag = tag.open; var contextNode = { name: startTag.name, attributes: [], match: tag }; // parse attributes var tagTree = xmlEditTree.parse(startTag.range.substring(content)); if (tagTree) { contextNode.attributes = tagTree.getAll().map(function(item) { return { name: item.name(), value: item.value() }; }); } return contextNode; } } return null; }
[ "function", "(", "editor", ",", "pos", ")", "{", "var", "allowedSyntaxes", "=", "{", "'html'", ":", "1", ",", "'xml'", ":", "1", ",", "'xsl'", ":", "1", ",", "'jsx'", ":", "1", "}", ";", "var", "syntax", "=", "editor", ".", "getSyntax", "(", ")", ";", "if", "(", "syntax", "in", "allowedSyntaxes", ")", "{", "var", "content", "=", "editor", ".", "getContent", "(", ")", ";", "if", "(", "typeof", "pos", "===", "'undefined'", ")", "{", "pos", "=", "editor", ".", "getCaretPos", "(", ")", ";", "}", "var", "tag", "=", "htmlMatcher", ".", "find", "(", "content", ",", "pos", ")", ";", "if", "(", "tag", "&&", "tag", ".", "type", "==", "'tag'", ")", "{", "var", "startTag", "=", "tag", ".", "open", ";", "var", "contextNode", "=", "{", "name", ":", "startTag", ".", "name", ",", "attributes", ":", "[", "]", ",", "match", ":", "tag", "}", ";", "// parse attributes", "var", "tagTree", "=", "xmlEditTree", ".", "parse", "(", "startTag", ".", "range", ".", "substring", "(", "content", ")", ")", ";", "if", "(", "tagTree", ")", "{", "contextNode", ".", "attributes", "=", "tagTree", ".", "getAll", "(", ")", ".", "map", "(", "function", "(", "item", ")", "{", "return", "{", "name", ":", "item", ".", "name", "(", ")", ",", "value", ":", "item", ".", "value", "(", ")", "}", ";", "}", ")", ";", "}", "return", "contextNode", ";", "}", "}", "return", "null", ";", "}" ]
Captures context XHTML element from editor under current caret position. This node can be used as a helper for abbreviation extraction @param {IEmmetEditor} editor @returns {Object}
[ "Captures", "context", "XHTML", "element", "from", "editor", "under", "current", "caret", "position", ".", "This", "node", "can", "be", "used", "as", "a", "helper", "for", "abbreviation", "extraction" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/action.js#L162-L196
11,238
emmetio/emmet
lib/parser/css.js
tokener
function tokener(value, type) { session.tokens.push({ value: value, type: type || value, start: null, end: null }); }
javascript
function tokener(value, type) { session.tokens.push({ value: value, type: type || value, start: null, end: null }); }
[ "function", "tokener", "(", "value", ",", "type", ")", "{", "session", ".", "tokens", ".", "push", "(", "{", "value", ":", "value", ",", "type", ":", "type", "||", "value", ",", "start", ":", "null", ",", "end", ":", "null", "}", ")", ";", "}" ]
creates token objects and pushes them to a list
[ "creates", "token", "objects", "and", "pushes", "them", "to", "a", "list" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/css.js#L76-L83
11,239
emmetio/emmet
lib/parser/css.js
tokenize
function tokenize() { var ch = walker.ch; if (ch === " " || ch === "\t") { return white(); } if (ch === '/') { return comment(); } if (ch === '"' || ch === "'") { return str(); } if (ch === '(') { return brace(); } if (ch === '-' || ch === '.' || isDigit(ch)) { // tricky - char: minus (-1px) or dash (-moz-stuff) return num(); } if (isNameChar(ch)) { return identifier(); } if (isOp(ch)) { return op(); } if (ch === '\r') { if (walker.peek() === '\n') { ch += walker.nextChar(); } tokener(ch, 'line'); walker.nextChar(); return; } if (ch === '\n') { tokener(ch, 'line'); walker.nextChar(); return; } raiseError("Unrecognized character '" + ch + "'"); }
javascript
function tokenize() { var ch = walker.ch; if (ch === " " || ch === "\t") { return white(); } if (ch === '/') { return comment(); } if (ch === '"' || ch === "'") { return str(); } if (ch === '(') { return brace(); } if (ch === '-' || ch === '.' || isDigit(ch)) { // tricky - char: minus (-1px) or dash (-moz-stuff) return num(); } if (isNameChar(ch)) { return identifier(); } if (isOp(ch)) { return op(); } if (ch === '\r') { if (walker.peek() === '\n') { ch += walker.nextChar(); } tokener(ch, 'line'); walker.nextChar(); return; } if (ch === '\n') { tokener(ch, 'line'); walker.nextChar(); return; } raiseError("Unrecognized character '" + ch + "'"); }
[ "function", "tokenize", "(", ")", "{", "var", "ch", "=", "walker", ".", "ch", ";", "if", "(", "ch", "===", "\" \"", "||", "ch", "===", "\"\\t\"", ")", "{", "return", "white", "(", ")", ";", "}", "if", "(", "ch", "===", "'/'", ")", "{", "return", "comment", "(", ")", ";", "}", "if", "(", "ch", "===", "'\"'", "||", "ch", "===", "\"'\"", ")", "{", "return", "str", "(", ")", ";", "}", "if", "(", "ch", "===", "'('", ")", "{", "return", "brace", "(", ")", ";", "}", "if", "(", "ch", "===", "'-'", "||", "ch", "===", "'.'", "||", "isDigit", "(", "ch", ")", ")", "{", "// tricky - char: minus (-1px) or dash (-moz-stuff)", "return", "num", "(", ")", ";", "}", "if", "(", "isNameChar", "(", "ch", ")", ")", "{", "return", "identifier", "(", ")", ";", "}", "if", "(", "isOp", "(", "ch", ")", ")", "{", "return", "op", "(", ")", ";", "}", "if", "(", "ch", "===", "'\\r'", ")", "{", "if", "(", "walker", ".", "peek", "(", ")", "===", "'\\n'", ")", "{", "ch", "+=", "walker", ".", "nextChar", "(", ")", ";", "}", "tokener", "(", "ch", ",", "'line'", ")", ";", "walker", ".", "nextChar", "(", ")", ";", "return", ";", "}", "if", "(", "ch", "===", "'\\n'", ")", "{", "tokener", "(", "ch", ",", "'line'", ")", ";", "walker", ".", "nextChar", "(", ")", ";", "return", ";", "}", "raiseError", "(", "\"Unrecognized character '\"", "+", "ch", "+", "\"'\"", ")", ";", "}" ]
call the appropriate handler based on the first character in a token suspect
[ "call", "the", "appropriate", "handler", "based", "on", "the", "first", "character", "in", "a", "token", "suspect" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/css.js#L324-L372
11,240
emmetio/emmet
lib/parser/css.js
function (source) { walker.init(source); session.tokens = []; // for empty source, return single space token if (!source) { session.tokens.push(this.white()); } else { while (walker.ch !== '') { tokenize(); } } var tokens = session.tokens; session.tokens = null; return tokens; }
javascript
function (source) { walker.init(source); session.tokens = []; // for empty source, return single space token if (!source) { session.tokens.push(this.white()); } else { while (walker.ch !== '') { tokenize(); } } var tokens = session.tokens; session.tokens = null; return tokens; }
[ "function", "(", "source", ")", "{", "walker", ".", "init", "(", "source", ")", ";", "session", ".", "tokens", "=", "[", "]", ";", "// for empty source, return single space token", "if", "(", "!", "source", ")", "{", "session", ".", "tokens", ".", "push", "(", "this", ".", "white", "(", ")", ")", ";", "}", "else", "{", "while", "(", "walker", ".", "ch", "!==", "''", ")", "{", "tokenize", "(", ")", ";", "}", "}", "var", "tokens", "=", "session", ".", "tokens", ";", "session", ".", "tokens", "=", "null", ";", "return", "tokens", ";", "}" ]
Sprits given source into tokens @param {String} source @returns {Array}
[ "Sprits", "given", "source", "into", "tokens" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/css.js#L380-L396
11,241
emmetio/emmet
lib/generator/lorem.js
paragraph
function paragraph(lang, wordCount, startWithCommon) { var data = langs[lang]; if (!data) { return ''; } var result = []; var totalWords = 0; var words; wordCount = parseInt(wordCount, 10); if (startWithCommon && data.common) { words = data.common.slice(0, wordCount); if (words.length > 5) { words[4] += ','; } totalWords += words.length; result.push(sentence(words, '.')); } while (totalWords < wordCount) { words = sample(data.words, Math.min(randint(2, 30), wordCount - totalWords)); totalWords += words.length; insertCommas(words); result.push(sentence(words)); } return result.join(' '); }
javascript
function paragraph(lang, wordCount, startWithCommon) { var data = langs[lang]; if (!data) { return ''; } var result = []; var totalWords = 0; var words; wordCount = parseInt(wordCount, 10); if (startWithCommon && data.common) { words = data.common.slice(0, wordCount); if (words.length > 5) { words[4] += ','; } totalWords += words.length; result.push(sentence(words, '.')); } while (totalWords < wordCount) { words = sample(data.words, Math.min(randint(2, 30), wordCount - totalWords)); totalWords += words.length; insertCommas(words); result.push(sentence(words)); } return result.join(' '); }
[ "function", "paragraph", "(", "lang", ",", "wordCount", ",", "startWithCommon", ")", "{", "var", "data", "=", "langs", "[", "lang", "]", ";", "if", "(", "!", "data", ")", "{", "return", "''", ";", "}", "var", "result", "=", "[", "]", ";", "var", "totalWords", "=", "0", ";", "var", "words", ";", "wordCount", "=", "parseInt", "(", "wordCount", ",", "10", ")", ";", "if", "(", "startWithCommon", "&&", "data", ".", "common", ")", "{", "words", "=", "data", ".", "common", ".", "slice", "(", "0", ",", "wordCount", ")", ";", "if", "(", "words", ".", "length", ">", "5", ")", "{", "words", "[", "4", "]", "+=", "','", ";", "}", "totalWords", "+=", "words", ".", "length", ";", "result", ".", "push", "(", "sentence", "(", "words", ",", "'.'", ")", ")", ";", "}", "while", "(", "totalWords", "<", "wordCount", ")", "{", "words", "=", "sample", "(", "data", ".", "words", ",", "Math", ".", "min", "(", "randint", "(", "2", ",", "30", ")", ",", "wordCount", "-", "totalWords", ")", ")", ";", "totalWords", "+=", "words", ".", "length", ";", "insertCommas", "(", "words", ")", ";", "result", ".", "push", "(", "sentence", "(", "words", ")", ")", ";", "}", "return", "result", ".", "join", "(", "' '", ")", ";", "}" ]
Generate a paragraph of "Lorem ipsum" text @param {Number} wordCount Words count in paragraph @param {Boolean} startWithCommon Should paragraph start with common "lorem ipsum" sentence. @returns {String}
[ "Generate", "a", "paragraph", "of", "Lorem", "ipsum", "text" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/generator/lorem.js#L211-L240
11,242
emmetio/emmet
lib/generator/lorem.js
function(lang, data) { if (typeof data === 'string') { data = { words: data.split(' ').filter(function(item) { return !!item; }) }; } else if (Array.isArray(data)) { data = {words: data}; } langs[lang] = data; }
javascript
function(lang, data) { if (typeof data === 'string') { data = { words: data.split(' ').filter(function(item) { return !!item; }) }; } else if (Array.isArray(data)) { data = {words: data}; } langs[lang] = data; }
[ "function", "(", "lang", ",", "data", ")", "{", "if", "(", "typeof", "data", "===", "'string'", ")", "{", "data", "=", "{", "words", ":", "data", ".", "split", "(", "' '", ")", ".", "filter", "(", "function", "(", "item", ")", "{", "return", "!", "!", "item", ";", "}", ")", "}", ";", "}", "else", "if", "(", "Array", ".", "isArray", "(", "data", ")", ")", "{", "data", "=", "{", "words", ":", "data", "}", ";", "}", "langs", "[", "lang", "]", "=", "data", ";", "}" ]
Adds new language words for Lorem Ipsum generator @param {String} lang Two-letter lang definition @param {Object} data Words for language. Maight be either a space-separated list of words (String), Array of words or object with <code>text</code> and <code>common</code> properties
[ "Adds", "new", "language", "words", "for", "Lorem", "Ipsum", "generator" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/generator/lorem.js#L250-L262
11,243
emmetio/emmet
lib/plugin/file.js
function(path, size, callback) { var params = this._parseParams(arguments); this._read(params, function(err, buf) { params.callback(err, err ? '' : bts(buf)); }); }
javascript
function(path, size, callback) { var params = this._parseParams(arguments); this._read(params, function(err, buf) { params.callback(err, err ? '' : bts(buf)); }); }
[ "function", "(", "path", ",", "size", ",", "callback", ")", "{", "var", "params", "=", "this", ".", "_parseParams", "(", "arguments", ")", ";", "this", ".", "_read", "(", "params", ",", "function", "(", "err", ",", "buf", ")", "{", "params", ".", "callback", "(", "err", ",", "err", "?", "''", ":", "bts", "(", "buf", ")", ")", ";", "}", ")", ";", "}" ]
Reads binary file content and return it @param {String} path File's relative or absolute path @return {String}
[ "Reads", "binary", "file", "content", "and", "return", "it" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/plugin/file.js#L116-L121
11,244
emmetio/emmet
lib/action/lineBreaks.js
function(editor) { var info = editorUtils.outputInfo(editor); var caretPos = editor.getCaretPos(); var nl = '\n'; var pad = '\t'; if (~xmlSyntaxes.indexOf(info.syntax)) { // let's see if we're breaking newly created tag var tag = htmlMatcher.tag(info.content, caretPos); if (tag && !tag.innerRange.length()) { editor.replaceContent(nl + pad + utils.getCaretPlaceholder() + nl, caretPos); return true; } } else if (info.syntax == 'css') { /** @type String */ var content = info.content; if (caretPos && content.charAt(caretPos - 1) == '{') { var append = prefs.get('css.closeBraceIndentation'); var hasCloseBrace = content.charAt(caretPos) == '}'; if (!hasCloseBrace) { // do we really need special formatting here? // check if this is really a newly created rule, // look ahead for a closing brace for (var i = caretPos, il = content.length, ch; i < il; i++) { ch = content.charAt(i); if (ch == '{') { // ok, this is a new rule without closing brace break; } if (ch == '}') { // not a new rule, just add indentation append = ''; hasCloseBrace = true; break; } } } if (!hasCloseBrace) { append += '}'; } // defining rule set var insValue = nl + pad + utils.getCaretPlaceholder() + append; editor.replaceContent(insValue, caretPos); return true; } } return false; }
javascript
function(editor) { var info = editorUtils.outputInfo(editor); var caretPos = editor.getCaretPos(); var nl = '\n'; var pad = '\t'; if (~xmlSyntaxes.indexOf(info.syntax)) { // let's see if we're breaking newly created tag var tag = htmlMatcher.tag(info.content, caretPos); if (tag && !tag.innerRange.length()) { editor.replaceContent(nl + pad + utils.getCaretPlaceholder() + nl, caretPos); return true; } } else if (info.syntax == 'css') { /** @type String */ var content = info.content; if (caretPos && content.charAt(caretPos - 1) == '{') { var append = prefs.get('css.closeBraceIndentation'); var hasCloseBrace = content.charAt(caretPos) == '}'; if (!hasCloseBrace) { // do we really need special formatting here? // check if this is really a newly created rule, // look ahead for a closing brace for (var i = caretPos, il = content.length, ch; i < il; i++) { ch = content.charAt(i); if (ch == '{') { // ok, this is a new rule without closing brace break; } if (ch == '}') { // not a new rule, just add indentation append = ''; hasCloseBrace = true; break; } } } if (!hasCloseBrace) { append += '}'; } // defining rule set var insValue = nl + pad + utils.getCaretPlaceholder() + append; editor.replaceContent(insValue, caretPos); return true; } } return false; }
[ "function", "(", "editor", ")", "{", "var", "info", "=", "editorUtils", ".", "outputInfo", "(", "editor", ")", ";", "var", "caretPos", "=", "editor", ".", "getCaretPos", "(", ")", ";", "var", "nl", "=", "'\\n'", ";", "var", "pad", "=", "'\\t'", ";", "if", "(", "~", "xmlSyntaxes", ".", "indexOf", "(", "info", ".", "syntax", ")", ")", "{", "// let's see if we're breaking newly created tag", "var", "tag", "=", "htmlMatcher", ".", "tag", "(", "info", ".", "content", ",", "caretPos", ")", ";", "if", "(", "tag", "&&", "!", "tag", ".", "innerRange", ".", "length", "(", ")", ")", "{", "editor", ".", "replaceContent", "(", "nl", "+", "pad", "+", "utils", ".", "getCaretPlaceholder", "(", ")", "+", "nl", ",", "caretPos", ")", ";", "return", "true", ";", "}", "}", "else", "if", "(", "info", ".", "syntax", "==", "'css'", ")", "{", "/** @type String */", "var", "content", "=", "info", ".", "content", ";", "if", "(", "caretPos", "&&", "content", ".", "charAt", "(", "caretPos", "-", "1", ")", "==", "'{'", ")", "{", "var", "append", "=", "prefs", ".", "get", "(", "'css.closeBraceIndentation'", ")", ";", "var", "hasCloseBrace", "=", "content", ".", "charAt", "(", "caretPos", ")", "==", "'}'", ";", "if", "(", "!", "hasCloseBrace", ")", "{", "// do we really need special formatting here?", "// check if this is really a newly created rule,", "// look ahead for a closing brace", "for", "(", "var", "i", "=", "caretPos", ",", "il", "=", "content", ".", "length", ",", "ch", ";", "i", "<", "il", ";", "i", "++", ")", "{", "ch", "=", "content", ".", "charAt", "(", "i", ")", ";", "if", "(", "ch", "==", "'{'", ")", "{", "// ok, this is a new rule without closing brace", "break", ";", "}", "if", "(", "ch", "==", "'}'", ")", "{", "// not a new rule, just add indentation", "append", "=", "''", ";", "hasCloseBrace", "=", "true", ";", "break", ";", "}", "}", "}", "if", "(", "!", "hasCloseBrace", ")", "{", "append", "+=", "'}'", ";", "}", "// defining rule set", "var", "insValue", "=", "nl", "+", "pad", "+", "utils", ".", "getCaretPlaceholder", "(", ")", "+", "append", ";", "editor", ".", "replaceContent", "(", "insValue", ",", "caretPos", ")", ";", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Inserts newline character with proper indentation in specific positions only. @param {IEmmetEditor} editor @return {Boolean} Returns <code>true</code> if line break was inserted
[ "Inserts", "newline", "character", "with", "proper", "indentation", "in", "specific", "positions", "only", "." ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/lineBreaks.js#L72-L124
11,245
emmetio/emmet
lib/editTree/base.js
EditContainer
function EditContainer(source, options) { this.options = utils.extend({offset: 0}, options); /** * Source code of edited structure. All changes in the structure are * immediately reflected into this property */ this.source = source; /** * List of all editable children * @private */ this._children = []; /** * Hash of all positions of container * @private */ this._positions = { name: 0 }; this.initialize.apply(this, arguments); }
javascript
function EditContainer(source, options) { this.options = utils.extend({offset: 0}, options); /** * Source code of edited structure. All changes in the structure are * immediately reflected into this property */ this.source = source; /** * List of all editable children * @private */ this._children = []; /** * Hash of all positions of container * @private */ this._positions = { name: 0 }; this.initialize.apply(this, arguments); }
[ "function", "EditContainer", "(", "source", ",", "options", ")", "{", "this", ".", "options", "=", "utils", ".", "extend", "(", "{", "offset", ":", "0", "}", ",", "options", ")", ";", "/**\n\t\t * Source code of edited structure. All changes in the structure are \n\t\t * immediately reflected into this property\n\t\t */", "this", ".", "source", "=", "source", ";", "/** \n\t\t * List of all editable children\n\t\t * @private \n\t\t */", "this", ".", "_children", "=", "[", "]", ";", "/**\n\t\t * Hash of all positions of container\n\t\t * @private\n\t\t */", "this", ".", "_positions", "=", "{", "name", ":", "0", "}", ";", "this", ".", "initialize", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}" ]
Named container of edited source @type EditContainer @param {String} source @param {Object} options
[ "Named", "container", "of", "edited", "source" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L44-L67
11,246
emmetio/emmet
lib/editTree/base.js
function(value, start, end) { // create modification range var r = range.create(start, typeof end === 'undefined' ? 0 : end - start); var delta = value.length - r.length(); var update = function(obj) { Object.keys(obj).forEach(function(k) { if (obj[k] >= r.end) { obj[k] += delta; } }); }; // update affected positions of current container update(this._positions); // update affected positions of children var recursiveUpdate = function(items) { items.forEach(function(item) { update(item._positions); if (item.type == 'container') { recursiveUpdate(item.list()); } }); }; recursiveUpdate(this.list()); this.source = utils.replaceSubstring(this.source, value, r); }
javascript
function(value, start, end) { // create modification range var r = range.create(start, typeof end === 'undefined' ? 0 : end - start); var delta = value.length - r.length(); var update = function(obj) { Object.keys(obj).forEach(function(k) { if (obj[k] >= r.end) { obj[k] += delta; } }); }; // update affected positions of current container update(this._positions); // update affected positions of children var recursiveUpdate = function(items) { items.forEach(function(item) { update(item._positions); if (item.type == 'container') { recursiveUpdate(item.list()); } }); }; recursiveUpdate(this.list()); this.source = utils.replaceSubstring(this.source, value, r); }
[ "function", "(", "value", ",", "start", ",", "end", ")", "{", "// create modification range", "var", "r", "=", "range", ".", "create", "(", "start", ",", "typeof", "end", "===", "'undefined'", "?", "0", ":", "end", "-", "start", ")", ";", "var", "delta", "=", "value", ".", "length", "-", "r", ".", "length", "(", ")", ";", "var", "update", "=", "function", "(", "obj", ")", "{", "Object", ".", "keys", "(", "obj", ")", ".", "forEach", "(", "function", "(", "k", ")", "{", "if", "(", "obj", "[", "k", "]", ">=", "r", ".", "end", ")", "{", "obj", "[", "k", "]", "+=", "delta", ";", "}", "}", ")", ";", "}", ";", "// update affected positions of current container", "update", "(", "this", ".", "_positions", ")", ";", "// update affected positions of children", "var", "recursiveUpdate", "=", "function", "(", "items", ")", "{", "items", ".", "forEach", "(", "function", "(", "item", ")", "{", "update", "(", "item", ".", "_positions", ")", ";", "if", "(", "item", ".", "type", "==", "'container'", ")", "{", "recursiveUpdate", "(", "item", ".", "list", "(", ")", ")", ";", "}", "}", ")", ";", "}", ";", "recursiveUpdate", "(", "this", ".", "list", "(", ")", ")", ";", "this", ".", "source", "=", "utils", ".", "replaceSubstring", "(", "this", ".", "source", ",", "value", ",", "r", ")", ";", "}" ]
Replace substring of tag's source @param {String} value @param {Number} start @param {Number} end @private
[ "Replace", "substring", "of", "tag", "s", "source" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L100-L128
11,247
emmetio/emmet
lib/editTree/base.js
function(items) { items.forEach(function(item) { update(item._positions); if (item.type == 'container') { recursiveUpdate(item.list()); } }); }
javascript
function(items) { items.forEach(function(item) { update(item._positions); if (item.type == 'container') { recursiveUpdate(item.list()); } }); }
[ "function", "(", "items", ")", "{", "items", ".", "forEach", "(", "function", "(", "item", ")", "{", "update", "(", "item", ".", "_positions", ")", ";", "if", "(", "item", ".", "type", "==", "'container'", ")", "{", "recursiveUpdate", "(", "item", ".", "list", "(", ")", ")", ";", "}", "}", ")", ";", "}" ]
update affected positions of children
[ "update", "affected", "positions", "of", "children" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L117-L124
11,248
emmetio/emmet
lib/editTree/base.js
function(name, value, pos) { // this is abstract implementation var item = new EditElement(name, value); this._children.push(item); return item; }
javascript
function(name, value, pos) { // this is abstract implementation var item = new EditElement(name, value); this._children.push(item); return item; }
[ "function", "(", "name", ",", "value", ",", "pos", ")", "{", "// this is abstract implementation", "var", "item", "=", "new", "EditElement", "(", "name", ",", "value", ")", ";", "this", ".", "_children", ".", "push", "(", "item", ")", ";", "return", "item", ";", "}" ]
Adds new attribute @param {String} name Property name @param {String} value Property value @param {Number} pos Position at which to insert new property. By default the property is inserted at the end of rule @returns {EditElement} Newly created element
[ "Adds", "new", "attribute" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L139-L144
11,249
emmetio/emmet
lib/editTree/base.js
function(name) { if (typeof name === 'number') { return this.list()[name]; } if (typeof name === 'string') { return utils.find(this.list(), function(prop) { return prop.name() === name; }); } return name; }
javascript
function(name) { if (typeof name === 'number') { return this.list()[name]; } if (typeof name === 'string') { return utils.find(this.list(), function(prop) { return prop.name() === name; }); } return name; }
[ "function", "(", "name", ")", "{", "if", "(", "typeof", "name", "===", "'number'", ")", "{", "return", "this", ".", "list", "(", ")", "[", "name", "]", ";", "}", "if", "(", "typeof", "name", "===", "'string'", ")", "{", "return", "utils", ".", "find", "(", "this", ".", "list", "(", ")", ",", "function", "(", "prop", ")", "{", "return", "prop", ".", "name", "(", ")", "===", "name", ";", "}", ")", ";", "}", "return", "name", ";", "}" ]
Returns attribute object @param {String} name Attribute name or its index @returns {EditElement}
[ "Returns", "attribute", "object" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L151-L163
11,250
emmetio/emmet
lib/editTree/base.js
function(name) { if (!Array.isArray(name)) name = [name]; // split names and indexes var names = [], indexes = []; name.forEach(function(item) { if (typeof item === 'string') { names.push(item); } else if (typeof item === 'number') { indexes.push(item); } }); return this.list().filter(function(attribute, i) { return ~indexes.indexOf(i) || ~names.indexOf(attribute.name()); }); }
javascript
function(name) { if (!Array.isArray(name)) name = [name]; // split names and indexes var names = [], indexes = []; name.forEach(function(item) { if (typeof item === 'string') { names.push(item); } else if (typeof item === 'number') { indexes.push(item); } }); return this.list().filter(function(attribute, i) { return ~indexes.indexOf(i) || ~names.indexOf(attribute.name()); }); }
[ "function", "(", "name", ")", "{", "if", "(", "!", "Array", ".", "isArray", "(", "name", ")", ")", "name", "=", "[", "name", "]", ";", "// split names and indexes", "var", "names", "=", "[", "]", ",", "indexes", "=", "[", "]", ";", "name", ".", "forEach", "(", "function", "(", "item", ")", "{", "if", "(", "typeof", "item", "===", "'string'", ")", "{", "names", ".", "push", "(", "item", ")", ";", "}", "else", "if", "(", "typeof", "item", "===", "'number'", ")", "{", "indexes", ".", "push", "(", "item", ")", ";", "}", "}", ")", ";", "return", "this", ".", "list", "(", ")", ".", "filter", "(", "function", "(", "attribute", ",", "i", ")", "{", "return", "~", "indexes", ".", "indexOf", "(", "i", ")", "||", "~", "names", ".", "indexOf", "(", "attribute", ".", "name", "(", ")", ")", ";", "}", ")", ";", "}" ]
Returns all children by name or indexes @param {Object} name Element name(s) or indexes (<code>String</code>, <code>Array</code>, <code>Number</code>) @returns {Array}
[ "Returns", "all", "children", "by", "name", "or", "indexes" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L171-L188
11,251
emmetio/emmet
lib/editTree/base.js
function(name) { var element = this.get(name); if (element) { this._updateSource('', element.fullRange()); var ix = this._children.indexOf(element); if (~ix) { this._children.splice(ix, 1); } } }
javascript
function(name) { var element = this.get(name); if (element) { this._updateSource('', element.fullRange()); var ix = this._children.indexOf(element); if (~ix) { this._children.splice(ix, 1); } } }
[ "function", "(", "name", ")", "{", "var", "element", "=", "this", ".", "get", "(", "name", ")", ";", "if", "(", "element", ")", "{", "this", ".", "_updateSource", "(", "''", ",", "element", ".", "fullRange", "(", ")", ")", ";", "var", "ix", "=", "this", ".", "_children", ".", "indexOf", "(", "element", ")", ";", "if", "(", "~", "ix", ")", "{", "this", ".", "_children", ".", "splice", "(", "ix", ",", "1", ")", ";", "}", "}", "}" ]
Remove child element @param {String} name Property name or its index
[ "Remove", "child", "element" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L202-L211
11,252
emmetio/emmet
lib/editTree/base.js
function(name, value, pos) { var element = this.get(name); if (element) return element.value(value); if (typeof value !== 'undefined') { // no such element — create it return this.add(name, value, pos); } }
javascript
function(name, value, pos) { var element = this.get(name); if (element) return element.value(value); if (typeof value !== 'undefined') { // no such element — create it return this.add(name, value, pos); } }
[ "function", "(", "name", ",", "value", ",", "pos", ")", "{", "var", "element", "=", "this", ".", "get", "(", "name", ")", ";", "if", "(", "element", ")", "return", "element", ".", "value", "(", "value", ")", ";", "if", "(", "typeof", "value", "!==", "'undefined'", ")", "{", "// no such element — create it", "return", "this", ".", "add", "(", "name", ",", "value", ",", "pos", ")", ";", "}", "}" ]
Returns or updates element value. If such element doesn't exists, it will be created automatically and added at the end of child list. @param {String} name Element name or its index @param {String} value New element value @returns {String}
[ "Returns", "or", "updates", "element", "value", ".", "If", "such", "element", "doesn", "t", "exists", "it", "will", "be", "created", "automatically", "and", "added", "at", "the", "end", "of", "child", "list", "." ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L229-L238
11,253
emmetio/emmet
lib/editTree/base.js
function(val) { if (typeof val !== 'undefined' && this._name !== (val = String(val))) { this._updateSource(val, this._positions.name, this._positions.name + this._name.length); this._name = val; } return this._name; }
javascript
function(val) { if (typeof val !== 'undefined' && this._name !== (val = String(val))) { this._updateSource(val, this._positions.name, this._positions.name + this._name.length); this._name = val; } return this._name; }
[ "function", "(", "val", ")", "{", "if", "(", "typeof", "val", "!==", "'undefined'", "&&", "this", ".", "_name", "!==", "(", "val", "=", "String", "(", "val", ")", ")", ")", "{", "this", ".", "_updateSource", "(", "val", ",", "this", ".", "_positions", ".", "name", ",", "this", ".", "_positions", ".", "name", "+", "this", ".", "_name", ".", "length", ")", ";", "this", ".", "_name", "=", "val", ";", "}", "return", "this", ".", "_name", ";", "}" ]
Sets or gets container name @param {String} val New name. If not passed, current name is returned @return {String}
[ "Sets", "or", "gets", "container", "name" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L259-L266
11,254
emmetio/emmet
lib/editTree/base.js
function(pos, isAbsolute) { return utils.find(this.list(), function(elem) { return elem.range(isAbsolute).inside(pos); }); }
javascript
function(pos, isAbsolute) { return utils.find(this.list(), function(elem) { return elem.range(isAbsolute).inside(pos); }); }
[ "function", "(", "pos", ",", "isAbsolute", ")", "{", "return", "utils", ".", "find", "(", "this", ".", "list", "(", ")", ",", "function", "(", "elem", ")", "{", "return", "elem", ".", "range", "(", "isAbsolute", ")", ".", "inside", "(", "pos", ")", ";", "}", ")", ";", "}" ]
Returns element that belongs to specified position @param {Number} pos @param {Boolean} isAbsolute @returns {EditElement}
[ "Returns", "element", "that", "belongs", "to", "specified", "position" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L292-L296
11,255
emmetio/emmet
lib/editTree/base.js
function(val) { if (typeof val !== 'undefined' && this._value !== (val = String(val))) { this.parent._updateSource(val, this.valueRange()); this._value = val; } return this._value; }
javascript
function(val) { if (typeof val !== 'undefined' && this._value !== (val = String(val))) { this.parent._updateSource(val, this.valueRange()); this._value = val; } return this._value; }
[ "function", "(", "val", ")", "{", "if", "(", "typeof", "val", "!==", "'undefined'", "&&", "this", ".", "_value", "!==", "(", "val", "=", "String", "(", "val", ")", ")", ")", "{", "this", ".", "parent", ".", "_updateSource", "(", "val", ",", "this", ".", "valueRange", "(", ")", ")", ";", "this", ".", "_value", "=", "val", ";", "}", "return", "this", ".", "_value", ";", "}" ]
Sets of gets element value @param {String} val New element value. If not passed, current value is returned @returns {String}
[ "Sets", "of", "gets", "element", "value" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L362-L369
11,256
emmetio/emmet
lib/editTree/base.js
function(val) { if (typeof val !== 'undefined' && this._name !== (val = String(val))) { this.parent._updateSource(val, this.nameRange()); this._name = val; } return this._name; }
javascript
function(val) { if (typeof val !== 'undefined' && this._name !== (val = String(val))) { this.parent._updateSource(val, this.nameRange()); this._name = val; } return this._name; }
[ "function", "(", "val", ")", "{", "if", "(", "typeof", "val", "!==", "'undefined'", "&&", "this", ".", "_name", "!==", "(", "val", "=", "String", "(", "val", ")", ")", ")", "{", "this", ".", "parent", ".", "_updateSource", "(", "val", ",", "this", ".", "nameRange", "(", ")", ")", ";", "this", ".", "_name", "=", "val", ";", "}", "return", "this", ".", "_name", ";", "}" ]
Sets of gets element name @param {String} val New element name. If not passed, current name is returned @returns {String}
[ "Sets", "of", "gets", "element", "name" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/editTree/base.js#L377-L384
11,257
emmetio/emmet
lib/resolver/gradient/linear.js
function(colorStop) { colorStop = normalizeSpace(colorStop); // find color declaration // first, try complex color declaration, like rgb(0,0,0) var color = null; colorStop = colorStop.replace(/^(\w+\(.+?\))\s*/, function(str, c) { color = c; return ''; }); if (!color) { // try simple declaration, like yellow, #fco, #ffffff, etc. var parts = colorStop.split(' '); color = parts[0]; colorStop = parts[1] || ''; } var result = { color: color }; if (colorStop) { // there's position in color stop definition colorStop.replace(/^(\-?[\d\.]+)([a-z%]+)?$/, function(str, pos, unit) { result.position = pos; if (~pos.indexOf('.')) { unit = ''; } else if (!unit) { unit = '%'; } if (unit) { result.unit = unit; } }); } return result; }
javascript
function(colorStop) { colorStop = normalizeSpace(colorStop); // find color declaration // first, try complex color declaration, like rgb(0,0,0) var color = null; colorStop = colorStop.replace(/^(\w+\(.+?\))\s*/, function(str, c) { color = c; return ''; }); if (!color) { // try simple declaration, like yellow, #fco, #ffffff, etc. var parts = colorStop.split(' '); color = parts[0]; colorStop = parts[1] || ''; } var result = { color: color }; if (colorStop) { // there's position in color stop definition colorStop.replace(/^(\-?[\d\.]+)([a-z%]+)?$/, function(str, pos, unit) { result.position = pos; if (~pos.indexOf('.')) { unit = ''; } else if (!unit) { unit = '%'; } if (unit) { result.unit = unit; } }); } return result; }
[ "function", "(", "colorStop", ")", "{", "colorStop", "=", "normalizeSpace", "(", "colorStop", ")", ";", "// find color declaration", "// first, try complex color declaration, like rgb(0,0,0)", "var", "color", "=", "null", ";", "colorStop", "=", "colorStop", ".", "replace", "(", "/", "^(\\w+\\(.+?\\))\\s*", "/", ",", "function", "(", "str", ",", "c", ")", "{", "color", "=", "c", ";", "return", "''", ";", "}", ")", ";", "if", "(", "!", "color", ")", "{", "// try simple declaration, like yellow, #fco, #ffffff, etc.", "var", "parts", "=", "colorStop", ".", "split", "(", "' '", ")", ";", "color", "=", "parts", "[", "0", "]", ";", "colorStop", "=", "parts", "[", "1", "]", "||", "''", ";", "}", "var", "result", "=", "{", "color", ":", "color", "}", ";", "if", "(", "colorStop", ")", "{", "// there's position in color stop definition", "colorStop", ".", "replace", "(", "/", "^(\\-?[\\d\\.]+)([a-z%]+)?$", "/", ",", "function", "(", "str", ",", "pos", ",", "unit", ")", "{", "result", ".", "position", "=", "pos", ";", "if", "(", "~", "pos", ".", "indexOf", "(", "'.'", ")", ")", "{", "unit", "=", "''", ";", "}", "else", "if", "(", "!", "unit", ")", "{", "unit", "=", "'%'", ";", "}", "if", "(", "unit", ")", "{", "result", ".", "unit", "=", "unit", ";", "}", "}", ")", ";", "}", "return", "result", ";", "}" ]
Parses color stop definition @param {String} colorStop @returns {Object}
[ "Parses", "color", "stop", "definition" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/resolver/gradient/linear.js#L94-L133
11,258
emmetio/emmet
lib/resolver/gradient/linear.js
function(colorStops) { var from = 0; colorStops.forEach(function(cs, i) { // make sure that first and last positions are defined if (!i) { return cs.position = cs.position || 0; } if (i == colorStops.length - 1 && !('position' in cs)) { cs.position = 1; } if ('position' in cs) { var start = colorStops[from].position || 0; var step = (cs.position - start) / (i - from); colorStops.slice(from, i).forEach(function(cs2, j) { cs2.position = start + step * j; }); from = i; } }); }
javascript
function(colorStops) { var from = 0; colorStops.forEach(function(cs, i) { // make sure that first and last positions are defined if (!i) { return cs.position = cs.position || 0; } if (i == colorStops.length - 1 && !('position' in cs)) { cs.position = 1; } if ('position' in cs) { var start = colorStops[from].position || 0; var step = (cs.position - start) / (i - from); colorStops.slice(from, i).forEach(function(cs2, j) { cs2.position = start + step * j; }); from = i; } }); }
[ "function", "(", "colorStops", ")", "{", "var", "from", "=", "0", ";", "colorStops", ".", "forEach", "(", "function", "(", "cs", ",", "i", ")", "{", "// make sure that first and last positions are defined", "if", "(", "!", "i", ")", "{", "return", "cs", ".", "position", "=", "cs", ".", "position", "||", "0", ";", "}", "if", "(", "i", "==", "colorStops", ".", "length", "-", "1", "&&", "!", "(", "'position'", "in", "cs", ")", ")", "{", "cs", ".", "position", "=", "1", ";", "}", "if", "(", "'position'", "in", "cs", ")", "{", "var", "start", "=", "colorStops", "[", "from", "]", ".", "position", "||", "0", ";", "var", "step", "=", "(", "cs", ".", "position", "-", "start", ")", "/", "(", "i", "-", "from", ")", ";", "colorStops", ".", "slice", "(", "from", ",", "i", ")", ".", "forEach", "(", "function", "(", "cs2", ",", "j", ")", "{", "cs2", ".", "position", "=", "start", "+", "step", "*", "j", ";", "}", ")", ";", "from", "=", "i", ";", "}", "}", ")", ";", "}" ]
Fills-out implied positions in color-stops. This function is useful for old Webkit gradient definitions
[ "Fills", "-", "out", "implied", "positions", "in", "color", "-", "stops", ".", "This", "function", "is", "useful", "for", "old", "Webkit", "gradient", "definitions" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/resolver/gradient/linear.js#L199-L222
11,259
emmetio/emmet
lib/resolver/gradient/linear.js
resolveDirection
function resolveDirection(dir) { if (typeof dir == 'number') { return dir; } dir = normalizeSpace(dir).toLowerCase(); if (reDeg.test(dir)) { return +RegExp.$1; } var prefix = /^to\s/.test(dir) ? 'to ' : ''; var left = ~dir.indexOf('left') && 'left'; var right = ~dir.indexOf('right') && 'right'; var top = ~dir.indexOf('top') && 'top'; var bottom = ~dir.indexOf('bottom') && 'bottom'; var key = normalizeSpace(prefix + (top || bottom || '') + ' ' + (left || right || '')); return directions[key] || 0; }
javascript
function resolveDirection(dir) { if (typeof dir == 'number') { return dir; } dir = normalizeSpace(dir).toLowerCase(); if (reDeg.test(dir)) { return +RegExp.$1; } var prefix = /^to\s/.test(dir) ? 'to ' : ''; var left = ~dir.indexOf('left') && 'left'; var right = ~dir.indexOf('right') && 'right'; var top = ~dir.indexOf('top') && 'top'; var bottom = ~dir.indexOf('bottom') && 'bottom'; var key = normalizeSpace(prefix + (top || bottom || '') + ' ' + (left || right || '')); return directions[key] || 0; }
[ "function", "resolveDirection", "(", "dir", ")", "{", "if", "(", "typeof", "dir", "==", "'number'", ")", "{", "return", "dir", ";", "}", "dir", "=", "normalizeSpace", "(", "dir", ")", ".", "toLowerCase", "(", ")", ";", "if", "(", "reDeg", ".", "test", "(", "dir", ")", ")", "{", "return", "+", "RegExp", ".", "$1", ";", "}", "var", "prefix", "=", "/", "^to\\s", "/", ".", "test", "(", "dir", ")", "?", "'to '", ":", "''", ";", "var", "left", "=", "~", "dir", ".", "indexOf", "(", "'left'", ")", "&&", "'left'", ";", "var", "right", "=", "~", "dir", ".", "indexOf", "(", "'right'", ")", "&&", "'right'", ";", "var", "top", "=", "~", "dir", ".", "indexOf", "(", "'top'", ")", "&&", "'top'", ";", "var", "bottom", "=", "~", "dir", ".", "indexOf", "(", "'bottom'", ")", "&&", "'bottom'", ";", "var", "key", "=", "normalizeSpace", "(", "prefix", "+", "(", "top", "||", "bottom", "||", "''", ")", "+", "' '", "+", "(", "left", "||", "right", "||", "''", ")", ")", ";", "return", "directions", "[", "key", "]", "||", "0", ";", "}" ]
Resolves textual direction to degrees @param {String} dir Direction to resolve @return {Number}
[ "Resolves", "textual", "direction", "to", "degrees" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/resolver/gradient/linear.js#L238-L256
11,260
emmetio/emmet
lib/resolver/gradient/linear.js
stringifyDirection
function stringifyDirection(dir, oldStyle) { var reNewStyle = /^to\s/; var keys = Object.keys(directions).filter(function(k) { var hasPrefix = reNewStyle.test(k); return oldStyle ? !hasPrefix : hasPrefix; }); for (var i = 0; i < keys.length; i++) { if (directions[keys[i]] == dir) { return keys[i]; } } if (oldStyle) { dir = (dir + 270) % 360; } return dir + 'deg'; }
javascript
function stringifyDirection(dir, oldStyle) { var reNewStyle = /^to\s/; var keys = Object.keys(directions).filter(function(k) { var hasPrefix = reNewStyle.test(k); return oldStyle ? !hasPrefix : hasPrefix; }); for (var i = 0; i < keys.length; i++) { if (directions[keys[i]] == dir) { return keys[i]; } } if (oldStyle) { dir = (dir + 270) % 360; } return dir + 'deg'; }
[ "function", "stringifyDirection", "(", "dir", ",", "oldStyle", ")", "{", "var", "reNewStyle", "=", "/", "^to\\s", "/", ";", "var", "keys", "=", "Object", ".", "keys", "(", "directions", ")", ".", "filter", "(", "function", "(", "k", ")", "{", "var", "hasPrefix", "=", "reNewStyle", ".", "test", "(", "k", ")", ";", "return", "oldStyle", "?", "!", "hasPrefix", ":", "hasPrefix", ";", "}", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "keys", ".", "length", ";", "i", "++", ")", "{", "if", "(", "directions", "[", "keys", "[", "i", "]", "]", "==", "dir", ")", "{", "return", "keys", "[", "i", "]", ";", "}", "}", "if", "(", "oldStyle", ")", "{", "dir", "=", "(", "dir", "+", "270", ")", "%", "360", ";", "}", "return", "dir", "+", "'deg'", ";", "}" ]
Tries to find keyword for given direction, expressed in degrees @param {Number} dir Direction (degrees) @param {Boolean} oldStyle Use old style keywords (e.g. "top" instead of "to bottom") @return {String} Keyword or <code>Ndeg</code> expression
[ "Tries", "to", "find", "keyword", "for", "given", "direction", "expressed", "in", "degrees" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/resolver/gradient/linear.js#L264-L282
11,261
emmetio/emmet
lib/resolver/gradient/linear.js
function(gradient) { // cut out all redundant data if (this.isLinearGradient(gradient)) { gradient = gradient.replace(/^\s*[\-a-z]+\s*\(|\)\s*$/ig, ''); } else { throw 'Invalid linear gradient definition:\n' + gradient; } return new LinearGradient(gradient); }
javascript
function(gradient) { // cut out all redundant data if (this.isLinearGradient(gradient)) { gradient = gradient.replace(/^\s*[\-a-z]+\s*\(|\)\s*$/ig, ''); } else { throw 'Invalid linear gradient definition:\n' + gradient; } return new LinearGradient(gradient); }
[ "function", "(", "gradient", ")", "{", "// cut out all redundant data", "if", "(", "this", ".", "isLinearGradient", "(", "gradient", ")", ")", "{", "gradient", "=", "gradient", ".", "replace", "(", "/", "^\\s*[\\-a-z]+\\s*\\(|\\)\\s*$", "/", "ig", ",", "''", ")", ";", "}", "else", "{", "throw", "'Invalid linear gradient definition:\\n'", "+", "gradient", ";", "}", "return", "new", "LinearGradient", "(", "gradient", ")", ";", "}" ]
Parses gradient definition into an object. This object can be used to transform gradient into various forms @param {String} gradient Gradient definition @return {LinearGradient}
[ "Parses", "gradient", "definition", "into", "an", "object", ".", "This", "object", "can", "be", "used", "to", "transform", "gradient", "into", "various", "forms" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/resolver/gradient/linear.js#L311-L320
11,262
emmetio/emmet
lib/assets/resources.js
parseAbbreviation
function parseAbbreviation(key, value) { key = utils.trim(key); var m; if ((m = reTag.exec(value))) { return elements.create('element', m[1], m[2], m[4] == '/'); } else { // assume it's reference to another abbreviation return elements.create('reference', value); } }
javascript
function parseAbbreviation(key, value) { key = utils.trim(key); var m; if ((m = reTag.exec(value))) { return elements.create('element', m[1], m[2], m[4] == '/'); } else { // assume it's reference to another abbreviation return elements.create('reference', value); } }
[ "function", "parseAbbreviation", "(", "key", ",", "value", ")", "{", "key", "=", "utils", ".", "trim", "(", "key", ")", ";", "var", "m", ";", "if", "(", "(", "m", "=", "reTag", ".", "exec", "(", "value", ")", ")", ")", "{", "return", "elements", ".", "create", "(", "'element'", ",", "m", "[", "1", "]", ",", "m", "[", "2", "]", ",", "m", "[", "4", "]", "==", "'/'", ")", ";", "}", "else", "{", "// assume it's reference to another abbreviation", "return", "elements", ".", "create", "(", "'reference'", ",", "value", ")", ";", "}", "}" ]
Parses single abbreviation @param {String} key Abbreviation name @param {String} value Abbreviation value @return {Object}
[ "Parses", "single", "abbreviation" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/resources.js#L75-L84
11,263
emmetio/emmet
lib/assets/resources.js
function(data, type) { cache = {}; // sections like "snippets" and "abbreviations" could have // definitions like `"f|fs": "fieldset"` which is the same as distinct // "f" and "fs" keys both equals to "fieldset". // We should parse these definitions first var voc = {}; each(data, function(section, syntax) { var _section = {}; each(section, function(subsection, name) { if (name == 'abbreviations' || name == 'snippets') { subsection = expandSnippetsDefinition(subsection); } _section[name] = subsection; }); voc[syntax] = _section; }); if (type == VOC_SYSTEM) { systemSettings = voc; } else { userSettings = voc; } }
javascript
function(data, type) { cache = {}; // sections like "snippets" and "abbreviations" could have // definitions like `"f|fs": "fieldset"` which is the same as distinct // "f" and "fs" keys both equals to "fieldset". // We should parse these definitions first var voc = {}; each(data, function(section, syntax) { var _section = {}; each(section, function(subsection, name) { if (name == 'abbreviations' || name == 'snippets') { subsection = expandSnippetsDefinition(subsection); } _section[name] = subsection; }); voc[syntax] = _section; }); if (type == VOC_SYSTEM) { systemSettings = voc; } else { userSettings = voc; } }
[ "function", "(", "data", ",", "type", ")", "{", "cache", "=", "{", "}", ";", "// sections like \"snippets\" and \"abbreviations\" could have", "// definitions like `\"f|fs\": \"fieldset\"` which is the same as distinct", "// \"f\" and \"fs\" keys both equals to \"fieldset\".", "// We should parse these definitions first", "var", "voc", "=", "{", "}", ";", "each", "(", "data", ",", "function", "(", "section", ",", "syntax", ")", "{", "var", "_section", "=", "{", "}", ";", "each", "(", "section", ",", "function", "(", "subsection", ",", "name", ")", "{", "if", "(", "name", "==", "'abbreviations'", "||", "name", "==", "'snippets'", ")", "{", "subsection", "=", "expandSnippetsDefinition", "(", "subsection", ")", ";", "}", "_section", "[", "name", "]", "=", "subsection", ";", "}", ")", ";", "voc", "[", "syntax", "]", "=", "_section", ";", "}", ")", ";", "if", "(", "type", "==", "VOC_SYSTEM", ")", "{", "systemSettings", "=", "voc", ";", "}", "else", "{", "userSettings", "=", "voc", ";", "}", "}" ]
Sets new unparsed data for specified settings vocabulary @param {Object} data @param {String} type Vocabulary type ('system' or 'user') @memberOf resources
[ "Sets", "new", "unparsed", "data", "for", "specified", "settings", "vocabulary" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/resources.js#L115-L141
11,264
emmetio/emmet
lib/assets/resources.js
function(name, value){ var voc = this.getVocabulary('user') || {}; if (!('variables' in voc)) voc.variables = {}; voc.variables[name] = value; this.setVocabulary(voc, 'user'); }
javascript
function(name, value){ var voc = this.getVocabulary('user') || {}; if (!('variables' in voc)) voc.variables = {}; voc.variables[name] = value; this.setVocabulary(voc, 'user'); }
[ "function", "(", "name", ",", "value", ")", "{", "var", "voc", "=", "this", ".", "getVocabulary", "(", "'user'", ")", "||", "{", "}", ";", "if", "(", "!", "(", "'variables'", "in", "voc", ")", ")", "voc", ".", "variables", "=", "{", "}", ";", "voc", ".", "variables", "[", "name", "]", "=", "value", ";", "this", ".", "setVocabulary", "(", "voc", ",", "'user'", ")", ";", "}" ]
Store runtime variable in user storage @param {String} name Variable name @param {String} value Variable value
[ "Store", "runtime", "variable", "in", "user", "storage" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/resources.js#L177-L184
11,265
emmetio/emmet
lib/assets/resources.js
function(name) { if (!name) return null; if (!(name in cache)) { cache[name] = utils.deepMerge({}, systemSettings[name], userSettings[name]); } var data = cache[name], subsections = utils.toArray(arguments, 1), key; while (data && (key = subsections.shift())) { if (key in data) { data = data[key]; } else { return null; } } return data; }
javascript
function(name) { if (!name) return null; if (!(name in cache)) { cache[name] = utils.deepMerge({}, systemSettings[name], userSettings[name]); } var data = cache[name], subsections = utils.toArray(arguments, 1), key; while (data && (key = subsections.shift())) { if (key in data) { data = data[key]; } else { return null; } } return data; }
[ "function", "(", "name", ")", "{", "if", "(", "!", "name", ")", "return", "null", ";", "if", "(", "!", "(", "name", "in", "cache", ")", ")", "{", "cache", "[", "name", "]", "=", "utils", ".", "deepMerge", "(", "{", "}", ",", "systemSettings", "[", "name", "]", ",", "userSettings", "[", "name", "]", ")", ";", "}", "var", "data", "=", "cache", "[", "name", "]", ",", "subsections", "=", "utils", ".", "toArray", "(", "arguments", ",", "1", ")", ",", "key", ";", "while", "(", "data", "&&", "(", "key", "=", "subsections", ".", "shift", "(", ")", ")", ")", "{", "if", "(", "key", "in", "data", ")", "{", "data", "=", "data", "[", "key", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}", "return", "data", ";", "}" ]
Returns actual section data, merged from both system and user data @param {String} name Section name (syntax) @param {String} ...args Subsections @returns
[ "Returns", "actual", "section", "data", "merged", "from", "both", "system", "and", "user", "data" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/resources.js#L220-L238
11,266
emmetio/emmet
lib/assets/resources.js
function(syntax, name, minScore) { var result = this.fuzzyFindMatches(syntax, name, minScore)[0]; if (result) { return result.value.parsedValue; } }
javascript
function(syntax, name, minScore) { var result = this.fuzzyFindMatches(syntax, name, minScore)[0]; if (result) { return result.value.parsedValue; } }
[ "function", "(", "syntax", ",", "name", ",", "minScore", ")", "{", "var", "result", "=", "this", ".", "fuzzyFindMatches", "(", "syntax", ",", "name", ",", "minScore", ")", "[", "0", "]", ";", "if", "(", "result", ")", "{", "return", "result", ".", "value", ".", "parsedValue", ";", "}", "}" ]
Performs fuzzy search of snippet definition @param {String} syntax Top-level section name (syntax) @param {String} name Snippet name @returns
[ "Performs", "fuzzy", "search", "of", "snippet", "definition" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/resources.js#L305-L310
11,267
emmetio/emmet
lib/assets/resources.js
function(syntax) { var cacheKey = 'all-' + syntax; if (!cache[cacheKey]) { var stack = [], sectionKey = syntax; var memo = []; do { var section = this.getSection(sectionKey); if (!section) break; ['snippets', 'abbreviations'].forEach(function(sectionName) { var stackItem = {}; each(section[sectionName] || null, function(v, k) { stackItem[k] = { nk: normalizeName(k), value: v, parsedValue: parseItem(k, v, sectionName), type: sectionName }; }); stack.push(stackItem); }); memo.push(sectionKey); sectionKey = section['extends']; } while (sectionKey && !~memo.indexOf(sectionKey)); cache[cacheKey] = utils.extend.apply(utils, stack.reverse()); } return cache[cacheKey]; }
javascript
function(syntax) { var cacheKey = 'all-' + syntax; if (!cache[cacheKey]) { var stack = [], sectionKey = syntax; var memo = []; do { var section = this.getSection(sectionKey); if (!section) break; ['snippets', 'abbreviations'].forEach(function(sectionName) { var stackItem = {}; each(section[sectionName] || null, function(v, k) { stackItem[k] = { nk: normalizeName(k), value: v, parsedValue: parseItem(k, v, sectionName), type: sectionName }; }); stack.push(stackItem); }); memo.push(sectionKey); sectionKey = section['extends']; } while (sectionKey && !~memo.indexOf(sectionKey)); cache[cacheKey] = utils.extend.apply(utils, stack.reverse()); } return cache[cacheKey]; }
[ "function", "(", "syntax", ")", "{", "var", "cacheKey", "=", "'all-'", "+", "syntax", ";", "if", "(", "!", "cache", "[", "cacheKey", "]", ")", "{", "var", "stack", "=", "[", "]", ",", "sectionKey", "=", "syntax", ";", "var", "memo", "=", "[", "]", ";", "do", "{", "var", "section", "=", "this", ".", "getSection", "(", "sectionKey", ")", ";", "if", "(", "!", "section", ")", "break", ";", "[", "'snippets'", ",", "'abbreviations'", "]", ".", "forEach", "(", "function", "(", "sectionName", ")", "{", "var", "stackItem", "=", "{", "}", ";", "each", "(", "section", "[", "sectionName", "]", "||", "null", ",", "function", "(", "v", ",", "k", ")", "{", "stackItem", "[", "k", "]", "=", "{", "nk", ":", "normalizeName", "(", "k", ")", ",", "value", ":", "v", ",", "parsedValue", ":", "parseItem", "(", "k", ",", "v", ",", "sectionName", ")", ",", "type", ":", "sectionName", "}", ";", "}", ")", ";", "stack", ".", "push", "(", "stackItem", ")", ";", "}", ")", ";", "memo", ".", "push", "(", "sectionKey", ")", ";", "sectionKey", "=", "section", "[", "'extends'", "]", ";", "}", "while", "(", "sectionKey", "&&", "!", "~", "memo", ".", "indexOf", "(", "sectionKey", ")", ")", ";", "cache", "[", "cacheKey", "]", "=", "utils", ".", "extend", ".", "apply", "(", "utils", ",", "stack", ".", "reverse", "(", ")", ")", ";", "}", "return", "cache", "[", "cacheKey", "]", ";", "}" ]
Returns plain dictionary of all available abbreviations and snippets for specified syntax with respect of inheritance @param {String} syntax @returns {Object}
[ "Returns", "plain", "dictionary", "of", "all", "available", "abbreviations", "and", "snippets", "for", "specified", "syntax", "with", "respect", "of", "inheritance" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/resources.js#L341-L375
11,268
emmetio/emmet
lib/action/expandAbbreviation.js
findAbbreviation
function findAbbreviation(editor) { var r = range(editor.getSelectionRange()); var content = String(editor.getContent()); if (r.length()) { // abbreviation is selected by user return r.substring(content); } // search for new abbreviation from current caret position var curLine = editor.getCurrentLineRange(); return actionUtils.extractAbbreviation(content.substring(curLine.start, r.start)); }
javascript
function findAbbreviation(editor) { var r = range(editor.getSelectionRange()); var content = String(editor.getContent()); if (r.length()) { // abbreviation is selected by user return r.substring(content); } // search for new abbreviation from current caret position var curLine = editor.getCurrentLineRange(); return actionUtils.extractAbbreviation(content.substring(curLine.start, r.start)); }
[ "function", "findAbbreviation", "(", "editor", ")", "{", "var", "r", "=", "range", "(", "editor", ".", "getSelectionRange", "(", ")", ")", ";", "var", "content", "=", "String", "(", "editor", ".", "getContent", "(", ")", ")", ";", "if", "(", "r", ".", "length", "(", ")", ")", "{", "// abbreviation is selected by user", "return", "r", ".", "substring", "(", "content", ")", ";", "}", "// search for new abbreviation from current caret position", "var", "curLine", "=", "editor", ".", "getCurrentLineRange", "(", ")", ";", "return", "actionUtils", ".", "extractAbbreviation", "(", "content", ".", "substring", "(", "curLine", ".", "start", ",", "r", ".", "start", ")", ")", ";", "}" ]
Search for abbreviation in editor from current caret position @param {IEmmetEditor} editor Editor instance @return {String}
[ "Search", "for", "abbreviation", "in", "editor", "from", "current", "caret", "position" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/expandAbbreviation.js#L31-L42
11,269
emmetio/emmet
lib/utils/editor.js
function(html, caretPos) { var reTag = /^<\/?\w[\w\:\-]*.*?>/; // search left to find opening brace var pos = caretPos; while (pos > -1) { if (html.charAt(pos) == '<') break; pos--; } if (pos != -1) { var m = reTag.exec(html.substring(pos)); if (m && caretPos > pos && caretPos < pos + m[0].length) return true; } return false; }
javascript
function(html, caretPos) { var reTag = /^<\/?\w[\w\:\-]*.*?>/; // search left to find opening brace var pos = caretPos; while (pos > -1) { if (html.charAt(pos) == '<') break; pos--; } if (pos != -1) { var m = reTag.exec(html.substring(pos)); if (m && caretPos > pos && caretPos < pos + m[0].length) return true; } return false; }
[ "function", "(", "html", ",", "caretPos", ")", "{", "var", "reTag", "=", "/", "^<\\/?\\w[\\w\\:\\-]*.*?>", "/", ";", "// search left to find opening brace", "var", "pos", "=", "caretPos", ";", "while", "(", "pos", ">", "-", "1", ")", "{", "if", "(", "html", ".", "charAt", "(", "pos", ")", "==", "'<'", ")", "break", ";", "pos", "--", ";", "}", "if", "(", "pos", "!=", "-", "1", ")", "{", "var", "m", "=", "reTag", ".", "exec", "(", "html", ".", "substring", "(", "pos", ")", ")", ";", "if", "(", "m", "&&", "caretPos", ">", "pos", "&&", "caretPos", "<", "pos", "+", "m", "[", "0", "]", ".", "length", ")", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if cursor is placed inside XHTML tag @param {String} html Contents of the document @param {Number} caretPos Current caret position inside tag @return {Boolean}
[ "Check", "if", "cursor", "is", "placed", "inside", "XHTML", "tag" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/editor.js#L22-L40
11,270
emmetio/emmet
lib/utils/editor.js
function(editor, syntax, profile) { // most of this code makes sense for Java/Rhino environment // because string that comes from Java are not actually JS string // but Java String object so the have to be explicitly converted // to native string profile = profile || editor.getProfileName(); return { /** @memberOf outputInfo */ syntax: String(syntax || editor.getSyntax()), profile: profile || null, content: String(editor.getContent()) }; }
javascript
function(editor, syntax, profile) { // most of this code makes sense for Java/Rhino environment // because string that comes from Java are not actually JS string // but Java String object so the have to be explicitly converted // to native string profile = profile || editor.getProfileName(); return { /** @memberOf outputInfo */ syntax: String(syntax || editor.getSyntax()), profile: profile || null, content: String(editor.getContent()) }; }
[ "function", "(", "editor", ",", "syntax", ",", "profile", ")", "{", "// most of this code makes sense for Java/Rhino environment", "// because string that comes from Java are not actually JS string", "// but Java String object so the have to be explicitly converted", "// to native string", "profile", "=", "profile", "||", "editor", ".", "getProfileName", "(", ")", ";", "return", "{", "/** @memberOf outputInfo */", "syntax", ":", "String", "(", "syntax", "||", "editor", ".", "getSyntax", "(", ")", ")", ",", "profile", ":", "profile", "||", "null", ",", "content", ":", "String", "(", "editor", ".", "getContent", "(", ")", ")", "}", ";", "}" ]
Sanitizes incoming editor data and provides default values for output-specific info @param {IEmmetEditor} editor @param {String} syntax @param {String} profile
[ "Sanitizes", "incoming", "editor", "data", "and", "provides", "default", "values", "for", "output", "-", "specific", "info" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/utils/editor.js#L49-L61
11,271
emmetio/emmet
lib/action/reflectCSSValue.js
getReflectedCSSName
function getReflectedCSSName(name) { name = cssEditTree.baseName(name); var vendorPrefix = '^(?:\\-\\w+\\-)?', m; if ((name == 'opacity' || name == 'filter') && prefs.get('css.reflect.oldIEOpacity')) { return new RegExp(vendorPrefix + '(?:opacity|filter)$'); } else if ((m = name.match(/^border-radius-(top|bottom)(left|right)/))) { // Mozilla-style border radius return new RegExp(vendorPrefix + '(?:' + name + '|border-' + m[1] + '-' + m[2] + '-radius)$'); } else if ((m = name.match(/^border-(top|bottom)-(left|right)-radius/))) { return new RegExp(vendorPrefix + '(?:' + name + '|border-radius-' + m[1] + m[2] + ')$'); } return new RegExp(vendorPrefix + name + '$'); }
javascript
function getReflectedCSSName(name) { name = cssEditTree.baseName(name); var vendorPrefix = '^(?:\\-\\w+\\-)?', m; if ((name == 'opacity' || name == 'filter') && prefs.get('css.reflect.oldIEOpacity')) { return new RegExp(vendorPrefix + '(?:opacity|filter)$'); } else if ((m = name.match(/^border-radius-(top|bottom)(left|right)/))) { // Mozilla-style border radius return new RegExp(vendorPrefix + '(?:' + name + '|border-' + m[1] + '-' + m[2] + '-radius)$'); } else if ((m = name.match(/^border-(top|bottom)-(left|right)-radius/))) { return new RegExp(vendorPrefix + '(?:' + name + '|border-radius-' + m[1] + m[2] + ')$'); } return new RegExp(vendorPrefix + name + '$'); }
[ "function", "getReflectedCSSName", "(", "name", ")", "{", "name", "=", "cssEditTree", ".", "baseName", "(", "name", ")", ";", "var", "vendorPrefix", "=", "'^(?:\\\\-\\\\w+\\\\-)?'", ",", "m", ";", "if", "(", "(", "name", "==", "'opacity'", "||", "name", "==", "'filter'", ")", "&&", "prefs", ".", "get", "(", "'css.reflect.oldIEOpacity'", ")", ")", "{", "return", "new", "RegExp", "(", "vendorPrefix", "+", "'(?:opacity|filter)$'", ")", ";", "}", "else", "if", "(", "(", "m", "=", "name", ".", "match", "(", "/", "^border-radius-(top|bottom)(left|right)", "/", ")", ")", ")", "{", "// Mozilla-style border radius", "return", "new", "RegExp", "(", "vendorPrefix", "+", "'(?:'", "+", "name", "+", "'|border-'", "+", "m", "[", "1", "]", "+", "'-'", "+", "m", "[", "2", "]", "+", "'-radius)$'", ")", ";", "}", "else", "if", "(", "(", "m", "=", "name", ".", "match", "(", "/", "^border-(top|bottom)-(left|right)-radius", "/", ")", ")", ")", "{", "return", "new", "RegExp", "(", "vendorPrefix", "+", "'(?:'", "+", "name", "+", "'|border-radius-'", "+", "m", "[", "1", "]", "+", "m", "[", "2", "]", "+", "')$'", ")", ";", "}", "return", "new", "RegExp", "(", "vendorPrefix", "+", "name", "+", "'$'", ")", ";", "}" ]
Returns regexp that should match reflected CSS property names @param {String} name Current CSS property name @return {RegExp}
[ "Returns", "regexp", "that", "should", "match", "reflected", "CSS", "property", "names" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/reflectCSSValue.js#L61-L75
11,272
emmetio/emmet
lib/action/editPoints.js
findNewEditPoint
function findNewEditPoint(editor, inc, offset) { inc = inc || 1; offset = offset || 0; var curPoint = editor.getCaretPos() + offset; var content = String(editor.getContent()); var maxLen = content.length; var nextPoint = -1; var reEmptyLine = /^\s+$/; function getLine(ix) { var start = ix; while (start >= 0) { var c = content.charAt(start); if (c == '\n' || c == '\r') break; start--; } return content.substring(start, ix); } while (curPoint <= maxLen && curPoint >= 0) { curPoint += inc; var curChar = content.charAt(curPoint); var nextChar = content.charAt(curPoint + 1); var prevChar = content.charAt(curPoint - 1); switch (curChar) { case '"': case '\'': if (nextChar == curChar && prevChar == '=') { // empty attribute nextPoint = curPoint + 1; } break; case '>': if (nextChar == '<') { // between tags nextPoint = curPoint + 1; } break; case '\n': case '\r': // empty line if (reEmptyLine.test(getLine(curPoint - 1))) { nextPoint = curPoint; } break; } if (nextPoint != -1) break; } return nextPoint; }
javascript
function findNewEditPoint(editor, inc, offset) { inc = inc || 1; offset = offset || 0; var curPoint = editor.getCaretPos() + offset; var content = String(editor.getContent()); var maxLen = content.length; var nextPoint = -1; var reEmptyLine = /^\s+$/; function getLine(ix) { var start = ix; while (start >= 0) { var c = content.charAt(start); if (c == '\n' || c == '\r') break; start--; } return content.substring(start, ix); } while (curPoint <= maxLen && curPoint >= 0) { curPoint += inc; var curChar = content.charAt(curPoint); var nextChar = content.charAt(curPoint + 1); var prevChar = content.charAt(curPoint - 1); switch (curChar) { case '"': case '\'': if (nextChar == curChar && prevChar == '=') { // empty attribute nextPoint = curPoint + 1; } break; case '>': if (nextChar == '<') { // between tags nextPoint = curPoint + 1; } break; case '\n': case '\r': // empty line if (reEmptyLine.test(getLine(curPoint - 1))) { nextPoint = curPoint; } break; } if (nextPoint != -1) break; } return nextPoint; }
[ "function", "findNewEditPoint", "(", "editor", ",", "inc", ",", "offset", ")", "{", "inc", "=", "inc", "||", "1", ";", "offset", "=", "offset", "||", "0", ";", "var", "curPoint", "=", "editor", ".", "getCaretPos", "(", ")", "+", "offset", ";", "var", "content", "=", "String", "(", "editor", ".", "getContent", "(", ")", ")", ";", "var", "maxLen", "=", "content", ".", "length", ";", "var", "nextPoint", "=", "-", "1", ";", "var", "reEmptyLine", "=", "/", "^\\s+$", "/", ";", "function", "getLine", "(", "ix", ")", "{", "var", "start", "=", "ix", ";", "while", "(", "start", ">=", "0", ")", "{", "var", "c", "=", "content", ".", "charAt", "(", "start", ")", ";", "if", "(", "c", "==", "'\\n'", "||", "c", "==", "'\\r'", ")", "break", ";", "start", "--", ";", "}", "return", "content", ".", "substring", "(", "start", ",", "ix", ")", ";", "}", "while", "(", "curPoint", "<=", "maxLen", "&&", "curPoint", ">=", "0", ")", "{", "curPoint", "+=", "inc", ";", "var", "curChar", "=", "content", ".", "charAt", "(", "curPoint", ")", ";", "var", "nextChar", "=", "content", ".", "charAt", "(", "curPoint", "+", "1", ")", ";", "var", "prevChar", "=", "content", ".", "charAt", "(", "curPoint", "-", "1", ")", ";", "switch", "(", "curChar", ")", "{", "case", "'\"'", ":", "case", "'\\''", ":", "if", "(", "nextChar", "==", "curChar", "&&", "prevChar", "==", "'='", ")", "{", "// empty attribute", "nextPoint", "=", "curPoint", "+", "1", ";", "}", "break", ";", "case", "'>'", ":", "if", "(", "nextChar", "==", "'<'", ")", "{", "// between tags", "nextPoint", "=", "curPoint", "+", "1", ";", "}", "break", ";", "case", "'\\n'", ":", "case", "'\\r'", ":", "// empty line", "if", "(", "reEmptyLine", ".", "test", "(", "getLine", "(", "curPoint", "-", "1", ")", ")", ")", "{", "nextPoint", "=", "curPoint", ";", "}", "break", ";", "}", "if", "(", "nextPoint", "!=", "-", "1", ")", "break", ";", "}", "return", "nextPoint", ";", "}" ]
Search for new caret insertion point @param {IEmmetEditor} editor Editor instance @param {Number} inc Search increment: -1 — search left, 1 — search right @param {Number} offset Initial offset relative to current caret position @return {Number} Returns -1 if insertion point wasn't found
[ "Search", "for", "new", "caret", "insertion", "point" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/editPoints.js#L19-L75
11,273
emmetio/emmet
lib/action/editPoints.js
function(editor, syntax, profile) { var curPos = editor.getCaretPos(); var newPoint = findNewEditPoint(editor, -1); if (newPoint == curPos) // we're still in the same point, try searching from the other place newPoint = findNewEditPoint(editor, -1, -2); if (newPoint != -1) { editor.setCaretPos(newPoint); return true; } return false; }
javascript
function(editor, syntax, profile) { var curPos = editor.getCaretPos(); var newPoint = findNewEditPoint(editor, -1); if (newPoint == curPos) // we're still in the same point, try searching from the other place newPoint = findNewEditPoint(editor, -1, -2); if (newPoint != -1) { editor.setCaretPos(newPoint); return true; } return false; }
[ "function", "(", "editor", ",", "syntax", ",", "profile", ")", "{", "var", "curPos", "=", "editor", ".", "getCaretPos", "(", ")", ";", "var", "newPoint", "=", "findNewEditPoint", "(", "editor", ",", "-", "1", ")", ";", "if", "(", "newPoint", "==", "curPos", ")", "// we're still in the same point, try searching from the other place", "newPoint", "=", "findNewEditPoint", "(", "editor", ",", "-", "1", ",", "-", "2", ")", ";", "if", "(", "newPoint", "!=", "-", "1", ")", "{", "editor", ".", "setCaretPos", "(", "newPoint", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Move to previous edit point @param {IEmmetEditor} editor Editor instance @param {String} syntax Current document syntax @param {String} profile Output profile name @return {Boolean}
[ "Move", "to", "previous", "edit", "point" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/editPoints.js#L85-L99
11,274
emmetio/emmet
lib/action/editPoints.js
function(editor, syntax, profile) { var newPoint = findNewEditPoint(editor, 1); if (newPoint != -1) { editor.setCaretPos(newPoint); return true; } return false; }
javascript
function(editor, syntax, profile) { var newPoint = findNewEditPoint(editor, 1); if (newPoint != -1) { editor.setCaretPos(newPoint); return true; } return false; }
[ "function", "(", "editor", ",", "syntax", ",", "profile", ")", "{", "var", "newPoint", "=", "findNewEditPoint", "(", "editor", ",", "1", ")", ";", "if", "(", "newPoint", "!=", "-", "1", ")", "{", "editor", ".", "setCaretPos", "(", "newPoint", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Move to next edit point @param {IEmmetEditor} editor Editor instance @param {String} syntax Current document syntax @param {String} profile Output profile name @return {Boolean}
[ "Move", "to", "next", "edit", "point" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/editPoints.js#L108-L116
11,275
emmetio/emmet
lib/filter/haml.js
makeAttributesString
function makeAttributesString(tag, profile) { var attrs = ''; var otherAttrs = []; var attrQuote = profile.attributeQuote(); var cursor = profile.cursor(); tag.attributeList().forEach(function(a) { var attrName = profile.attributeName(a.name); switch (attrName.toLowerCase()) { // use short notation for ID and CLASS attributes case 'id': attrs += '#' + (a.value || cursor); break; case 'class': attrs += '.' + transformClassName(a.value || cursor); break; // process other attributes default: otherAttrs.push({ name: attrName, value: a.value || cursor, isBoolean: profile.isBoolean(a.name, a.value) }); } }); if (otherAttrs.length) { attrs += stringifyAttrs(condenseDataAttrs(otherAttrs), profile); } return attrs; }
javascript
function makeAttributesString(tag, profile) { var attrs = ''; var otherAttrs = []; var attrQuote = profile.attributeQuote(); var cursor = profile.cursor(); tag.attributeList().forEach(function(a) { var attrName = profile.attributeName(a.name); switch (attrName.toLowerCase()) { // use short notation for ID and CLASS attributes case 'id': attrs += '#' + (a.value || cursor); break; case 'class': attrs += '.' + transformClassName(a.value || cursor); break; // process other attributes default: otherAttrs.push({ name: attrName, value: a.value || cursor, isBoolean: profile.isBoolean(a.name, a.value) }); } }); if (otherAttrs.length) { attrs += stringifyAttrs(condenseDataAttrs(otherAttrs), profile); } return attrs; }
[ "function", "makeAttributesString", "(", "tag", ",", "profile", ")", "{", "var", "attrs", "=", "''", ";", "var", "otherAttrs", "=", "[", "]", ";", "var", "attrQuote", "=", "profile", ".", "attributeQuote", "(", ")", ";", "var", "cursor", "=", "profile", ".", "cursor", "(", ")", ";", "tag", ".", "attributeList", "(", ")", ".", "forEach", "(", "function", "(", "a", ")", "{", "var", "attrName", "=", "profile", ".", "attributeName", "(", "a", ".", "name", ")", ";", "switch", "(", "attrName", ".", "toLowerCase", "(", ")", ")", "{", "// use short notation for ID and CLASS attributes", "case", "'id'", ":", "attrs", "+=", "'#'", "+", "(", "a", ".", "value", "||", "cursor", ")", ";", "break", ";", "case", "'class'", ":", "attrs", "+=", "'.'", "+", "transformClassName", "(", "a", ".", "value", "||", "cursor", ")", ";", "break", ";", "// process other attributes", "default", ":", "otherAttrs", ".", "push", "(", "{", "name", ":", "attrName", ",", "value", ":", "a", ".", "value", "||", "cursor", ",", "isBoolean", ":", "profile", ".", "isBoolean", "(", "a", ".", "name", ",", "a", ".", "value", ")", "}", ")", ";", "}", "}", ")", ";", "if", "(", "otherAttrs", ".", "length", ")", "{", "attrs", "+=", "stringifyAttrs", "(", "condenseDataAttrs", "(", "otherAttrs", ")", ",", "profile", ")", ";", "}", "return", "attrs", ";", "}" ]
Creates HAML attributes string from tag according to profile settings @param {AbbreviationNode} tag @param {Object} profile
[ "Creates", "HAML", "attributes", "string", "from", "tag", "according", "to", "profile", "settings" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/filter/haml.js#L67-L98
11,276
emmetio/emmet
lib/action/updateImageSize.js
updateImageSizeHTML
function updateImageSizeHTML(editor) { var offset = editor.getCaretPos(); // find tag from current caret position var info = editorUtils.outputInfo(editor); var xmlElem = xmlEditTree.parseFromPosition(info.content, offset, true); if (xmlElem && (xmlElem.name() || '').toLowerCase() == 'img') { getImageSizeForSource(editor, xmlElem.value('src'), function(size) { if (size) { var compoundData = xmlElem.range(true); xmlElem.value('width', size.width); xmlElem.value('height', size.height, xmlElem.indexOf('width') + 1); actionUtils.compoundUpdate(editor, utils.extend(compoundData, { data: xmlElem.toString(), caret: offset })); } }); } }
javascript
function updateImageSizeHTML(editor) { var offset = editor.getCaretPos(); // find tag from current caret position var info = editorUtils.outputInfo(editor); var xmlElem = xmlEditTree.parseFromPosition(info.content, offset, true); if (xmlElem && (xmlElem.name() || '').toLowerCase() == 'img') { getImageSizeForSource(editor, xmlElem.value('src'), function(size) { if (size) { var compoundData = xmlElem.range(true); xmlElem.value('width', size.width); xmlElem.value('height', size.height, xmlElem.indexOf('width') + 1); actionUtils.compoundUpdate(editor, utils.extend(compoundData, { data: xmlElem.toString(), caret: offset })); } }); } }
[ "function", "updateImageSizeHTML", "(", "editor", ")", "{", "var", "offset", "=", "editor", ".", "getCaretPos", "(", ")", ";", "// find tag from current caret position", "var", "info", "=", "editorUtils", ".", "outputInfo", "(", "editor", ")", ";", "var", "xmlElem", "=", "xmlEditTree", ".", "parseFromPosition", "(", "info", ".", "content", ",", "offset", ",", "true", ")", ";", "if", "(", "xmlElem", "&&", "(", "xmlElem", ".", "name", "(", ")", "||", "''", ")", ".", "toLowerCase", "(", ")", "==", "'img'", ")", "{", "getImageSizeForSource", "(", "editor", ",", "xmlElem", ".", "value", "(", "'src'", ")", ",", "function", "(", "size", ")", "{", "if", "(", "size", ")", "{", "var", "compoundData", "=", "xmlElem", ".", "range", "(", "true", ")", ";", "xmlElem", ".", "value", "(", "'width'", ",", "size", ".", "width", ")", ";", "xmlElem", ".", "value", "(", "'height'", ",", "size", ".", "height", ",", "xmlElem", ".", "indexOf", "(", "'width'", ")", "+", "1", ")", ";", "actionUtils", ".", "compoundUpdate", "(", "editor", ",", "utils", ".", "extend", "(", "compoundData", ",", "{", "data", ":", "xmlElem", ".", "toString", "(", ")", ",", "caret", ":", "offset", "}", ")", ")", ";", "}", "}", ")", ";", "}", "}" ]
Updates image size of &lt;img src=""&gt; tag @param {IEmmetEditor} editor
[ "Updates", "image", "size", "of", "&lt", ";", "img", "src", "=", "&gt", ";", "tag" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/updateImageSize.js#L24-L44
11,277
emmetio/emmet
lib/action/updateImageSize.js
getImageSizeForSource
function getImageSizeForSource(editor, src, callback) { var fileContent; if (src) { // check if it is data:url if (/^data:/.test(src)) { fileContent = base64.decode( src.replace(/^data\:.+?;.+?,/, '') ); return callback(actionUtils.getImageSize(fileContent)); } var filePath = editor.getFilePath(); file.locateFile(filePath, src, function(absPath) { if (absPath === null) { throw "Can't find " + src + ' file'; } file.read(absPath, function(err, content) { if (err) { throw 'Unable to read ' + absPath + ': ' + err; } content = String(content); callback(actionUtils.getImageSize(content)); }); }); } }
javascript
function getImageSizeForSource(editor, src, callback) { var fileContent; if (src) { // check if it is data:url if (/^data:/.test(src)) { fileContent = base64.decode( src.replace(/^data\:.+?;.+?,/, '') ); return callback(actionUtils.getImageSize(fileContent)); } var filePath = editor.getFilePath(); file.locateFile(filePath, src, function(absPath) { if (absPath === null) { throw "Can't find " + src + ' file'; } file.read(absPath, function(err, content) { if (err) { throw 'Unable to read ' + absPath + ': ' + err; } content = String(content); callback(actionUtils.getImageSize(content)); }); }); } }
[ "function", "getImageSizeForSource", "(", "editor", ",", "src", ",", "callback", ")", "{", "var", "fileContent", ";", "if", "(", "src", ")", "{", "// check if it is data:url", "if", "(", "/", "^data:", "/", ".", "test", "(", "src", ")", ")", "{", "fileContent", "=", "base64", ".", "decode", "(", "src", ".", "replace", "(", "/", "^data\\:.+?;.+?,", "/", ",", "''", ")", ")", ";", "return", "callback", "(", "actionUtils", ".", "getImageSize", "(", "fileContent", ")", ")", ";", "}", "var", "filePath", "=", "editor", ".", "getFilePath", "(", ")", ";", "file", ".", "locateFile", "(", "filePath", ",", "src", ",", "function", "(", "absPath", ")", "{", "if", "(", "absPath", "===", "null", ")", "{", "throw", "\"Can't find \"", "+", "src", "+", "' file'", ";", "}", "file", ".", "read", "(", "absPath", ",", "function", "(", "err", ",", "content", ")", "{", "if", "(", "err", ")", "{", "throw", "'Unable to read '", "+", "absPath", "+", "': '", "+", "err", ";", "}", "content", "=", "String", "(", "content", ")", ";", "callback", "(", "actionUtils", ".", "getImageSize", "(", "content", ")", ")", ";", "}", ")", ";", "}", ")", ";", "}", "}" ]
Returns image dimensions for source @param {IEmmetEditor} editor @param {String} src Image source (path or data:url)
[ "Returns", "image", "dimensions", "for", "source" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/updateImageSize.js#L81-L106
11,278
emmetio/emmet
lib/filter/main.js
function(tree, filters, profileName) { profileName = profile.get(profileName); list(filters).forEach(function(filter) { var name = utils.trim(filter.toLowerCase()); if (name && name in registeredFilters) { tree = registeredFilters[name](tree, profileName); } }); return tree; }
javascript
function(tree, filters, profileName) { profileName = profile.get(profileName); list(filters).forEach(function(filter) { var name = utils.trim(filter.toLowerCase()); if (name && name in registeredFilters) { tree = registeredFilters[name](tree, profileName); } }); return tree; }
[ "function", "(", "tree", ",", "filters", ",", "profileName", ")", "{", "profileName", "=", "profile", ".", "get", "(", "profileName", ")", ";", "list", "(", "filters", ")", ".", "forEach", "(", "function", "(", "filter", ")", "{", "var", "name", "=", "utils", ".", "trim", "(", "filter", ".", "toLowerCase", "(", ")", ")", ";", "if", "(", "name", "&&", "name", "in", "registeredFilters", ")", "{", "tree", "=", "registeredFilters", "[", "name", "]", "(", "tree", ",", "profileName", ")", ";", "}", "}", ")", ";", "return", "tree", ";", "}" ]
Apply filters for final output tree @param {AbbreviationNode} tree Output tree @param {Array} filters List of filters to apply. Might be a <code>String</code> @param {Object} profile Output profile, defined in <i>profile</i> module. Filters defined it profile are not used, <code>profile</code> is passed to filter function @memberOf emmet.filters @returns {AbbreviationNode}
[ "Apply", "filters", "for", "final", "output", "tree" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/filter/main.js#L66-L77
11,279
emmetio/emmet
lib/filter/main.js
function(syntax, profileName, additionalFilters) { profileName = profile.get(profileName); var filters = list(profileName.filters || resources.findItem(syntax, 'filters') || basicFilters); if (profileName.extraFilters) { filters = filters.concat(list(profileName.extraFilters)); } if (additionalFilters) { filters = filters.concat(list(additionalFilters)); } if (!filters || !filters.length) { // looks like unknown syntax, apply basic filters filters = list(basicFilters); } return filters; }
javascript
function(syntax, profileName, additionalFilters) { profileName = profile.get(profileName); var filters = list(profileName.filters || resources.findItem(syntax, 'filters') || basicFilters); if (profileName.extraFilters) { filters = filters.concat(list(profileName.extraFilters)); } if (additionalFilters) { filters = filters.concat(list(additionalFilters)); } if (!filters || !filters.length) { // looks like unknown syntax, apply basic filters filters = list(basicFilters); } return filters; }
[ "function", "(", "syntax", ",", "profileName", ",", "additionalFilters", ")", "{", "profileName", "=", "profile", ".", "get", "(", "profileName", ")", ";", "var", "filters", "=", "list", "(", "profileName", ".", "filters", "||", "resources", ".", "findItem", "(", "syntax", ",", "'filters'", ")", "||", "basicFilters", ")", ";", "if", "(", "profileName", ".", "extraFilters", ")", "{", "filters", "=", "filters", ".", "concat", "(", "list", "(", "profileName", ".", "extraFilters", ")", ")", ";", "}", "if", "(", "additionalFilters", ")", "{", "filters", "=", "filters", ".", "concat", "(", "list", "(", "additionalFilters", ")", ")", ";", "}", "if", "(", "!", "filters", "||", "!", "filters", ".", "length", ")", "{", "// looks like unknown syntax, apply basic filters", "filters", "=", "list", "(", "basicFilters", ")", ";", "}", "return", "filters", ";", "}" ]
Composes list of filters that should be applied to a tree, based on passed data @param {String} syntax Syntax name ('html', 'css', etc.) @param {Object} profile Output profile @param {String} additionalFilters List or pipe-separated string of additional filters to apply @returns {Array}
[ "Composes", "list", "of", "filters", "that", "should", "be", "applied", "to", "a", "tree", "based", "on", "passed", "data" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/filter/main.js#L88-L106
11,280
emmetio/emmet
lib/filter/main.js
function(abbr) { var filters = ''; abbr = abbr.replace(/\|([\w\|\-]+)$/, function(str, p1){ filters = p1; return ''; }); return [abbr, list(filters)]; }
javascript
function(abbr) { var filters = ''; abbr = abbr.replace(/\|([\w\|\-]+)$/, function(str, p1){ filters = p1; return ''; }); return [abbr, list(filters)]; }
[ "function", "(", "abbr", ")", "{", "var", "filters", "=", "''", ";", "abbr", "=", "abbr", ".", "replace", "(", "/", "\\|([\\w\\|\\-]+)$", "/", ",", "function", "(", "str", ",", "p1", ")", "{", "filters", "=", "p1", ";", "return", "''", ";", "}", ")", ";", "return", "[", "abbr", ",", "list", "(", "filters", ")", "]", ";", "}" ]
Extracts filter list from abbreviation @param {String} abbr @returns {Array} Array with cleaned abbreviation and list of extracted filters
[ "Extracts", "filter", "list", "from", "abbreviation" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/filter/main.js#L114-L122
11,281
emmetio/emmet
lib/assets/htmlMatcher.js
function(i) { var key = 'p' + i; if (!(key in memo)) { memo[key] = false; if (text.charAt(i) == '<') { var substr = text.slice(i); if ((m = substr.match(reOpenTag))) { memo[key] = openTag(i, m); } else if ((m = substr.match(reCloseTag))) { memo[key] = closeTag(i, m); } } } return memo[key]; }
javascript
function(i) { var key = 'p' + i; if (!(key in memo)) { memo[key] = false; if (text.charAt(i) == '<') { var substr = text.slice(i); if ((m = substr.match(reOpenTag))) { memo[key] = openTag(i, m); } else if ((m = substr.match(reCloseTag))) { memo[key] = closeTag(i, m); } } } return memo[key]; }
[ "function", "(", "i", ")", "{", "var", "key", "=", "'p'", "+", "i", ";", "if", "(", "!", "(", "key", "in", "memo", ")", ")", "{", "memo", "[", "key", "]", "=", "false", ";", "if", "(", "text", ".", "charAt", "(", "i", ")", "==", "'<'", ")", "{", "var", "substr", "=", "text", ".", "slice", "(", "i", ")", ";", "if", "(", "(", "m", "=", "substr", ".", "match", "(", "reOpenTag", ")", ")", ")", "{", "memo", "[", "key", "]", "=", "openTag", "(", "i", ",", "m", ")", ";", "}", "else", "if", "(", "(", "m", "=", "substr", ".", "match", "(", "reCloseTag", ")", ")", ")", "{", "memo", "[", "key", "]", "=", "closeTag", "(", "i", ",", "m", ")", ";", "}", "}", "}", "return", "memo", "[", "key", "]", ";", "}" ]
Matches either opening or closing tag for given position @param i @returns
[ "Matches", "either", "opening", "or", "closing", "tag", "for", "given", "position" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/htmlMatcher.js#L81-L97
11,282
emmetio/emmet
lib/assets/htmlMatcher.js
findClosingPair
function findClosingPair(open, matcher) { var stack = [], tag = null; var text = matcher.text(); for (var pos = open.range.end, len = text.length; pos < len; pos++) { if (matches(text, pos, '<!--')) { // skip to end of comment for (var j = pos; j < len; j++) { if (matches(text, j, '-->')) { pos = j + 3; break; } } } if ((tag = matcher.matches(pos))) { if (tag.type == 'open' && !tag.selfClose) { stack.push(tag.name); } else if (tag.type == 'close') { if (!stack.length) { // found valid pair? return tag.name == open.name ? tag : null; } // check if current closing tag matches previously opened one if (stack[stack.length - 1] == tag.name) { stack.pop(); } else { var found = false; while (stack.length && !found) { var last = stack.pop(); if (last == tag.name) { found = true; } } if (!stack.length && !found) { return tag.name == open.name ? tag : null; } } } pos = tag.range.end - 1; } } }
javascript
function findClosingPair(open, matcher) { var stack = [], tag = null; var text = matcher.text(); for (var pos = open.range.end, len = text.length; pos < len; pos++) { if (matches(text, pos, '<!--')) { // skip to end of comment for (var j = pos; j < len; j++) { if (matches(text, j, '-->')) { pos = j + 3; break; } } } if ((tag = matcher.matches(pos))) { if (tag.type == 'open' && !tag.selfClose) { stack.push(tag.name); } else if (tag.type == 'close') { if (!stack.length) { // found valid pair? return tag.name == open.name ? tag : null; } // check if current closing tag matches previously opened one if (stack[stack.length - 1] == tag.name) { stack.pop(); } else { var found = false; while (stack.length && !found) { var last = stack.pop(); if (last == tag.name) { found = true; } } if (!stack.length && !found) { return tag.name == open.name ? tag : null; } } } pos = tag.range.end - 1; } } }
[ "function", "findClosingPair", "(", "open", ",", "matcher", ")", "{", "var", "stack", "=", "[", "]", ",", "tag", "=", "null", ";", "var", "text", "=", "matcher", ".", "text", "(", ")", ";", "for", "(", "var", "pos", "=", "open", ".", "range", ".", "end", ",", "len", "=", "text", ".", "length", ";", "pos", "<", "len", ";", "pos", "++", ")", "{", "if", "(", "matches", "(", "text", ",", "pos", ",", "'<!--'", ")", ")", "{", "// skip to end of comment", "for", "(", "var", "j", "=", "pos", ";", "j", "<", "len", ";", "j", "++", ")", "{", "if", "(", "matches", "(", "text", ",", "j", ",", "'-->'", ")", ")", "{", "pos", "=", "j", "+", "3", ";", "break", ";", "}", "}", "}", "if", "(", "(", "tag", "=", "matcher", ".", "matches", "(", "pos", ")", ")", ")", "{", "if", "(", "tag", ".", "type", "==", "'open'", "&&", "!", "tag", ".", "selfClose", ")", "{", "stack", ".", "push", "(", "tag", ".", "name", ")", ";", "}", "else", "if", "(", "tag", ".", "type", "==", "'close'", ")", "{", "if", "(", "!", "stack", ".", "length", ")", "{", "// found valid pair?", "return", "tag", ".", "name", "==", "open", ".", "name", "?", "tag", ":", "null", ";", "}", "// check if current closing tag matches previously opened one", "if", "(", "stack", "[", "stack", ".", "length", "-", "1", "]", "==", "tag", ".", "name", ")", "{", "stack", ".", "pop", "(", ")", ";", "}", "else", "{", "var", "found", "=", "false", ";", "while", "(", "stack", ".", "length", "&&", "!", "found", ")", "{", "var", "last", "=", "stack", ".", "pop", "(", ")", ";", "if", "(", "last", "==", "tag", ".", "name", ")", "{", "found", "=", "true", ";", "}", "}", "if", "(", "!", "stack", ".", "length", "&&", "!", "found", ")", "{", "return", "tag", ".", "name", "==", "open", ".", "name", "?", "tag", ":", "null", ";", "}", "}", "}", "pos", "=", "tag", ".", "range", ".", "end", "-", "1", ";", "}", "}", "}" ]
Search for closing pair of opening tag @param {Object} open Open tag instance @param {Object} matcher Matcher instance
[ "Search", "for", "closing", "pair", "of", "opening", "tag" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/assets/htmlMatcher.js#L122-L166
11,283
emmetio/emmet
lib/parser/abbreviation.js
function(child, position) { child = child || new AbbreviationNode(); child.parent = this; if (typeof position === 'undefined') { this.children.push(child); } else { this.children.splice(position, 0, child); } return child; }
javascript
function(child, position) { child = child || new AbbreviationNode(); child.parent = this; if (typeof position === 'undefined') { this.children.push(child); } else { this.children.splice(position, 0, child); } return child; }
[ "function", "(", "child", ",", "position", ")", "{", "child", "=", "child", "||", "new", "AbbreviationNode", "(", ")", ";", "child", ".", "parent", "=", "this", ";", "if", "(", "typeof", "position", "===", "'undefined'", ")", "{", "this", ".", "children", ".", "push", "(", "child", ")", ";", "}", "else", "{", "this", ".", "children", ".", "splice", "(", "position", ",", "0", ",", "child", ")", ";", "}", "return", "child", ";", "}" ]
Adds passed node as child or creates new child @param {AbbreviationNode} child @param {Number} position Index in children array where child should be inserted @return {AbbreviationNode}
[ "Adds", "passed", "node", "as", "child", "or", "creates", "new", "child" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L86-L97
11,284
emmetio/emmet
lib/parser/abbreviation.js
function() { var node = new AbbreviationNode(); var attrs = ['abbreviation', 'counter', '_name', '_text', 'repeatCount', 'hasImplicitRepeat', 'start', 'end', 'content', 'padding']; attrs.forEach(function(a) { node[a] = this[a]; }, this); // clone attributes node._attributes = this._attributes.map(function(attr) { return utils.extend({}, attr); }); node._data = utils.extend({}, this._data); // clone children node.children = this.children.map(function(child) { child = child.clone(); child.parent = node; return child; }); return node; }
javascript
function() { var node = new AbbreviationNode(); var attrs = ['abbreviation', 'counter', '_name', '_text', 'repeatCount', 'hasImplicitRepeat', 'start', 'end', 'content', 'padding']; attrs.forEach(function(a) { node[a] = this[a]; }, this); // clone attributes node._attributes = this._attributes.map(function(attr) { return utils.extend({}, attr); }); node._data = utils.extend({}, this._data); // clone children node.children = this.children.map(function(child) { child = child.clone(); child.parent = node; return child; }); return node; }
[ "function", "(", ")", "{", "var", "node", "=", "new", "AbbreviationNode", "(", ")", ";", "var", "attrs", "=", "[", "'abbreviation'", ",", "'counter'", ",", "'_name'", ",", "'_text'", ",", "'repeatCount'", ",", "'hasImplicitRepeat'", ",", "'start'", ",", "'end'", ",", "'content'", ",", "'padding'", "]", ";", "attrs", ".", "forEach", "(", "function", "(", "a", ")", "{", "node", "[", "a", "]", "=", "this", "[", "a", "]", ";", "}", ",", "this", ")", ";", "// clone attributes", "node", ".", "_attributes", "=", "this", ".", "_attributes", ".", "map", "(", "function", "(", "attr", ")", "{", "return", "utils", ".", "extend", "(", "{", "}", ",", "attr", ")", ";", "}", ")", ";", "node", ".", "_data", "=", "utils", ".", "extend", "(", "{", "}", ",", "this", ".", "_data", ")", ";", "// clone children", "node", ".", "children", "=", "this", ".", "children", ".", "map", "(", "function", "(", "child", ")", "{", "child", "=", "child", ".", "clone", "(", ")", ";", "child", ".", "parent", "=", "node", ";", "return", "child", ";", "}", ")", ";", "return", "node", ";", "}" ]
Creates a deep copy of current node @returns {AbbreviationNode}
[ "Creates", "a", "deep", "copy", "of", "current", "node" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L103-L125
11,285
emmetio/emmet
lib/parser/abbreviation.js
function(name, value) { if (arguments.length == 2) { if (value === null) { // remove attribute var vals = this._attributes.filter(function(attr) { return attr.name === name; }); var that = this; vals.forEach(function(attr) { var ix = that._attributes.indexOf(attr); if (~ix) { that._attributes.splice(ix, 1); } }); return; } // modify attribute var attrNames = this._attributes.map(function(attr) { return attr.name; }); var ix = attrNames.indexOf(name.toLowerCase()); if (~ix) { this._attributes[ix].value = value; } else { this._attributes.push({ name: name, value: value }); } } return (utils.find(this.attributeList(), function(attr) { return attr.name == name; }) || {}).value; }
javascript
function(name, value) { if (arguments.length == 2) { if (value === null) { // remove attribute var vals = this._attributes.filter(function(attr) { return attr.name === name; }); var that = this; vals.forEach(function(attr) { var ix = that._attributes.indexOf(attr); if (~ix) { that._attributes.splice(ix, 1); } }); return; } // modify attribute var attrNames = this._attributes.map(function(attr) { return attr.name; }); var ix = attrNames.indexOf(name.toLowerCase()); if (~ix) { this._attributes[ix].value = value; } else { this._attributes.push({ name: name, value: value }); } } return (utils.find(this.attributeList(), function(attr) { return attr.name == name; }) || {}).value; }
[ "function", "(", "name", ",", "value", ")", "{", "if", "(", "arguments", ".", "length", "==", "2", ")", "{", "if", "(", "value", "===", "null", ")", "{", "// remove attribute", "var", "vals", "=", "this", ".", "_attributes", ".", "filter", "(", "function", "(", "attr", ")", "{", "return", "attr", ".", "name", "===", "name", ";", "}", ")", ";", "var", "that", "=", "this", ";", "vals", ".", "forEach", "(", "function", "(", "attr", ")", "{", "var", "ix", "=", "that", ".", "_attributes", ".", "indexOf", "(", "attr", ")", ";", "if", "(", "~", "ix", ")", "{", "that", ".", "_attributes", ".", "splice", "(", "ix", ",", "1", ")", ";", "}", "}", ")", ";", "return", ";", "}", "// modify attribute", "var", "attrNames", "=", "this", ".", "_attributes", ".", "map", "(", "function", "(", "attr", ")", "{", "return", "attr", ".", "name", ";", "}", ")", ";", "var", "ix", "=", "attrNames", ".", "indexOf", "(", "name", ".", "toLowerCase", "(", ")", ")", ";", "if", "(", "~", "ix", ")", "{", "this", ".", "_attributes", "[", "ix", "]", ".", "value", "=", "value", ";", "}", "else", "{", "this", ".", "_attributes", ".", "push", "(", "{", "name", ":", "name", ",", "value", ":", "value", "}", ")", ";", "}", "}", "return", "(", "utils", ".", "find", "(", "this", ".", "attributeList", "(", ")", ",", "function", "(", "attr", ")", "{", "return", "attr", ".", "name", "==", "name", ";", "}", ")", "||", "{", "}", ")", ".", "value", ";", "}" ]
Returns or sets attribute value @param {String} name Attribute name @param {String} value New attribute value. `Null` value will remove attribute @returns {String}
[ "Returns", "or", "sets", "attribute", "value" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L252-L289
11,286
emmetio/emmet
lib/parser/abbreviation.js
function(abbr) { abbr = abbr || ''; var that = this; // find multiplier abbr = abbr.replace(/\*(\d+)?$/, function(str, repeatCount) { that._setRepeat(repeatCount); return ''; }); this.abbreviation = abbr; var abbrText = extractText(abbr); if (abbrText) { abbr = abbrText.element; this.content = this._text = abbrText.text; } var abbrAttrs = parseAttributes(abbr); if (abbrAttrs) { abbr = abbrAttrs.element; this._attributes = abbrAttrs.attributes; } this._name = abbr; // validate name if (this._name && !reValidName.test(this._name)) { throw new Error('Invalid abbreviation'); } }
javascript
function(abbr) { abbr = abbr || ''; var that = this; // find multiplier abbr = abbr.replace(/\*(\d+)?$/, function(str, repeatCount) { that._setRepeat(repeatCount); return ''; }); this.abbreviation = abbr; var abbrText = extractText(abbr); if (abbrText) { abbr = abbrText.element; this.content = this._text = abbrText.text; } var abbrAttrs = parseAttributes(abbr); if (abbrAttrs) { abbr = abbrAttrs.element; this._attributes = abbrAttrs.attributes; } this._name = abbr; // validate name if (this._name && !reValidName.test(this._name)) { throw new Error('Invalid abbreviation'); } }
[ "function", "(", "abbr", ")", "{", "abbr", "=", "abbr", "||", "''", ";", "var", "that", "=", "this", ";", "// find multiplier", "abbr", "=", "abbr", ".", "replace", "(", "/", "\\*(\\d+)?$", "/", ",", "function", "(", "str", ",", "repeatCount", ")", "{", "that", ".", "_setRepeat", "(", "repeatCount", ")", ";", "return", "''", ";", "}", ")", ";", "this", ".", "abbreviation", "=", "abbr", ";", "var", "abbrText", "=", "extractText", "(", "abbr", ")", ";", "if", "(", "abbrText", ")", "{", "abbr", "=", "abbrText", ".", "element", ";", "this", ".", "content", "=", "this", ".", "_text", "=", "abbrText", ".", "text", ";", "}", "var", "abbrAttrs", "=", "parseAttributes", "(", "abbr", ")", ";", "if", "(", "abbrAttrs", ")", "{", "abbr", "=", "abbrAttrs", ".", "element", ";", "this", ".", "_attributes", "=", "abbrAttrs", ".", "attributes", ";", "}", "this", ".", "_name", "=", "abbr", ";", "// validate name", "if", "(", "this", ".", "_name", "&&", "!", "reValidName", ".", "test", "(", "this", ".", "_name", ")", ")", "{", "throw", "new", "Error", "(", "'Invalid abbreviation'", ")", ";", "}", "}" ]
Sets abbreviation that belongs to current node @param {String} abbr
[ "Sets", "abbreviation", "that", "belongs", "to", "current", "node" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L315-L346
11,287
emmetio/emmet
lib/parser/abbreviation.js
function() { var start = this.start; var end = this.end; var content = this.content; // apply output processors var node = this; outputProcessors.forEach(function(fn) { start = fn(start, node, 'start'); content = fn(content, node, 'content'); end = fn(end, node, 'end'); }); var innerContent = this.children.map(function(child) { return child.valueOf(); }).join(''); content = abbreviationUtils.insertChildContent(content, innerContent, { keepVariable: false }); return start + utils.padString(content, this.padding) + end; }
javascript
function() { var start = this.start; var end = this.end; var content = this.content; // apply output processors var node = this; outputProcessors.forEach(function(fn) { start = fn(start, node, 'start'); content = fn(content, node, 'content'); end = fn(end, node, 'end'); }); var innerContent = this.children.map(function(child) { return child.valueOf(); }).join(''); content = abbreviationUtils.insertChildContent(content, innerContent, { keepVariable: false }); return start + utils.padString(content, this.padding) + end; }
[ "function", "(", ")", "{", "var", "start", "=", "this", ".", "start", ";", "var", "end", "=", "this", ".", "end", ";", "var", "content", "=", "this", ".", "content", ";", "// apply output processors", "var", "node", "=", "this", ";", "outputProcessors", ".", "forEach", "(", "function", "(", "fn", ")", "{", "start", "=", "fn", "(", "start", ",", "node", ",", "'start'", ")", ";", "content", "=", "fn", "(", "content", ",", "node", ",", "'content'", ")", ";", "end", "=", "fn", "(", "end", ",", "node", ",", "'end'", ")", ";", "}", ")", ";", "var", "innerContent", "=", "this", ".", "children", ".", "map", "(", "function", "(", "child", ")", "{", "return", "child", ".", "valueOf", "(", ")", ";", "}", ")", ".", "join", "(", "''", ")", ";", "content", "=", "abbreviationUtils", ".", "insertChildContent", "(", "content", ",", "innerContent", ",", "{", "keepVariable", ":", "false", "}", ")", ";", "return", "start", "+", "utils", ".", "padString", "(", "content", ",", "this", ".", "padding", ")", "+", "end", ";", "}" ]
Returns string representation of current node @return {String}
[ "Returns", "string", "representation", "of", "current", "node" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L352-L375
11,288
emmetio/emmet
lib/parser/abbreviation.js
function() { if (!this.children.length) return null; var deepestChild = this; while (deepestChild.children.length) { deepestChild = deepestChild.children[deepestChild.children.length - 1]; } return deepestChild; }
javascript
function() { if (!this.children.length) return null; var deepestChild = this; while (deepestChild.children.length) { deepestChild = deepestChild.children[deepestChild.children.length - 1]; } return deepestChild; }
[ "function", "(", ")", "{", "if", "(", "!", "this", ".", "children", ".", "length", ")", "return", "null", ";", "var", "deepestChild", "=", "this", ";", "while", "(", "deepestChild", ".", "children", ".", "length", ")", "{", "deepestChild", "=", "deepestChild", ".", "children", "[", "deepestChild", ".", "children", ".", "length", "-", "1", "]", ";", "}", "return", "deepestChild", ";", "}" ]
Returns latest and deepest child of current tree @returns {AbbreviationNode}
[ "Returns", "latest", "and", "deepest", "child", "of", "current", "tree" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L446-L456
11,289
emmetio/emmet
lib/parser/abbreviation.js
splitAttributes
function splitAttributes(attrSet) { attrSet = utils.trim(attrSet); var parts = []; // split attribute set by spaces var stream = stringStream(attrSet), ch; while ((ch = stream.next())) { if (ch == ' ') { parts.push(utils.trim(stream.current())); // skip spaces while (stream.peek() == ' ') { stream.next(); } stream.start = stream.pos; } else if (ch == '"' || ch == "'") { // skip values in strings if (!stream.skipString(ch)) { throw new Error('Invalid attribute set'); } } } parts.push(utils.trim(stream.current())); return parts; }
javascript
function splitAttributes(attrSet) { attrSet = utils.trim(attrSet); var parts = []; // split attribute set by spaces var stream = stringStream(attrSet), ch; while ((ch = stream.next())) { if (ch == ' ') { parts.push(utils.trim(stream.current())); // skip spaces while (stream.peek() == ' ') { stream.next(); } stream.start = stream.pos; } else if (ch == '"' || ch == "'") { // skip values in strings if (!stream.skipString(ch)) { throw new Error('Invalid attribute set'); } } } parts.push(utils.trim(stream.current())); return parts; }
[ "function", "splitAttributes", "(", "attrSet", ")", "{", "attrSet", "=", "utils", ".", "trim", "(", "attrSet", ")", ";", "var", "parts", "=", "[", "]", ";", "// split attribute set by spaces", "var", "stream", "=", "stringStream", "(", "attrSet", ")", ",", "ch", ";", "while", "(", "(", "ch", "=", "stream", ".", "next", "(", ")", ")", ")", "{", "if", "(", "ch", "==", "' '", ")", "{", "parts", ".", "push", "(", "utils", ".", "trim", "(", "stream", ".", "current", "(", ")", ")", ")", ";", "// skip spaces", "while", "(", "stream", ".", "peek", "(", ")", "==", "' '", ")", "{", "stream", ".", "next", "(", ")", ";", "}", "stream", ".", "start", "=", "stream", ".", "pos", ";", "}", "else", "if", "(", "ch", "==", "'\"'", "||", "ch", "==", "\"'\"", ")", "{", "// skip values in strings", "if", "(", "!", "stream", ".", "skipString", "(", "ch", ")", ")", "{", "throw", "new", "Error", "(", "'Invalid attribute set'", ")", ";", "}", "}", "}", "parts", ".", "push", "(", "utils", ".", "trim", "(", "stream", ".", "current", "(", ")", ")", ")", ";", "return", "parts", ";", "}" ]
Splits attribute set into a list of attributes string @param {String} attrSet @return {Array}
[ "Splits", "attribute", "set", "into", "a", "list", "of", "attributes", "string" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L577-L602
11,290
emmetio/emmet
lib/parser/abbreviation.js
unquote
function unquote(str) { var ch = str.charAt(0); if (ch == '"' || ch == "'") { str = str.substr(1); var last = str.charAt(str.length - 1); if (last === ch) { str = str.substr(0, str.length - 1); } } return str; }
javascript
function unquote(str) { var ch = str.charAt(0); if (ch == '"' || ch == "'") { str = str.substr(1); var last = str.charAt(str.length - 1); if (last === ch) { str = str.substr(0, str.length - 1); } } return str; }
[ "function", "unquote", "(", "str", ")", "{", "var", "ch", "=", "str", ".", "charAt", "(", "0", ")", ";", "if", "(", "ch", "==", "'\"'", "||", "ch", "==", "\"'\"", ")", "{", "str", "=", "str", ".", "substr", "(", "1", ")", ";", "var", "last", "=", "str", ".", "charAt", "(", "str", ".", "length", "-", "1", ")", ";", "if", "(", "last", "===", "ch", ")", "{", "str", "=", "str", ".", "substr", "(", "0", ",", "str", ".", "length", "-", "1", ")", ";", "}", "}", "return", "str", ";", "}" ]
Removes opening and closing quotes from given string @param {String} str @return {String}
[ "Removes", "opening", "and", "closing", "quotes", "from", "given", "string" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L609-L620
11,291
emmetio/emmet
lib/parser/abbreviation.js
function(abbr, options) { if (!abbr) return ''; if (typeof options == 'string') { throw new Error('Deprecated use of `expand` method: `options` must be object'); } options = options || {}; if (!options.syntax) { options.syntax = utils.defaultSyntax(); } var p = profile.get(options.profile, options.syntax); tabStops.resetTabstopIndex(); var data = filters.extract(abbr); var outputTree = this.parse(data[0], options); var filtersList = filters.composeList(options.syntax, p, data[1]); filters.apply(outputTree, filtersList, p); return outputTree.valueOf(); }
javascript
function(abbr, options) { if (!abbr) return ''; if (typeof options == 'string') { throw new Error('Deprecated use of `expand` method: `options` must be object'); } options = options || {}; if (!options.syntax) { options.syntax = utils.defaultSyntax(); } var p = profile.get(options.profile, options.syntax); tabStops.resetTabstopIndex(); var data = filters.extract(abbr); var outputTree = this.parse(data[0], options); var filtersList = filters.composeList(options.syntax, p, data[1]); filters.apply(outputTree, filtersList, p); return outputTree.valueOf(); }
[ "function", "(", "abbr", ",", "options", ")", "{", "if", "(", "!", "abbr", ")", "return", "''", ";", "if", "(", "typeof", "options", "==", "'string'", ")", "{", "throw", "new", "Error", "(", "'Deprecated use of `expand` method: `options` must be object'", ")", ";", "}", "options", "=", "options", "||", "{", "}", ";", "if", "(", "!", "options", ".", "syntax", ")", "{", "options", ".", "syntax", "=", "utils", ".", "defaultSyntax", "(", ")", ";", "}", "var", "p", "=", "profile", ".", "get", "(", "options", ".", "profile", ",", "options", ".", "syntax", ")", ";", "tabStops", ".", "resetTabstopIndex", "(", ")", ";", "var", "data", "=", "filters", ".", "extract", "(", "abbr", ")", ";", "var", "outputTree", "=", "this", ".", "parse", "(", "data", "[", "0", "]", ",", "options", ")", ";", "var", "filtersList", "=", "filters", ".", "composeList", "(", "options", ".", "syntax", ",", "p", ",", "data", "[", "1", "]", ")", ";", "filters", ".", "apply", "(", "outputTree", ",", "filtersList", ",", "p", ")", ";", "return", "outputTree", ".", "valueOf", "(", ")", ";", "}" ]
Expands given abbreviation into a formatted code structure. This is the main method that is used for expanding abbreviation @param {String} abbr Abbreviation to expand @param {Options} options Additional options for abbreviation expanding and transformation: `syntax`, `profile`, `contextNode` etc. @return {String}
[ "Expands", "given", "abbreviation", "into", "a", "formatted", "code", "structure", ".", "This", "is", "the", "main", "method", "that", "is", "used", "for", "expanding", "abbreviation" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/parser/abbreviation.js#L941-L963
11,292
emmetio/emmet
lib/action/selectItem.js
findItem
function findItem(editor, isBackward, extractFn, rangeFn) { var content = editorUtils.outputInfo(editor).content; var contentLength = content.length; var itemRange, rng; /** @type Range */ var prevRange = range(-1, 0); /** @type Range */ var sel = range(editor.getSelectionRange()); var searchPos = sel.start, loop = 100000; // endless loop protection while (searchPos >= 0 && searchPos < contentLength && --loop > 0) { if ( (itemRange = extractFn(content, searchPos, isBackward)) ) { if (prevRange.equal(itemRange)) { break; } prevRange = itemRange.clone(); rng = rangeFn(itemRange.substring(content), itemRange.start, sel.clone()); if (rng) { editor.createSelection(rng.start, rng.end); return true; } else { searchPos = isBackward ? itemRange.start : itemRange.end - 1; } } searchPos += isBackward ? -1 : 1; } return false; }
javascript
function findItem(editor, isBackward, extractFn, rangeFn) { var content = editorUtils.outputInfo(editor).content; var contentLength = content.length; var itemRange, rng; /** @type Range */ var prevRange = range(-1, 0); /** @type Range */ var sel = range(editor.getSelectionRange()); var searchPos = sel.start, loop = 100000; // endless loop protection while (searchPos >= 0 && searchPos < contentLength && --loop > 0) { if ( (itemRange = extractFn(content, searchPos, isBackward)) ) { if (prevRange.equal(itemRange)) { break; } prevRange = itemRange.clone(); rng = rangeFn(itemRange.substring(content), itemRange.start, sel.clone()); if (rng) { editor.createSelection(rng.start, rng.end); return true; } else { searchPos = isBackward ? itemRange.start : itemRange.end - 1; } } searchPos += isBackward ? -1 : 1; } return false; }
[ "function", "findItem", "(", "editor", ",", "isBackward", ",", "extractFn", ",", "rangeFn", ")", "{", "var", "content", "=", "editorUtils", ".", "outputInfo", "(", "editor", ")", ".", "content", ";", "var", "contentLength", "=", "content", ".", "length", ";", "var", "itemRange", ",", "rng", ";", "/** @type Range */", "var", "prevRange", "=", "range", "(", "-", "1", ",", "0", ")", ";", "/** @type Range */", "var", "sel", "=", "range", "(", "editor", ".", "getSelectionRange", "(", ")", ")", ";", "var", "searchPos", "=", "sel", ".", "start", ",", "loop", "=", "100000", ";", "// endless loop protection", "while", "(", "searchPos", ">=", "0", "&&", "searchPos", "<", "contentLength", "&&", "--", "loop", ">", "0", ")", "{", "if", "(", "(", "itemRange", "=", "extractFn", "(", "content", ",", "searchPos", ",", "isBackward", ")", ")", ")", "{", "if", "(", "prevRange", ".", "equal", "(", "itemRange", ")", ")", "{", "break", ";", "}", "prevRange", "=", "itemRange", ".", "clone", "(", ")", ";", "rng", "=", "rangeFn", "(", "itemRange", ".", "substring", "(", "content", ")", ",", "itemRange", ".", "start", ",", "sel", ".", "clone", "(", ")", ")", ";", "if", "(", "rng", ")", "{", "editor", ".", "createSelection", "(", "rng", ".", "start", ",", "rng", ".", "end", ")", ";", "return", "true", ";", "}", "else", "{", "searchPos", "=", "isBackward", "?", "itemRange", ".", "start", ":", "itemRange", ".", "end", "-", "1", ";", "}", "}", "searchPos", "+=", "isBackward", "?", "-", "1", ":", "1", ";", "}", "return", "false", ";", "}" ]
Generic function for searching for items to select @param {IEmmetEditor} editor @param {Boolean} isBackward Search backward (search forward otherwise) @param {Function} extractFn Function that extracts item content @param {Function} rangeFn Function that search for next token range
[ "Generic", "function", "for", "searching", "for", "items", "to", "select" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L31-L63
11,293
emmetio/emmet
lib/action/selectItem.js
findNextHTMLItem
function findNextHTMLItem(editor) { var isFirst = true; return findItem(editor, false, function(content, searchPos){ if (isFirst) { isFirst = false; return findOpeningTagFromPosition(content, searchPos); } else { return getOpeningTagFromPosition(content, searchPos); } }, function(tag, offset, selRange) { return getRangeForHTMLItem(tag, offset, selRange, false); }); }
javascript
function findNextHTMLItem(editor) { var isFirst = true; return findItem(editor, false, function(content, searchPos){ if (isFirst) { isFirst = false; return findOpeningTagFromPosition(content, searchPos); } else { return getOpeningTagFromPosition(content, searchPos); } }, function(tag, offset, selRange) { return getRangeForHTMLItem(tag, offset, selRange, false); }); }
[ "function", "findNextHTMLItem", "(", "editor", ")", "{", "var", "isFirst", "=", "true", ";", "return", "findItem", "(", "editor", ",", "false", ",", "function", "(", "content", ",", "searchPos", ")", "{", "if", "(", "isFirst", ")", "{", "isFirst", "=", "false", ";", "return", "findOpeningTagFromPosition", "(", "content", ",", "searchPos", ")", ";", "}", "else", "{", "return", "getOpeningTagFromPosition", "(", "content", ",", "searchPos", ")", ";", "}", "}", ",", "function", "(", "tag", ",", "offset", ",", "selRange", ")", "{", "return", "getRangeForHTMLItem", "(", "tag", ",", "offset", ",", "selRange", ",", "false", ")", ";", "}", ")", ";", "}" ]
XXX HTML section Find next HTML item @param {IEmmetEditor} editor
[ "XXX", "HTML", "section", "Find", "next", "HTML", "item" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L71-L83
11,294
emmetio/emmet
lib/action/selectItem.js
findPrevHTMLItem
function findPrevHTMLItem(editor) { return findItem(editor, true, getOpeningTagFromPosition, function (tag, offset, selRange) { return getRangeForHTMLItem(tag, offset, selRange, true); }); }
javascript
function findPrevHTMLItem(editor) { return findItem(editor, true, getOpeningTagFromPosition, function (tag, offset, selRange) { return getRangeForHTMLItem(tag, offset, selRange, true); }); }
[ "function", "findPrevHTMLItem", "(", "editor", ")", "{", "return", "findItem", "(", "editor", ",", "true", ",", "getOpeningTagFromPosition", ",", "function", "(", "tag", ",", "offset", ",", "selRange", ")", "{", "return", "getRangeForHTMLItem", "(", "tag", ",", "offset", ",", "selRange", ",", "true", ")", ";", "}", ")", ";", "}" ]
Find previous HTML item @param {IEmmetEditor} editor
[ "Find", "previous", "HTML", "item" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L89-L93
11,295
emmetio/emmet
lib/action/selectItem.js
makePossibleRangesHTML
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(); }); }
javascript
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" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L101-L159
11,296
emmetio/emmet
lib/action/selectItem.js
getRangeForHTMLItem
function getRangeForHTMLItem(tag, offset, selRange, isBackward) { var ranges = makePossibleRangesHTML(tag, xmlParser.parse(tag), offset); if (isBackward) ranges.reverse(); // try to find selected range var curRange = utils.find(ranges, function(r) { return r.equal(selRange); }); if (curRange) { var ix = ranges.indexOf(curRange); if (ix < ranges.length - 1) return ranges[ix + 1]; return null; } // no selected range, find nearest one if (isBackward) // search backward return utils.find(ranges, function(r) { return r.start < selRange.start; }); // search forward // to deal with overlapping ranges (like full attribute definition // and attribute value) let's find range under caret first if (!curRange) { var matchedRanges = ranges.filter(function(r) { return r.inside(selRange.end); }); if (matchedRanges.length > 1) return matchedRanges[1]; } return utils.find(ranges, function(r) { return r.end > selRange.end; }); }
javascript
function getRangeForHTMLItem(tag, offset, selRange, isBackward) { var ranges = makePossibleRangesHTML(tag, xmlParser.parse(tag), offset); if (isBackward) ranges.reverse(); // try to find selected range var curRange = utils.find(ranges, function(r) { return r.equal(selRange); }); if (curRange) { var ix = ranges.indexOf(curRange); if (ix < ranges.length - 1) return ranges[ix + 1]; return null; } // no selected range, find nearest one if (isBackward) // search backward return utils.find(ranges, function(r) { return r.start < selRange.start; }); // search forward // to deal with overlapping ranges (like full attribute definition // and attribute value) let's find range under caret first if (!curRange) { var matchedRanges = ranges.filter(function(r) { return r.inside(selRange.end); }); if (matchedRanges.length > 1) return matchedRanges[1]; } return utils.find(ranges, function(r) { return r.end > selRange.end; }); }
[ "function", "getRangeForHTMLItem", "(", "tag", ",", "offset", ",", "selRange", ",", "isBackward", ")", "{", "var", "ranges", "=", "makePossibleRangesHTML", "(", "tag", ",", "xmlParser", ".", "parse", "(", "tag", ")", ",", "offset", ")", ";", "if", "(", "isBackward", ")", "ranges", ".", "reverse", "(", ")", ";", "// try to find selected range", "var", "curRange", "=", "utils", ".", "find", "(", "ranges", ",", "function", "(", "r", ")", "{", "return", "r", ".", "equal", "(", "selRange", ")", ";", "}", ")", ";", "if", "(", "curRange", ")", "{", "var", "ix", "=", "ranges", ".", "indexOf", "(", "curRange", ")", ";", "if", "(", "ix", "<", "ranges", ".", "length", "-", "1", ")", "return", "ranges", "[", "ix", "+", "1", "]", ";", "return", "null", ";", "}", "// no selected range, find nearest one", "if", "(", "isBackward", ")", "// search backward", "return", "utils", ".", "find", "(", "ranges", ",", "function", "(", "r", ")", "{", "return", "r", ".", "start", "<", "selRange", ".", "start", ";", "}", ")", ";", "// search forward", "// to deal with overlapping ranges (like full attribute definition", "// and attribute value) let's find range under caret first", "if", "(", "!", "curRange", ")", "{", "var", "matchedRanges", "=", "ranges", ".", "filter", "(", "function", "(", "r", ")", "{", "return", "r", ".", "inside", "(", "selRange", ".", "end", ")", ";", "}", ")", ";", "if", "(", "matchedRanges", ".", "length", ">", "1", ")", "return", "matchedRanges", "[", "1", "]", ";", "}", "return", "utils", ".", "find", "(", "ranges", ",", "function", "(", "r", ")", "{", "return", "r", ".", "end", ">", "selRange", ".", "end", ";", "}", ")", ";", "}" ]
Returns best HTML tag range match for current selection @param {String} tag Tag declaration @param {Number} offset Tag's position index inside content @param {Range} selRange Selection range @return {Range} Returns range if next item was found, <code>null</code> otherwise
[ "Returns", "best", "HTML", "tag", "range", "match", "for", "current", "selection" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L196-L238
11,297
emmetio/emmet
lib/action/selectItem.js
findOpeningTagFromPosition
function findOpeningTagFromPosition(html, pos) { var tag; while (pos >= 0) { if ((tag = getOpeningTagFromPosition(html, pos))) return tag; pos--; } return null; }
javascript
function findOpeningTagFromPosition(html, pos) { var tag; while (pos >= 0) { if ((tag = getOpeningTagFromPosition(html, pos))) return tag; pos--; } return null; }
[ "function", "findOpeningTagFromPosition", "(", "html", ",", "pos", ")", "{", "var", "tag", ";", "while", "(", "pos", ">=", "0", ")", "{", "if", "(", "(", "tag", "=", "getOpeningTagFromPosition", "(", "html", ",", "pos", ")", ")", ")", "return", "tag", ";", "pos", "--", ";", "}", "return", "null", ";", "}" ]
Search for opening tag in content, starting at specified position @param {String} html Where to search tag @param {Number} pos Character index where to start searching @return {Range} Returns range if valid opening tag was found, <code>null</code> otherwise
[ "Search", "for", "opening", "tag", "in", "content", "starting", "at", "specified", "position" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L247-L256
11,298
emmetio/emmet
lib/action/selectItem.js
findInnerRanges
function findInnerRanges(rule) { // rule selector var ranges = [rule.nameRange(true)]; // find nested sections, keep selectors only var nestedSections = cssSections.nestedSectionsInRule(rule); nestedSections.forEach(function(section) { ranges.push(range.create2(section.start, section._selectorEnd)); }); // add full property ranges and values rule.list().forEach(function(property) { ranges = ranges.concat(makePossibleRangesCSS(property)); }); ranges = range.sort(ranges); // optimize result: remove empty ranges and duplicates ranges = ranges.filter(function(item) { return !!item.length(); }); return utils.unique(ranges, function(item) { return item.toString(); }); }
javascript
function findInnerRanges(rule) { // rule selector var ranges = [rule.nameRange(true)]; // find nested sections, keep selectors only var nestedSections = cssSections.nestedSectionsInRule(rule); nestedSections.forEach(function(section) { ranges.push(range.create2(section.start, section._selectorEnd)); }); // add full property ranges and values rule.list().forEach(function(property) { ranges = ranges.concat(makePossibleRangesCSS(property)); }); ranges = range.sort(ranges); // optimize result: remove empty ranges and duplicates ranges = ranges.filter(function(item) { return !!item.length(); }); return utils.unique(ranges, function(item) { return item.toString(); }); }
[ "function", "findInnerRanges", "(", "rule", ")", "{", "// rule selector", "var", "ranges", "=", "[", "rule", ".", "nameRange", "(", "true", ")", "]", ";", "// find nested sections, keep selectors only", "var", "nestedSections", "=", "cssSections", ".", "nestedSectionsInRule", "(", "rule", ")", ";", "nestedSections", ".", "forEach", "(", "function", "(", "section", ")", "{", "ranges", ".", "push", "(", "range", ".", "create2", "(", "section", ".", "start", ",", "section", ".", "_selectorEnd", ")", ")", ";", "}", ")", ";", "// add full property ranges and values", "rule", ".", "list", "(", ")", ".", "forEach", "(", "function", "(", "property", ")", "{", "ranges", "=", "ranges", ".", "concat", "(", "makePossibleRangesCSS", "(", "property", ")", ")", ";", "}", ")", ";", "ranges", "=", "range", ".", "sort", "(", "ranges", ")", ";", "// optimize result: remove empty ranges and duplicates", "ranges", "=", "ranges", ".", "filter", "(", "function", "(", "item", ")", "{", "return", "!", "!", "item", ".", "length", "(", ")", ";", "}", ")", ";", "return", "utils", ".", "unique", "(", "ranges", ",", "function", "(", "item", ")", "{", "return", "item", ".", "toString", "(", ")", ";", "}", ")", ";", "}" ]
Returns all ranges inside given rule, available for selection @param {CSSEditContainer} rule @return {Array}
[ "Returns", "all", "ranges", "inside", "given", "rule", "available", "for", "selection" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L280-L304
11,299
emmetio/emmet
lib/action/selectItem.js
matchedRangeForCSSProperty
function matchedRangeForCSSProperty(rule, selRange, isBackward) { var ranges = findInnerRanges(rule); if (isBackward) { ranges.reverse(); } // return next to selected range, if possible var r = utils.find(ranges, function(item) { return item.equal(selRange); }); if (r) { return ranges[ranges.indexOf(r) + 1]; } // find matched and (possibly) overlapping ranges var nested = ranges.filter(function(item) { return item.inside(selRange.end); }); if (nested.length) { return nested.sort(function(a, b) { return a.length() - b.length(); })[0]; } // return range next to caret var test = r = utils.find(ranges, isBackward ? function(item) {return item.end < selRange.start;} : function(item) {return item.end > selRange.start;} ); if (!r) { // can’t find anything, just pick first one r = ranges[0]; } return r; }
javascript
function matchedRangeForCSSProperty(rule, selRange, isBackward) { var ranges = findInnerRanges(rule); if (isBackward) { ranges.reverse(); } // return next to selected range, if possible var r = utils.find(ranges, function(item) { return item.equal(selRange); }); if (r) { return ranges[ranges.indexOf(r) + 1]; } // find matched and (possibly) overlapping ranges var nested = ranges.filter(function(item) { return item.inside(selRange.end); }); if (nested.length) { return nested.sort(function(a, b) { return a.length() - b.length(); })[0]; } // return range next to caret var test = r = utils.find(ranges, isBackward ? function(item) {return item.end < selRange.start;} : function(item) {return item.end > selRange.start;} ); if (!r) { // can’t find anything, just pick first one r = ranges[0]; } return r; }
[ "function", "matchedRangeForCSSProperty", "(", "rule", ",", "selRange", ",", "isBackward", ")", "{", "var", "ranges", "=", "findInnerRanges", "(", "rule", ")", ";", "if", "(", "isBackward", ")", "{", "ranges", ".", "reverse", "(", ")", ";", "}", "// return next to selected range, if possible", "var", "r", "=", "utils", ".", "find", "(", "ranges", ",", "function", "(", "item", ")", "{", "return", "item", ".", "equal", "(", "selRange", ")", ";", "}", ")", ";", "if", "(", "r", ")", "{", "return", "ranges", "[", "ranges", ".", "indexOf", "(", "r", ")", "+", "1", "]", ";", "}", "// find matched and (possibly) overlapping ranges", "var", "nested", "=", "ranges", ".", "filter", "(", "function", "(", "item", ")", "{", "return", "item", ".", "inside", "(", "selRange", ".", "end", ")", ";", "}", ")", ";", "if", "(", "nested", ".", "length", ")", "{", "return", "nested", ".", "sort", "(", "function", "(", "a", ",", "b", ")", "{", "return", "a", ".", "length", "(", ")", "-", "b", ".", "length", "(", ")", ";", "}", ")", "[", "0", "]", ";", "}", "// return range next to caret", "var", "test", "=", "r", "=", "utils", ".", "find", "(", "ranges", ",", "isBackward", "?", "function", "(", "item", ")", "{", "return", "item", ".", "end", "<", "selRange", ".", "start", ";", "}", ":", "function", "(", "item", ")", "{", "return", "item", ".", "end", ">", "selRange", ".", "start", ";", "}", ")", ";", "if", "(", "!", "r", ")", "{", "// can’t find anything, just pick first one", "r", "=", "ranges", "[", "0", "]", ";", "}", "return", "r", ";", "}" ]
Tries to find matched CSS property and nearest range for selection @param {CSSRule} rule @param {Range} selRange @param {Boolean} isBackward @returns {Range}
[ "Tries", "to", "find", "matched", "CSS", "property", "and", "nearest", "range", "for", "selection" ]
7c9a4623cea414c2f2cc9caebc13355d2bbd898d
https://github.com/emmetio/emmet/blob/7c9a4623cea414c2f2cc9caebc13355d2bbd898d/lib/action/selectItem.js#L356-L395