forked from PrismJS/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prism-jsdoc.js
78 lines (72 loc) · 1.98 KB
/
prism-jsdoc.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
67
68
69
70
71
72
73
74
75
76
77
78
(function (Prism) {
var javascript = Prism.languages.javascript;
var type = /{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})+}/.source;
var parameterPrefix = '(@(?:param|arg|argument|property)\\s+(?:' + type + '\\s+)?)';
Prism.languages.jsdoc = Prism.languages.extend('javadoclike', {
'parameter': {
// @param {string} foo - foo bar
pattern: RegExp(parameterPrefix + /[$\w\xA0-\uFFFF.]+(?=\s|$)/.source),
lookbehind: true,
inside: {
'punctuation': /\./
}
}
});
Prism.languages.insertBefore('jsdoc', 'keyword', {
'optional-parameter': {
// @param {string} [baz.foo="bar"] foo bar
pattern: RegExp(parameterPrefix + /\[[$\w\xA0-\uFFFF.]+(?:=[^[\]]+)?\](?=\s|$)/.source),
lookbehind: true,
inside: {
'parameter': {
pattern: /(^\[)[$\w\xA0-\uFFFF\.]+/,
lookbehind: true,
inside: {
'punctuation': /\./
}
},
'code': {
pattern: /(=)[\s\S]*(?=\]$)/,
lookbehind: true,
inside: javascript,
alias: 'language-javascript'
},
'punctuation': /[=[\]]/
}
},
'class-name': [
{
pattern: RegExp(/(@(?:augments|extends|class|interface|memberof!?|template|this|typedef)\s+(?:<TYPE>\s+)?)[A-Z]\w*(?:\.[A-Z]\w*)*/.source.replace(/<TYPE>/g, function () { return type; })),
lookbehind: true,
inside: {
'punctuation': /\./
}
},
{
pattern: RegExp('(@[a-z]+\\s+)' + type),
lookbehind: true,
inside: {
'string': javascript.string,
'number': javascript.number,
'boolean': javascript.boolean,
'keyword': Prism.languages.typescript.keyword,
'operator': /=>|\.\.\.|[&|?:*]/,
'punctuation': /[.,;=<>{}()[\]]/
}
}
],
'example': {
pattern: /(@example\s+)[^@]+?(?=\s*(?:\*\s*)?(?:@\w|\*\/))/,
lookbehind: true,
inside: {
'code': {
pattern: /^(\s*(?:\*\s*)?).+$/m,
lookbehind: true,
inside: javascript,
alias: 'language-javascript'
}
}
}
});
Prism.languages.javadoclike.addSupport('javascript', Prism.languages.jsdoc);
}(Prism));