typedoc-plugin-linkrewriter
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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:

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`;
    },
}

Package Sidebar

Install

npm i typedoc-plugin-linkrewriter

Weekly Downloads

2

Version

0.1.1

License

Apache-2.0

Unpacked Size

59.7 kB

Total Files

17

Last publish

Collaborators

  • rbuckton