forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de2bda0
commit f178a53
Showing
8 changed files
with
211 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
exports.activate = function () { | ||
exports.activate = function() { | ||
// Highlight macro bodies as C/C++ | ||
for (const language of ['c', 'cpp']) { | ||
for (const nodeType of ['preproc_def', 'preproc_function_def']) { | ||
atom.grammars.addInjectionPoint(`source.${language}`, { | ||
type: nodeType, | ||
language (node) { return language }, | ||
content (node) { return node.lastNamedChild } | ||
}) | ||
language(node) { | ||
return language; | ||
}, | ||
content(node) { | ||
return node.lastNamedChild; | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,63 @@ | ||
exports.activate = function () { | ||
exports.activate = function() { | ||
atom.grammars.addInjectionPoint('text.html.basic', { | ||
type: 'script_element', | ||
language () { return 'javascript' }, | ||
content (node) { return node.child(1) } | ||
}) | ||
language() { | ||
return 'javascript'; | ||
}, | ||
content(node) { | ||
return node.child(1); | ||
} | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('text.html.basic', { | ||
type: 'style_element', | ||
language () { return 'css' }, | ||
content (node) { return node.child(1) } | ||
}) | ||
language() { | ||
return 'css'; | ||
}, | ||
content(node) { | ||
return node.child(1); | ||
} | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('text.html.ejs', { | ||
type: 'template', | ||
language (node) { return 'javascript' }, | ||
content (node) { return node.descendantsOfType('code') }, | ||
language(node) { | ||
return 'javascript'; | ||
}, | ||
content(node) { | ||
return node.descendantsOfType('code'); | ||
}, | ||
newlinesBetween: true | ||
}) | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('text.html.ejs', { | ||
type: 'template', | ||
language (node) { return 'html' }, | ||
content (node) { return node.descendantsOfType('content') } | ||
}) | ||
language(node) { | ||
return 'html'; | ||
}, | ||
content(node) { | ||
return node.descendantsOfType('content'); | ||
} | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('text.html.erb', { | ||
type: 'template', | ||
language (node) { return 'ruby' }, | ||
content (node) { return node.descendantsOfType('code') }, | ||
language(node) { | ||
return 'ruby'; | ||
}, | ||
content(node) { | ||
return node.descendantsOfType('code'); | ||
}, | ||
newlinesBetween: true | ||
}) | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('text.html.erb', { | ||
type: 'template', | ||
language (node) { return 'html' }, | ||
content (node) { return node.descendantsOfType('content') } | ||
}) | ||
} | ||
language(node) { | ||
return 'html'; | ||
}, | ||
content(node) { | ||
return node.descendantsOfType('content'); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,86 @@ | ||
exports.activate = function () { | ||
if (!atom.grammars.addInjectionPoint) return | ||
exports.activate = function() { | ||
if (!atom.grammars.addInjectionPoint) return; | ||
|
||
atom.grammars.addInjectionPoint('source.js', { | ||
type: 'call_expression', | ||
|
||
language (callExpression) { | ||
const {firstChild} = callExpression | ||
language(callExpression) { | ||
const { firstChild } = callExpression; | ||
switch (firstChild.type) { | ||
case 'identifier': | ||
return languageStringForTemplateTag(firstChild.text) | ||
return languageStringForTemplateTag(firstChild.text); | ||
case 'call_expression': | ||
return languageStringForTemplateTag(firstChild.children[0].text) | ||
return languageStringForTemplateTag(firstChild.children[0].text); | ||
case 'member_expression': | ||
if (firstChild.startPosition.row === firstChild.endPosition.row) { | ||
return languageStringForTemplateTag(firstChild.text) | ||
return languageStringForTemplateTag(firstChild.text); | ||
} | ||
} | ||
}, | ||
|
||
content (callExpression) { | ||
const {lastChild} = callExpression | ||
content(callExpression) { | ||
const { lastChild } = callExpression; | ||
if (lastChild.type === 'template_string') { | ||
return lastChild | ||
return lastChild; | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('source.js', { | ||
type: 'assignment_expression', | ||
|
||
language (callExpression) { | ||
const {firstChild} = callExpression | ||
language(callExpression) { | ||
const { firstChild } = callExpression; | ||
if (firstChild.type === 'member_expression') { | ||
if (firstChild.lastChild.text === 'innerHTML') { | ||
return 'html' | ||
return 'html'; | ||
} | ||
} | ||
}, | ||
|
||
content (callExpression) { | ||
const {lastChild} = callExpression | ||
content(callExpression) { | ||
const { lastChild } = callExpression; | ||
if (lastChild.type === 'template_string') { | ||
return lastChild | ||
return lastChild; | ||
} | ||
} | ||
}) | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('source.js', { | ||
type: 'regex_pattern', | ||
language (regex) { return 'regex' }, | ||
content (regex) { return regex } | ||
}) | ||
language(regex) { | ||
return 'regex'; | ||
}, | ||
content(regex) { | ||
return regex; | ||
} | ||
}); | ||
|
||
for (const scopeName of ['source.js', 'source.flow', 'source.ts']) { | ||
atom.grammars.addInjectionPoint(scopeName, { | ||
type: 'comment', | ||
language (comment) { | ||
if (comment.text.startsWith('/**')) return 'jsdoc' | ||
language(comment) { | ||
if (comment.text.startsWith('/**')) return 'jsdoc'; | ||
}, | ||
content (comment) { | ||
return comment | ||
content(comment) { | ||
return comment; | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
}; | ||
|
||
const CSS_REGEX = /\bstyled\b|\bcss\b/i | ||
const GQL_REGEX = /\bgraphql\b|\bgql\b/i | ||
const SQL_REGEX = /\bsql\b/i | ||
const CSS_REGEX = /\bstyled\b|\bcss\b/i; | ||
const GQL_REGEX = /\bgraphql\b|\bgql\b/i; | ||
const SQL_REGEX = /\bsql\b/i; | ||
|
||
function languageStringForTemplateTag (tag) { | ||
function languageStringForTemplateTag(tag) { | ||
if (CSS_REGEX.test(tag)) { | ||
return 'CSS' | ||
return 'CSS'; | ||
} else if (GQL_REGEX.test(tag)) { | ||
return 'GraphQL' | ||
return 'GraphQL'; | ||
} else if (SQL_REGEX.test(tag)) { | ||
return 'SQL' | ||
return 'SQL'; | ||
} else { | ||
return tag | ||
return tag; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
exports.activate = function() { | ||
if (!atom.grammars.addInjectionPoint) return | ||
if (!atom.grammars.addInjectionPoint) return; | ||
|
||
atom.grammars.addInjectionPoint('source.ruby', { | ||
type: 'heredoc_body', | ||
language (node) { return node.lastChild.text }, | ||
content (node) { return node } | ||
}) | ||
language(node) { | ||
return node.lastChild.text; | ||
}, | ||
content(node) { | ||
return node; | ||
} | ||
}); | ||
|
||
atom.grammars.addInjectionPoint('source.ruby', { | ||
type: 'regex', | ||
language () { return 'regex' }, | ||
content (node) { return node } | ||
}) | ||
} | ||
language() { | ||
return 'regex'; | ||
}, | ||
content(node) { | ||
return node; | ||
} | ||
}); | ||
}; |
Oops, something went wrong.