-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocs-theme.ts
More file actions
45 lines (39 loc) · 1.31 KB
/
docs-theme.ts
File metadata and controls
45 lines (39 loc) · 1.31 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
import { type Application } from 'typedoc'
import { MarkdownPageEvent, MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown'
class MyMarkdownTheme extends MarkdownTheme {
// @ts-ignore
getRenderContext(page) {
const ctx = new MarkdownThemeContext(this, page, this.application.options)
{
const orig = ctx.partials.typeArguments
ctx.partials.typeArguments = function (typeArguments, options) {
// @ts-ignore
if (typeArguments[0]?.name === 'ArrayBufferLike') return ''
// @ts-ignore
return orig.call(this, typeArguments, options)
}
}
const sources = ctx.partials.sources
ctx.partials.sources = function (...args) {
const src = sources.call(this, args[0])
return `[source]${src.slice(src.indexOf(']') + 1)}`
}
return ctx
}
render(page: MarkdownPageEvent): string {
const res = super.render(page)
return res
.replaceAll(
`## Constructors
### Constructor`,
'## Constructor',
)
.replaceAll('\\| `string` & \\{ \\}', '')
.replaceAll('\\| `string` & `object`', '')
.replaceAll(`\\|`, '∣')
.replaceAll(/\| `options\?` \| \\{[^\|]+\\} \|/g, '\| `options?` \| \|')
}
}
export function load(app: Application) {
app.renderer.defineTheme('my-markdown', MyMarkdownTheme)
}