UNPKG

5.85 kBTypeScriptView Raw
1import * as reflect from 'jsii-reflect';
2import { MarkdownDocument } from './markdown-doc';
3import { ApiReferenceSchema, AssemblyMetadataSchema, ClassSchema, ConstructSchema, EnumMemberSchema, EnumSchema, InitializerSchema, InterfaceSchema, JsiiEntity, MethodSchema, ParameterSchema, PropertySchema, Schema, StructSchema, TypeSchema } from '../schema';
4import { Language } from '../transpile/transpile';
5export interface MarkdownFormattingOptions {
6 /**
7 * How jsii entity IDs should be formatted into anchors. This should be
8 * customized in conjunction with `linkFormatter`.
9 *
10 * @param type - the entity we are creating an anchor for
11 *
12 * @experimental
13 * @default - use the full id
14 */
15 readonly anchorFormatter?: (type: JsiiEntity) => string;
16 /**
17 * How should links to entities be rendered. For example, if a class or a
18 * property is referenced within a description or table.
19 *
20 * The `metadata` parameter can be optionally used to customize links based
21 * on whether or not the type belongs to the package / submodule that is
22 * being generated.
23 *
24 * @param type - the entity we are creating a link for
25 * @param metadata - information about the module being docgen-ed
26 *
27 * @experimental
28 * @default - '<a href="#{type.id}">{type.displayName}</a>' if the type
29 * belongs to this package, '{type.fqn}' otherwise
30 */
31 readonly linkFormatter?: (type: JsiiEntity, metadata: AssemblyMetadataSchema) => string;
32 /**
33 * How type signatures should be formatted, including those made of nested
34 * types (like `Map<string, Bucket>`).
35 *
36 * The `metadata` and `linkFormatter` parameters are provided so that links
37 * can be included in the formatted types if desired.
38 *
39 * @param type - the type being formatted
40 * @param metadata - information about the module being docgen-ed
41 * @param linkFormatter - the type link formatter
42 *
43 * @experimental
44 * @default - HTML code block with type references linked
45 * according to `linkFormatter`
46 */
47 readonly typeFormatter?: (type: TypeSchema, metadata: AssemblyMetadataSchema, linkFormatter: (type: JsiiEntity, metadata: AssemblyMetadataSchema) => string) => string;
48 readonly header?: {
49 title: string;
50 id: string;
51 };
52}
53export interface MarkdownRendererOptions extends MarkdownFormattingOptions, AssemblyMetadataSchema {
54 /**
55 * Language the documentation is rendered for.
56 */
57 readonly language: Language;
58}
59/**
60 * Generates `MarkdownDocument` instances from `API.json` or its parts.
61 *
62 * This class can be used in two ways:
63 *
64 * 1. Instantiate it via the constructor with `options`, which requires
65 * passing in some global context about the module and language you are
66 * generated for. (This context can be found in the top-level `metadata`
67 * field of API.json.) Then, call a `visitXxx` method to generate a
68 * `MarkdownDocument` for the appropriate part of the schema.
69 *
70 * 2. Generate a `MarkdownDocument` from the complete `API.json` using the
71 * `fromSchema` static method (no instantiation needed). Global context is
72 * automatically inferred from the API.json.
73 *
74 * Both choices allow customizing the output via `MarkdownFormattingOptions`.
75 */
76export declare class MarkdownRenderer {
77 static fromSchema(schema: Schema, options: MarkdownFormattingOptions): MarkdownDocument;
78 static fromSubmodules(submodules: readonly reflect.Submodule[], fileSuffix: string, options: MarkdownRendererOptions): MarkdownDocument;
79 private readonly anchorFormatter;
80 private readonly linkFormatter;
81 private readonly typeFormatter;
82 private readonly metadata;
83 private readonly language;
84 constructor(options: MarkdownRendererOptions);
85 visitSubmodules(submodules: readonly reflect.Submodule[], fileSuffix: string): MarkdownDocument;
86 visitApiReference(apiRef: ApiReferenceSchema, header?: {
87 title: string;
88 id: string;
89 }): MarkdownDocument;
90 visitConstructs(constructs: ConstructSchema[]): MarkdownDocument;
91 visitStructs(structs: StructSchema[]): MarkdownDocument;
92 visitClasses(classes: ClassSchema[]): MarkdownDocument;
93 visitInterfaces(ifaces: InterfaceSchema[]): MarkdownDocument;
94 visitEnums(enums: EnumSchema[]): MarkdownDocument;
95 visitConstruct(construct: ConstructSchema): MarkdownDocument;
96 visitStruct(struct: StructSchema): MarkdownDocument;
97 visitClass(klass: ClassSchema): MarkdownDocument;
98 visitInterface(iface: InterfaceSchema): MarkdownDocument;
99 visitEnum(enu: EnumSchema): MarkdownDocument;
100 visitEnumMembers(enus: EnumMemberSchema[]): MarkdownDocument;
101 visitProperties(properties: PropertySchema[]): MarkdownDocument;
102 visitInitializer(init: InitializerSchema): MarkdownDocument;
103 visitInstanceMethods(methods: MethodSchema[]): MarkdownDocument;
104 visitStaticFunctions(methods: MethodSchema[]): MarkdownDocument;
105 visitConstants(constants: PropertySchema[]): MarkdownDocument;
106 visitEnumMember(em: EnumMemberSchema): MarkdownDocument;
107 visitProperty(prop: PropertySchema): MarkdownDocument;
108 visitParameter(parameter: ParameterSchema): MarkdownDocument;
109 visitInstanceMethod(method: MethodSchema): MarkdownDocument;
110 visitStaticFunction(method: MethodSchema): MarkdownDocument;
111 visitConstant(constant: PropertySchema): MarkdownDocument;
112 private createTable;
113 private createTableWithTypes;
114}
115export declare const defaultAnchorFormatter: (type: JsiiEntity) => string;
116export declare const defaultLinkFormatter: (type: JsiiEntity, metadata: AssemblyMetadataSchema) => string;
117export declare const defaultTypeFormatter: (type: TypeSchema, metadata: AssemblyMetadataSchema, linkFormatter: (type: JsiiEntity, metadata: AssemblyMetadataSchema) => string) => string;