|
1 | | -import { MarkdownTheme, MarkdownThemeContext } from "typedoc-plugin-markdown"; |
2 | | -import { ReflectionKind } from "typedoc"; |
3 | | -import * as typePartials from "./types.mjs"; |
4 | | - |
5 | | -const KIND_PREFIX = { |
6 | | - [ReflectionKind.Class]: "Class", |
7 | | - [ReflectionKind.Interface]: "Interface", |
8 | | - [ReflectionKind.Enum]: "Enum", |
9 | | - [ReflectionKind.TypeAlias]: "Type", |
10 | | - [ReflectionKind.Namespace]: "Namespace", |
11 | | - [ReflectionKind.Constructor]: "Constructor", |
12 | | - [ReflectionKind.Property]: "Property", |
13 | | - [ReflectionKind.Accessor]: "Accessor", |
14 | | -}; |
15 | | - |
16 | | -const STATIC_PREFIX = { |
17 | | - [ReflectionKind.Method]: "Static method", |
18 | | -}; |
19 | | - |
20 | | -const resolveMemberPrefix = (model) => |
21 | | - model.flags?.isStatic ? STATIC_PREFIX[model.kind] : KIND_PREFIX[model.kind]; |
| 1 | +import { MarkdownTheme, MarkdownThemeContext } from 'typedoc-plugin-markdown'; |
| 2 | +import helpers from './helpers/index.mjs'; |
| 3 | +import partials from './partials/index.mjs'; |
22 | 4 |
|
23 | 5 | export class DocKitTheme extends MarkdownTheme { |
24 | 6 | getRenderContext(page) { |
25 | | - this.application.options.setValue("propertiesFormat", "table"); |
| 7 | + this.application.options.setValue('hidePageHeader', true); |
| 8 | + this.application.options.setValue('hideBreadcrumbs', true); |
| 9 | + this.application.options.setValue('propertiesFormat', 'table'); |
26 | 10 | return new DocKitThemeContext(this, page, this.application.options); |
27 | 11 | } |
28 | 12 | } |
29 | 13 |
|
30 | 14 | export class DocKitThemeContext extends MarkdownThemeContext { |
31 | | - helpers = { |
32 | | - ...this.helpers, |
33 | | - |
34 | | - /** @param {import('typedoc').ParameterReflection} */ |
35 | | - typedListItem: ({ label, name, type, comment }) => { |
36 | | - const namePart = label ? ` ${label}:` : name ? ` \`${name}\`` : ""; |
37 | | - const typePart = type |
38 | | - ? ` ${typeof type === "string" ? type : this.partials.someType(type)}` |
39 | | - : ""; |
40 | | - const descPart = comment |
41 | | - ? ` ${this.helpers.getCommentParts(comment.summary ?? comment.content)}` |
42 | | - : ""; |
43 | | - |
44 | | - return `*${namePart}${typePart}${descPart}`; |
45 | | - }, |
46 | | - |
47 | | - typedList: (entries) => entries.map(this.helpers.typedListItem).join("\n"), |
48 | | - }; |
49 | | - partials = { |
50 | | - ...this.partials, |
51 | | - ...typePartials, |
52 | | - |
53 | | - // Typed Lists |
54 | | - parametersList: this.helpers.typedList, |
55 | | - propertiesTable: this.helpers.typedList, |
56 | | - signature: (model, options) => { |
57 | | - const comment = options.multipleSignatures |
58 | | - ? model.comment |
59 | | - : model.comment || model.parent?.comment; |
| 15 | + helpers = helpers(this); |
60 | 16 |
|
61 | | - return [ |
62 | | - model.typeParameters?.length && |
63 | | - this.partials.typeParametersList(model.typeParameters, { |
64 | | - headingLevel: options.headingLevel, |
65 | | - }), |
66 | | - model.parameters?.length && |
67 | | - this.partials.parametersList(model.parameters, { |
68 | | - headingLevel: options.headingLevel, |
69 | | - }), |
70 | | - this.helpers.typedListItem({ |
71 | | - label: "Returns", |
72 | | - type: model.type ?? "void", |
73 | | - comment: model.comment?.getTag("@returns"), |
74 | | - }), |
75 | | - "", |
76 | | - comment && |
77 | | - this.partials.comment(comment, { |
78 | | - headingLevel: options.headingLevel, |
79 | | - }), |
80 | | - ] |
81 | | - .filter((x) => (typeof x === "string" ? x : Boolean(x))) |
82 | | - .join("\n"); |
83 | | - }, |
| 17 | + partials = partials(this); |
84 | 18 |
|
85 | | - // Titles |
86 | | - memberTitle: (model) => { |
87 | | - const prefix = resolveMemberPrefix(model); |
88 | | - const params = model.signatures?.[0]?.parameters ?? null; |
89 | | - const name = params |
90 | | - ? // TODO: If params optional, wrap in `[]` |
91 | | - `\`${model.name}(${params.map((p) => p.name).join(", ")})\`` |
92 | | - : `\`${model.name}\``; |
93 | | - return prefix ? `${prefix}: ${name}` : name; |
94 | | - }, |
| 19 | + templates = { |
| 20 | + ...this.templates, |
95 | 21 | }; |
96 | 22 | } |
97 | 23 |
|
98 | | -/** @param {import('typedoc').Application} app */ |
99 | 24 | export function load(app) { |
100 | | - app.renderer.defineTheme("doc-kit", DocKitTheme); |
| 25 | + app.renderer.defineTheme('doc-kit', DocKitTheme); |
101 | 26 | } |
0 commit comments