-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
jsdoc.js
99 lines (98 loc) · 2.93 KB
/
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// @ts-nocheck
import refractorJavadoclike from './javadoclike.js'
import refractorJavascript from './javascript.js'
import refractorTypescript from './typescript.js'
jsdoc.displayName = 'jsdoc'
jsdoc.aliases = []
/** @type {import('../core.js').Syntax} */
export default function jsdoc(Prism) {
Prism.register(refractorJavadoclike)
Prism.register(refractorJavascript)
Prism.register(refractorTypescript)
;(function (Prism) {
var javascript = Prism.languages.javascript
var type = /\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})+\}/.source
var parameterPrefix =
'(@(?:arg|argument|param|property)\\s+(?:' + type + '\\s+)?)'
Prism.languages.jsdoc = Prism.languages.extend('javadoclike', {
parameter: {
// @param {string} foo - foo bar
pattern: RegExp(
parameterPrefix + /(?:(?!\s)[$\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 +
/\[(?:(?!\s)[$\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|class|extends|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]|\s+(?!\s))+?(?=\s*(?:\*\s*)?(?:@\w|\*\/))/,
lookbehind: true,
inside: {
code: {
pattern: /^([\t ]*(?:\*\s*)?)\S.*$/m,
lookbehind: true,
inside: javascript,
alias: 'language-javascript'
}
}
}
})
Prism.languages.javadoclike.addSupport('javascript', Prism.languages.jsdoc)
})(Prism)
}