droppedcode / typedoc-plugin-copy-assets

Typedoc plugin that copies the assets found in comments to the output assets folder.
MIT License
3 stars 1 forks source link

Copy assets plugin for typedoc

This plugin for typedoc copies the assets found in comments to the output assets folder.

This way if you define any assets in the jsdoc comment it will be copied into the output folder and the path modified to be used from there.

The path must be relative (starting with ./ or ../) to the current file processed to be copied to the output.

Same named files (from different paths) will be suffixed with an index.

Configuration

To configure what assets are copied you can configure it in the typedoc options file. By default only images (e.g. ![label](./path/image.png)) are copied to allow non image links (e.g. [label](./path/image.md)), set the only images to false.

To define more granular control over what is copied add regexes to the include/includePath lists and/or exclude/excludePath lists.

You can enable the copy from html image tags (e.g. <img src="https://github.com/droppedcode/typedoc-plugin-copy-assets/raw/main/path/to/image.png" alt="Image" />) with the copyHtmlImgTag option. It handles all paths as relative (e.g. path/img.png is same as ./path/img.png).

E.g. configuration that allows png images and md files, but not from the exclude folder:

{
  "copyAssets": {
    "onlyImages": false,
    "include": [],
    "exclude": [],
    "includePath": [".(png|md)$"],
    "excludePath": [".*?exclude/.*?$"],
    "copyHtmlImgTag": false
  }
}

Options

How include / exclude works

There are 2 pairs, the include/exclude will match against the whole link (e.g. [foo](bar.baz)), the includePath/excludePath will be matched against the path part only (e.g. bar.baz). The workflow:

The output path

The output will be determined from the settings of typedoc using the out option (see typedoc options) joined with assets/media.

Typedoc

Supports 0.25 (tested with 0.25.2)

For 0.23 see version 1.0.9

For 0.22 see version 1.0.4

How to build

How to debug

Changes

1.0.11