|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: Markdown Generator |
| 4 | +parent: API Reference |
| 5 | +nav_order: 2 |
| 6 | +--- |
| 7 | + |
| 8 | +# MarkdownGenerator API |
| 9 | + |
| 10 | +The `MarkdownGenerator` class generates Markdown documentation from a parsed API/type definition object, such as the output of your Lua/Luau parser or a custom API description. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +The Markdown generator is included in LuaTS. Import it as follows: |
| 17 | + |
| 18 | +```typescript |
| 19 | +import { MarkdownGenerator } from 'luats/dist/generators/markdown/generator'; |
| 20 | +``` |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +### Basic Example |
| 27 | + |
| 28 | +```typescript |
| 29 | +import { MarkdownGenerator } from 'luats/dist/generators/markdown/generator'; |
| 30 | + |
| 31 | +const apiObject = { |
| 32 | + name: "My API", |
| 33 | + description: "This is an example API.", |
| 34 | + functions: [ |
| 35 | + { |
| 36 | + name: "foo", |
| 37 | + description: "Does foo things.", |
| 38 | + signature: "function foo(bar: string): number", |
| 39 | + parameters: [ |
| 40 | + { name: "bar", type: "string", description: "The bar argument." } |
| 41 | + ], |
| 42 | + returns: { type: "number", description: "The result." } |
| 43 | + } |
| 44 | + ], |
| 45 | + types: [ |
| 46 | + { |
| 47 | + name: "FooType", |
| 48 | + description: "A type for foo.", |
| 49 | + definition: "type FooType = { bar: string }" |
| 50 | + } |
| 51 | + ], |
| 52 | + examples: [ |
| 53 | + { |
| 54 | + title: "Basic usage", |
| 55 | + description: "How to use foo.", |
| 56 | + code: "foo('hello')" |
| 57 | + } |
| 58 | + ] |
| 59 | +}; |
| 60 | + |
| 61 | +const generator = new MarkdownGenerator({ title: "API Reference" }); |
| 62 | +const markdown = generator.generate(apiObject); |
| 63 | + |
| 64 | +console.log(markdown); |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## Options |
| 70 | + |
| 71 | +| Option | Type | Description | |
| 72 | +|------------------|-----------|------------------------------------------------------------------| |
| 73 | +| `title` | `string` | Title for the generated Markdown (overrides `api.name`) | |
| 74 | +| `description` | `string` | Description for the Markdown (overrides `api.description`) | |
| 75 | +| `includeTypes` | `boolean` | Whether to include the Types section (default: `true`) | |
| 76 | +| `includeExamples`| `boolean` | Whether to include the Examples section (default: `true`) | |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## API Object Structure |
| 81 | + |
| 82 | +- `name`: (string) Name of the API/module. |
| 83 | +- `description`: (string) Description of the API/module. |
| 84 | +- `functions`: (array) List of function objects. |
| 85 | + - `name`: (string) Function name. |
| 86 | + - `description`: (string) Function description. |
| 87 | + - `signature`: (string, optional) Function signature (if omitted, generated from parameters). |
| 88 | + - `parameters`: (array) List of parameter objects: |
| 89 | + - `name`: (string) Parameter name. |
| 90 | + - `type`: (string) Parameter type. |
| 91 | + - `description`: (string, optional) Parameter description. |
| 92 | + - `returns`: (object, optional) |
| 93 | + - `type`: (string) Return type. |
| 94 | + - `description`: (string, optional) Return description. |
| 95 | +- `types`: (array) List of type objects. |
| 96 | + - `name`: (string) Type name. |
| 97 | + - `description`: (string, optional) Type description. |
| 98 | + - `definition`: (string) Type definition (as Lua/Luau code). |
| 99 | +- `examples`: (array) List of example objects. |
| 100 | + - `title`: (string, optional) Example title. |
| 101 | + - `description`: (string, optional) Example description. |
| 102 | + - `code`: (string) Example code (Lua/Luau). |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## Output Format |
| 107 | + |
| 108 | +The generated Markdown includes: |
| 109 | + |
| 110 | +- Title and description |
| 111 | +- Table of Contents |
| 112 | +- Functions section (with signatures, parameters, and return types) |
| 113 | +- Types section (with code blocks) |
| 114 | +- Examples section (with code blocks) |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## Advanced |
| 119 | + |
| 120 | +- You can customize the API object structure to fit your needs, as long as you provide the required fields. |
| 121 | +- The generator is designed to work with the output of the LuaTS parser, but you can use it with any compatible object. |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## See Also |
| 126 | + |
| 127 | +- [LuaTS TypeScript Generator](./api-typescript-generator.md) |
| 128 | +- [API Reference](./api-reference.md) |
0 commit comments