forked from dayjs/dayjs-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.js
60 lines (52 loc) · 1.41 KB
/
plugin.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
const translate = require(process.cwd() + '/node_modules/docusaurus/lib/server/translate.js').translate;
const parse = md => {
if (md.src.charCodeAt(md.pos) !== 64) { // @
return false
}
const match = /@>>?([\S]+)/.exec(md.src)
if (!match) return false
md.pos += match[0].length
const token = {
type: 'pluginNotice',
level: md.level,
content: {
inline: md.src.indexOf('>>') > -1,
plugin: match[1],
match: match,
},
}
md.push(token)
return true
}
const render = (tokens, idx) => {
const token = tokens[idx]
const pluginName = token.content.plugin
let pluginSnakeName
if (['UTC'].indexOf(pluginName) === -1) {
pluginSnakeName = pluginName.replace(/([A-Z])/g, "-$1").toLowerCase().slice(1)
} else {
pluginSnakeName = pluginName.toLowerCase()
}
const isInline = token.content.inline
if (isInline) {
return `(
${translate("dependent|plugin")}
<a href="../plugin/${pluginSnakeName}">
<code>${token.content.plugin}</code>
</a>
${translate("plugin|plugin")}
)`
}
return `<blockquote>
${translate("This requires the|plugin")}
<a href="../plugin/${pluginSnakeName}">
<code>${token.content.plugin}</code>
</a>
${translate("plugin to work|plugin")}
</blockquote>`
}
const pluginNotice = ctx => {
ctx.inline.ruler.push('pluginNotice', parse)
ctx.renderer.rules['pluginNotice'] = render
}
module.exports = pluginNotice