-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathprism-python-plugin.js
More file actions
65 lines (60 loc) · 2.02 KB
/
Copy pathprism-python-plugin.js
File metadata and controls
65 lines (60 loc) · 2.02 KB
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
Prism.hooks.add('before-highlightall', function (env) {
// This plugin improves prism highliting by adding rules that are missing from default
// prism implementation
Prism.languages.python = Prism.languages.insertBefore("python", "comment", {
definition: {
// Modified behavior of highlighting assignments from the ABNF language
pattern: /([(, \t]+)(?:[a-z][\w-]*|<[^<>\r\n]*>)(?=\s*=)/m,
// here changed "*" to "+" to filter out assignments from arguments
// here added "(," to the group to highlight inline named arguments
lookbehind: true,
alias: 'property',
inside: {
'punctuation': /<|>/
}
},
libraries: {
pattern: /\b(?:os|time|numpy|Path)\b/,
// keywords commonly hightlighted in python editors that are missing from prism
alias: "keyword"
},
GDKeywords: {
pattern: /\b(sdk|GoodDataSDK|GoodDataSdk)\.\b/,
// keywords commonly hightlighted in python editors that are missing from prism
alias: "keyword",
inside: {
'punctuation': /\./
// Avoid higlighting the trailing dot
}
}
}
)
function replace(pattern, replacements) {
return pattern.replace(/<<(\d+)>>/g, function (m, index) {
return '(?:' + replacements[+index] + ')';
});
}
/**
* @param {string} pattern
* @param {string[]} replacements
* @param {string} [flags]
* @returns {RegExp}
*/
function re(pattern, replacements, flags) {
return RegExp(replace(pattern, replacements), flags || '');
}
Prism.languages.insertBefore('jsx', 'script', {
'customScript': {
// Allow for two levels of nesting
pattern: re(/=<BRACES>/.source),
alias: 'language-javascript',
inside: {
'script-punctuation': {
pattern: /^=(?=\{)/,
alias: 'punctuation'
},
rest: Prism.languages.jsx
},
}
}, Prism.languages.jsx.tag);
})