A plugin for TypeDoc that enables TypeScript API documentation to be generated in Markdown.
—
Multiple router implementations providing different strategies for organizing generated documentation files, from member-based to module-based file organization patterns.
Router implementation for member-based file organization strategy where each member gets its own file.
/**
* Router implementation for member-based file organization strategy.
* Organizes documentation by giving individual members their own files.
*/
class MemberRouter extends MarkdownRouter {
/**
* Builds child pages for reflections in member-based organization
* @param reflection - The parent reflection
* @param outPages - Array to collect generated page definitions
*/
buildChildPages(reflection: Reflection, outPages: PageDefinition[]): void;
/**
* Gets the ideal base name for a reflection in member-based routing
* @param reflection - The reflection to get base name for
* @returns Ideal base filename without extension
*/
getIdealBaseName(reflection: Reflection): string;
}Router implementation for module-based file organization strategy where modules determine file structure.
/**
* Router implementation for module-based file organization strategy.
* Organizes documentation by module boundaries and hierarchies.
*/
class ModuleRouter extends MarkdownRouter {
/**
* Builds child pages for reflections in module-based organization
* @param reflection - The parent reflection
* @param outPages - Array to collect generated page definitions
*/
buildChildPages(reflection: Reflection, outPages: PageDefinition[]): void;
/**
* Gets the ideal base name for a reflection in module-based routing
* @param reflection - The reflection to get base name for
* @returns Ideal base filename without extension
*/
getIdealBaseName(reflection: Reflection): string;
}Abstract base class for all markdown routers providing common functionality and configuration.
/**
* Abstract base class for markdown routers with common functionality
* and configuration options for file organization strategies.
*/
abstract class MarkdownRouter extends BaseRouter {
/** File extension for generated files */
extension: string;
/** Output file strategy setting */
outputFileStrategy: string;
/** Entry module setting */
entryModule: string;
/** Whether to ignore scopes in paths */
ignoreScopes: boolean;
/** Modules file name */
modulesFileName: string;
/** Entry file name */
entryFileName: string;
/** Whether using packages strategy */
isPackages: boolean;
/** Members that get their own files */
membersWithOwnFile: string[];
/** Whether to merge readme with entry */
mergeReadme: boolean;
/** Prefix for anchors */
anchorPrefix: string;
/** Directory mappings for reflection kinds */
directories: Map<ReflectionKind, string>;
/** String mappings for reflection kinds */
kindsToString: Map<ReflectionKind, string>;
/**
* Builds all pages for a project
* @param project - The TypeDoc project reflection
* @returns Array of page definitions to generate
*/
buildPages(project: ProjectReflection): PageDefinition[];
/**
* Gets anchor for a router target
* @param target - The router target to get anchor for
* @returns Anchor string for linking
*/
getAnchor(target: RouterTarget): string;
/**
* Gets flattened base name for a reflection
* @param reflection - The reflection to get name for
* @returns Flattened base name
*/
getIdealBaseNameFlattened(reflection: Reflection): string;
/**
* Gets reflection alias for display purposes
* @param reflection - The reflection to get alias for
* @returns Display alias string
*/
getReflectionAlias(reflection: Reflection): string;
/**
* Gets modules file name for a reflection
* @param reflection - The reflection to get modules filename for
* @returns Modules filename
*/
getModulesFileName(reflection: Reflection): string;
}Core TypeDoc routers decorated to handle plugin file options and integrate with markdown generation.
/**
* Kind-based router that organizes files by reflection kind (class, interface, etc.)
*/
class KindRouter extends CoreKindRouter {
// Inherits kind-based routing behavior with markdown enhancements
}
/**
* Kind-based directory router that creates subdirectories by reflection kind
*/
class KindDirRouter extends KindRouter {
// Extends kind routing with directory organization
}
/**
* Structure-based router that follows the source code structure
*/
class StructureRouter extends CoreStructureRouter {
// Inherits structure-based routing with markdown enhancements
}
/**
* Structure-based directory router with subdirectory organization
*/
class StructureDirRouter extends StructureRouter {
// Extends structure routing with directory organization
}
/**
* Group-based router that organizes by TypeDoc groups
*/
class GroupRouter extends CoreGroupRouter {
// Inherits group-based routing with markdown enhancements
}
/**
* Category-based router that organizes by TypeDoc categories
*/
class CategoryRouter extends CoreCategoryRouter {
// Inherits category-based routing with markdown enhancements
}Usage Examples:
import { MemberRouter, ModuleRouter } from "typedoc-plugin-markdown";
import { Application } from "typedoc";
// Configure member-based routing
const app = new Application();
app.options.setValue('outputFileStrategy', 'members');
// This will use MemberRouter internally
// Each class method, property, etc. gets its own file
// Example structure:
// - docs/classes/MyClass.md
// - docs/classes/MyClass/method1.md
// - docs/classes/MyClass/property1.md
// Configure module-based routing
app.options.setValue('outputFileStrategy', 'modules');
// This will use ModuleRouter internally
// Files organized by module boundaries
// Example structure:
// - docs/modules/core.md
// - docs/modules/utils.md
// - docs/modules/types.mdRouter Configuration Options:
// File extension configuration
app.options.setValue('fileExtension', '.md');
// Entry and modules filenames
app.options.setValue('entryFileName', 'README');
app.options.setValue('modulesFileName', 'modules');
// Directory organization
app.options.setValue('flattenOutputFiles', false); // Creates subdirectories
// Members with own files (for member router)
app.options.setValue('membersWithOwnFile', [
'Class',
'Interface',
'Enum',
'Function'
]);
// Scope handling
app.options.setValue('ignoreScopes', true); // Ignores @internal, @alpha tags in paths
// Anchor prefix for cross-references
app.options.setValue('anchorPrefix', 'md:');Custom Router Development:
import { MarkdownRouter } from "typedoc-plugin-markdown";
class CustomRouter extends MarkdownRouter {
buildChildPages(reflection: Reflection, outPages: PageDefinition[]): void {
// Custom logic for organizing child pages
if (reflection.kind === ReflectionKind.Class) {
// Group methods and properties differently
const methods = reflection.getChildrenByKind(ReflectionKind.Method);
const properties = reflection.getChildrenByKind(ReflectionKind.Property);
// Create separate pages for methods and properties
if (methods.length > 0) {
outPages.push({
model: reflection,
filename: `${this.getIdealBaseName(reflection)}/methods.md`,
url: `${this.getIdealBaseName(reflection)}/methods.html`
});
}
if (properties.length > 0) {
outPages.push({
model: reflection,
filename: `${this.getIdealBaseName(reflection)}/properties.md`,
url: `${this.getIdealBaseName(reflection)}/properties.html`
});
}
}
super.buildChildPages(reflection, outPages);
}
getIdealBaseName(reflection: Reflection): string {
// Custom naming logic
const baseName = super.getIdealBaseName(reflection);
// Add prefixes based on reflection kind
switch (reflection.kind) {
case ReflectionKind.Class:
return `class-${baseName}`;
case ReflectionKind.Interface:
return `interface-${baseName}`;
case ReflectionKind.Function:
return `function-${baseName}`;
default:
return baseName;
}
}
}Router Selection Logic:
The plugin automatically selects the appropriate router based on configuration:
// Router selection based on outputFileStrategy option
switch (options.getValue('outputFileStrategy')) {
case 'members':
return new MemberRouter(options);
case 'modules':
return new ModuleRouter(options);
case 'kinds':
return new KindRouter(options);
case 'structure':
return new StructureRouter(options);
default:
return new ModuleRouter(options); // Default fallback
}Install with Tessl CLI
npx tessl i tessl/npm-typedoc-plugin-markdown