forked from FormidableLabs/prism-react-renderer
/
scopeMapper.js
executable file
·66 lines (61 loc) · 1.95 KB
/
scopeMapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const scopeMap = {
comment: "comment",
punctuation: "punctuation",
string: "string",
variable: "variable",
constant: "constant",
header: "prolog",
"support.function.magic": "constant",
"support.variable": "constant",
"entity.name.type.namespace": "namespace",
"keyword.operator": "operator",
"constant.numeric": "number",
"constant.character.numeric": "number",
"support.type.vendor.property-name": "property",
"support.type.property-name": "property",
"meta.property-list": "property",
"entity.name.tag": "tag",
"entity.name.function": "function",
"entity.name.class": "class-name",
"entity.name.tag.doctype": "doctype",
"meta.selector": "selector",
"entity.other.attribute-name": "attr-name",
"meta.attribute-selector": "attr-name",
"constant.other": "constant",
"constant.other.symbol": "symbol",
"constant.language.boolean": "boolean",
"constant.character": "char",
"entity.name.tag": "tag",
"meta.tag.html": "tag",
"meta.tag.js": "tag",
"meta.selector": "selector",
"support.function": "builtin",
"support.type.property-name": "builtin",
"variable.other.constant": "builtin",
"constant.language": "builtin",
"keyword.control": "keyword",
"keyword.other": "keyword",
"variable.parameter.url": "url",
"meta.at-rule": "atrule",
"source.css.scss": "atrule",
"markup.inserted": "inserted",
"markup.deleted": "deleted",
"markup.changed": "changed",
}
const mapScope = scope => {
// If the scope includes a whitespace, it's a specific
// type that we don't support
if (scope.includes(" ")) {
return undefined
}
const scopeAccess = scope.split(".")
for (let i = scopeAccess.length; i >= 0; i--) {
const searchScope = scopeAccess.slice(0, i).join(".")
const outputScope = scopeMap[searchScope]
if (outputScope !== undefined) {
return outputScope
}
}
return undefined
}
module.exports = { mapScope }