typedoc-plugin-linkrewriter
v0.1.1
Published
A TypeDoc plugin for rewriting links in markdown
Downloads
34
Readme
typedoc-plugin-linkrewriter
A plugin for TypeDoc for rewriting links in markdown.
Installation
npm install --save-dev typedoc typedoc-plugin-linkrewriter
Usage
typedoc --rewriteLinks path/to/linkrewriter.json
The LinkRewriter
plugin recognizes the following link formats supported by Github Flavored Markdown:
- Inline Links (e.g.
[Foo](bar)
) - Link Reference Definitions (e.g.
[Foo]: bar
) - Images (e.g.

) - Auto Links (e.g.
<http://foo.bar>
) - Auto Links (extension) (e.g.
www.foo.bar
andhttp://foo.bar
)
Arguments
This plugin adds the following additional arguments to TypeDoc:
--rewriteLinks
The path to a JSON file or JS file exporting a Links
object.
A Links
object is an object where each key is parsed as a regular expression pattern and
each value is either a replacement string or a replacer function:
interface Links {
[pattern: string]: string | LinkRewriter;
}
type LinkRewriter = (this: LinkRewriterContext, matched: string, ...args: any[]) => string;
interface LinkRewriterContext {
project?: ProjectReflection;
reflection?: DeclarationReflection;
url?: string;
file?: string;
}
Example (JSON)
{
"^packages/([^/]+)(?:#readme|/README.md)": "modules/$1.html"
}
Example (JS)
module.exports = {
// maps 'packages/foo-bar#readme' to 'modules/foo_bar.html'
[String.raw`^packages/([^/]+)(?:#readme|/README.md)`](_, name) {
return `modules/${name.replace(/-/g, "_")}.html`;
},
// maps '../foo-bar#readme' to './foo_bar.html'
[String.raw`^\.\./([^/]+)(?:#readme|/README.md)`](_, name) {
return `./${name.replace(/-/g, "_")}.html`;
},
}