or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration-options.mdevents-hooks.mdindex.mdplugin-bootstrap.mdrouting-system.mdtheme-system.md

routing-system.mddocs/

0

# Routing System

1

2

Multiple router implementations providing different strategies for organizing generated documentation files, from member-based to module-based file organization patterns.

3

4

## Capabilities

5

6

### MemberRouter Class

7

8

Router implementation for member-based file organization strategy where each member gets its own file.

9

10

```typescript { .api }

11

/**

12

* Router implementation for member-based file organization strategy.

13

* Organizes documentation by giving individual members their own files.

14

*/

15

class MemberRouter extends MarkdownRouter {

16

/**

17

* Builds child pages for reflections in member-based organization

18

* @param reflection - The parent reflection

19

* @param outPages - Array to collect generated page definitions

20

*/

21

buildChildPages(reflection: Reflection, outPages: PageDefinition[]): void;

22

23

/**

24

* Gets the ideal base name for a reflection in member-based routing

25

* @param reflection - The reflection to get base name for

26

* @returns Ideal base filename without extension

27

*/

28

getIdealBaseName(reflection: Reflection): string;

29

}

30

```

31

32

### ModuleRouter Class

33

34

Router implementation for module-based file organization strategy where modules determine file structure.

35

36

```typescript { .api }

37

/**

38

* Router implementation for module-based file organization strategy.

39

* Organizes documentation by module boundaries and hierarchies.

40

*/

41

class ModuleRouter extends MarkdownRouter {

42

/**

43

* Builds child pages for reflections in module-based organization

44

* @param reflection - The parent reflection

45

* @param outPages - Array to collect generated page definitions

46

*/

47

buildChildPages(reflection: Reflection, outPages: PageDefinition[]): void;

48

49

/**

50

* Gets the ideal base name for a reflection in module-based routing

51

* @param reflection - The reflection to get base name for

52

* @returns Ideal base filename without extension

53

*/

54

getIdealBaseName(reflection: Reflection): string;

55

}

56

```

57

58

### MarkdownRouter Abstract Base Class

59

60

Abstract base class for all markdown routers providing common functionality and configuration.

61

62

```typescript { .api }

63

/**

64

* Abstract base class for markdown routers with common functionality

65

* and configuration options for file organization strategies.

66

*/

67

abstract class MarkdownRouter extends BaseRouter {

68

/** File extension for generated files */

69

extension: string;

70

71

/** Output file strategy setting */

72

outputFileStrategy: string;

73

74

/** Entry module setting */

75

entryModule: string;

76

77

/** Whether to ignore scopes in paths */

78

ignoreScopes: boolean;

79

80

/** Modules file name */

81

modulesFileName: string;

82

83

/** Entry file name */

84

entryFileName: string;

85

86

/** Whether using packages strategy */

87

isPackages: boolean;

88

89

/** Members that get their own files */

90

membersWithOwnFile: string[];

91

92

/** Whether to merge readme with entry */

93

mergeReadme: boolean;

94

95

/** Prefix for anchors */

96

anchorPrefix: string;

97

98

/** Directory mappings for reflection kinds */

99

directories: Map<ReflectionKind, string>;

100

101

/** String mappings for reflection kinds */

102

kindsToString: Map<ReflectionKind, string>;

103

104

/**

105

* Builds all pages for a project

106

* @param project - The TypeDoc project reflection

107

* @returns Array of page definitions to generate

108

*/

109

buildPages(project: ProjectReflection): PageDefinition[];

110

111

/**

112

* Gets anchor for a router target

113

* @param target - The router target to get anchor for

114

* @returns Anchor string for linking

115

*/

116

getAnchor(target: RouterTarget): string;

117

118

/**

119

* Gets flattened base name for a reflection

120

* @param reflection - The reflection to get name for

121

* @returns Flattened base name

122

*/

123

getIdealBaseNameFlattened(reflection: Reflection): string;

124

125

/**

126

* Gets reflection alias for display purposes

127

* @param reflection - The reflection to get alias for

128

* @returns Display alias string

129

*/

130

getReflectionAlias(reflection: Reflection): string;

131

132

/**

133

* Gets modules file name for a reflection

134

* @param reflection - The reflection to get modules filename for

135

* @returns Modules filename

136

*/

137

getModulesFileName(reflection: Reflection): string;

138

}

139

```

140

141

### Core Router Classes

142

143

Core TypeDoc routers decorated to handle plugin file options and integrate with markdown generation.

144

145

```typescript { .api }

146

/**

147

* Kind-based router that organizes files by reflection kind (class, interface, etc.)

148

*/

149

class KindRouter extends CoreKindRouter {

150

// Inherits kind-based routing behavior with markdown enhancements

151

}

152

153

/**

154

* Kind-based directory router that creates subdirectories by reflection kind

155

*/

156

class KindDirRouter extends KindRouter {

157

// Extends kind routing with directory organization

158

}

159

160

/**

161

* Structure-based router that follows the source code structure

162

*/

163

class StructureRouter extends CoreStructureRouter {

164

// Inherits structure-based routing with markdown enhancements

165

}

166

167

/**

168

* Structure-based directory router with subdirectory organization

169

*/

170

class StructureDirRouter extends StructureRouter {

171

// Extends structure routing with directory organization

172

}

173

174

/**

175

* Group-based router that organizes by TypeDoc groups

176

*/

177

class GroupRouter extends CoreGroupRouter {

178

// Inherits group-based routing with markdown enhancements

179

}

180

181

/**

182

* Category-based router that organizes by TypeDoc categories

183

*/

184

class CategoryRouter extends CoreCategoryRouter {

185

// Inherits category-based routing with markdown enhancements

186

}

187

```

188

189

**Usage Examples:**

190

191

```typescript

192

import { MemberRouter, ModuleRouter } from "typedoc-plugin-markdown";

193

import { Application } from "typedoc";

194

195

// Configure member-based routing

196

const app = new Application();

197

app.options.setValue('outputFileStrategy', 'members');

198

199

// This will use MemberRouter internally

200

// Each class method, property, etc. gets its own file

201

// Example structure:

202

// - docs/classes/MyClass.md

203

// - docs/classes/MyClass/method1.md

204

// - docs/classes/MyClass/property1.md

205

206

// Configure module-based routing

207

app.options.setValue('outputFileStrategy', 'modules');

208

209

// This will use ModuleRouter internally

210

// Files organized by module boundaries

211

// Example structure:

212

// - docs/modules/core.md

213

// - docs/modules/utils.md

214

// - docs/modules/types.md

215

```

216

217

**Router Configuration Options:**

218

219

```typescript

220

// File extension configuration

221

app.options.setValue('fileExtension', '.md');

222

223

// Entry and modules filenames

224

app.options.setValue('entryFileName', 'README');

225

app.options.setValue('modulesFileName', 'modules');

226

227

// Directory organization

228

app.options.setValue('flattenOutputFiles', false); // Creates subdirectories

229

230

// Members with own files (for member router)

231

app.options.setValue('membersWithOwnFile', [

232

'Class',

233

'Interface',

234

'Enum',

235

'Function'

236

]);

237

238

// Scope handling

239

app.options.setValue('ignoreScopes', true); // Ignores @internal, @alpha tags in paths

240

241

// Anchor prefix for cross-references

242

app.options.setValue('anchorPrefix', 'md:');

243

```

244

245

**Custom Router Development:**

246

247

```typescript

248

import { MarkdownRouter } from "typedoc-plugin-markdown";

249

250

class CustomRouter extends MarkdownRouter {

251

buildChildPages(reflection: Reflection, outPages: PageDefinition[]): void {

252

// Custom logic for organizing child pages

253

if (reflection.kind === ReflectionKind.Class) {

254

// Group methods and properties differently

255

const methods = reflection.getChildrenByKind(ReflectionKind.Method);

256

const properties = reflection.getChildrenByKind(ReflectionKind.Property);

257

258

// Create separate pages for methods and properties

259

if (methods.length > 0) {

260

outPages.push({

261

model: reflection,

262

filename: `${this.getIdealBaseName(reflection)}/methods.md`,

263

url: `${this.getIdealBaseName(reflection)}/methods.html`

264

});

265

}

266

267

if (properties.length > 0) {

268

outPages.push({

269

model: reflection,

270

filename: `${this.getIdealBaseName(reflection)}/properties.md`,

271

url: `${this.getIdealBaseName(reflection)}/properties.html`

272

});

273

}

274

}

275

276

super.buildChildPages(reflection, outPages);

277

}

278

279

getIdealBaseName(reflection: Reflection): string {

280

// Custom naming logic

281

const baseName = super.getIdealBaseName(reflection);

282

283

// Add prefixes based on reflection kind

284

switch (reflection.kind) {

285

case ReflectionKind.Class:

286

return `class-${baseName}`;

287

case ReflectionKind.Interface:

288

return `interface-${baseName}`;

289

case ReflectionKind.Function:

290

return `function-${baseName}`;

291

default:

292

return baseName;

293

}

294

}

295

}

296

```

297

298

**Router Selection Logic:**

299

300

The plugin automatically selects the appropriate router based on configuration:

301

302

```typescript

303

// Router selection based on outputFileStrategy option

304

switch (options.getValue('outputFileStrategy')) {

305

case 'members':

306

return new MemberRouter(options);

307

case 'modules':

308

return new ModuleRouter(options);

309

case 'kinds':

310

return new KindRouter(options);

311

case 'structure':

312

return new StructureRouter(options);

313

default:

314

return new ModuleRouter(options); // Default fallback

315

}

316

```