rehype-typedoc
Rehype plugin to auto-link inline code to TypeDoc API documentation
npm install rehype-typedocrehype-typedoc
TypeDoc-aware markdown and HTML linking plugins for Unified pipelines.
Installation
npm install rehype-typedoc
For directive support (:typedoc[...] and ::typedoc{...}), also install remark-directive.
What It Does
- Links inline
<code>symbols to API docs. - Links identifiers inside syntax-highlighted TypeScript/JavaScript code blocks.
- Adds directive helpers so docs authors can disambiguate symbol lookups and optionally inject signatures.
Exports
rehypeTypedoc(default): links inline code nodes.rehypeTypedocCodeBlocks: links identifiers in<pre><code>blocks.remarkCodeProps: converts:typedoc[...]and::typedoc{...}directives to linkable code nodes.
Quick Start
import rehypeShiki from '@shikijs/rehype';
import rehypeStringify from 'rehype-stringify';
import remarkDirective from 'remark-directive';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import { unified } from 'unified';
import rehypeTypedoc, {
rehypeTypedocCodeBlocks,
remarkCodeProps,
type RehypeTypedocOptions,
} from 'rehype-typedoc';
const options: RehypeTypedocOptions = {
symbols: new Map([
[
'createMatcher',
{
name: 'createMatcher',
package: 'devkit',
path: '/api/devkit/create-matcher',
},
],
]),
buildLink: (symbol) => symbol.path,
};
const file = await unified()
.use(remarkParse)
.use(remarkDirective)
.use(remarkCodeProps)
.use(remarkRehype)
.use(rehypeTypedoc, options)
.use(rehypeShiki, { theme: 'github-dark', addLanguageClass: true })
.use(rehypeTypedocCodeBlocks, options)
.use(rehypeStringify)
.process('Use `createMatcher` in your plugin.');
const html = String(file);
Symbol Resolution and Disambiguation
When the same symbol name exists in multiple packages, resolution order is:
- Use
data-pkgwhen present. - Filter out re-exports and use the defining symbol when only one remains.
- Throw an error if multiple defining symbols still remain.
Use :typedoc directive attributes to set data-pkg from markdown:
Use :typedoc[Config]{pkg=core} for core configuration.
Directive Syntax
Text directive:
:typedoc[createMatcher]{pkg=devkit}
Leaf directive (requires resolveSignature):
::typedoc{symbol="Plugin" pkg="devkit"}
Provide a resolver when using leaf directives:
unified().use(remarkCodeProps, {
resolveSignature: (symbolName, pkg) => {
// return a TypeScript signature string for this symbol
return undefined;
},
});
Styling
Generated links use class="typedoc-link", so you can style API links independently from normal prose links.
License
MIT
API EXPORTS
Interfaces
Variables
defaultvariablerehypeTypedocvariableRehype plugin that wraps inline `<code>` elements in `<a>` tags when their text content matches a known TypeDoc symbol. Supports `data-pkg` attribute on code elements for disambiguation when a symbol name exists in multiple packages.
rehypeTypedocCodeBlocksvariableRehype plugin that wraps identifier tokens inside syntax-highlighted `<pre><code>` blocks with `<a>` links to their API documentation. Must run **after** a syntax highlighter (e.g. `@shikijs/rehype`) so that code blocks contain `<span>` tokens to process. Identifiers inside comments and string literals are never linked.
remarkCodePropsvariableRemark plugin that transforms `:typedoc` directives into code nodes with `data-*` attributes. Requires `remark-directive` to run before it. **Text directive** — inline code with attributes: `:typedoc[createMatcher]{pkg=devkit}` → `<code data-pkg="devkit">createMatcher</code>` **Leaf directive** — fenced code block with resolved signature: `::typedoc{symbol="Plugin" pkg="functional-examples"}` → code block with resolved type signature Attributes are converted to `data-*` hast properties using camelCase convention (e.g. `pkg` → `dataPkg`).