# remark-images-download

> This plugin downloads images to a custom directory, replacing images URLs with the path to the downloaded file.

Latest version **3.0.5** (published 2024-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install remark-images-download
pnpm add remark-images-download
yarn add remark-images-download
bun add remark-images-download
```

## Health

**Score 15/100 (F)** — status: abandoned.

Warnings: low downloads; no types; no esm support; has vulnerabilities.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.5 |
| Published | 2024-04-27 |
| First published | 2017-08-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 30.8 KB |
| Known vulnerabilities | 1 (+8 in 3 direct dependencies) |
| Install scripts | no |
| GitHub stars | 237 |
| Author | Victor Felder |
| Maintainers | situphen, talone |
| Keywords | remark |

## Links

- npm: https://www.npmjs.com/package/remark-images-download
- Repository: https://github.com/zestedesavoir/zmarkdown.git#master
- Homepage: https://github.com/zestedesavoir/zmarkdown/tree/master#readme
- Issues: https://github.com/zestedesavoir/zmarkdown/issues
- npm.io page: https://npm.io/package/remark-images-download

## Dependencies (8)

- [clone](https://npm.io/package/clone.md) ^2.1.2
- [is-svg](https://npm.io/package/is-svg.md) ~4.2.1
- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2
- [shortid](https://npm.io/package/shortid.md) ^2.2.15
- [file-type](https://npm.io/package/file-type.md) ^14.6.2
- [ip-address](https://npm.io/package/ip-address.md) ^8.1.0
- [read-chunk](https://npm.io/package/read-chunk.md) ^3.2.0
- [unist-util-visit](https://npm.io/package/unist-util-visit.md) ^2.0.3

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 3.0.5 (latest) — 2024-04-27
- 3.0.4 — 2024-04-02
- 3.0.3 — 2024-01-14
- 3.0.2 — 2022-03-29
- 3.1.0 — 2021-08-30
- 3.0.1 — 2021-02-14
- 3.0.0 — 2020-02-03
- 2.9.3 — 2020-01-21
- 2.9.0 — 2019-08-29
- 2.8.8 — 2019-07-27
- 2.8.7 — 2019-05-25
- 2.8.6 — 2019-04-14
- 2.8.5 — 2019-02-04
- 2.8.4 — 2018-11-23
- 2.8.3 — 2018-10-04
- … 27 more at https://npm.io/package/remark-images-download/versions

## README

# remark-images-download [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status]

This plugin downloads images to a custom directory, replacing images URLs
with the path to the downloaded file.

## Installation

[npm][npm]:

```bash
npm install remark-images-download
```

## Usage

Dependencies:

```javascript
const unified = require('unified')
const remarkParse = require('remark-parse')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')

const remarkImagesDownload = require('remark-images-download')
```

Usage:

```javascript
unified()
  .use(remarkParse)
  .use(remarkIframe,
  .use(remarkImagesDownload, {
    disabled: true,
    downloadDestination: './img/',
    defaultImagePath: 'black.png',
    defaultOn: {
      statusCode: true,
      mimeType: false,
      fileTooBig: false,
    },
    maxlength: 1000000,
    dirSizeLimit: 10000000,
    localUrlToLocalPath: (localUrl) => localPath
  })
  .use(remark2rehype)
  .use(stringify)
```

## Configuration options:

All options are optional.

- `disabled`: bool, default: `false`

  If `true`, disables the plugin.

- `downloadDestination`: string, default: `/tmp`

  Parent destination folder for downloads.

- `defaultImagePath`: string or boolean, default: `false`

  Image path to fallback to for images that couldn't be found.
  Set to `false` or keep default value to disable.

- `defaultOn`: object, with properties,

  Cases when the default image should be used.

  - `statusCode`: boolean, default `false`

    The status code is different than 200.

  - `mimeType`: boolean, default `false`

    The MIME type does not match an image.

  - `fileTooBig`: boolean, default `false`

    The file size exceed the `maxFileSize` limit.

- `maxFileLength`: number, default: `1000000`

  Any file with a bigger size than this number (in bytes) will be skipped.

- `dirSizeLimit`: number, default: `10000000`

  Download directory size limit (in bytes). When reached, subsequent
  images are skipped.

- `localUrlToLocalPath`: `(localUrl: string): string => localPath` or `[from: string, to: string]`, default: `<none>` (skip local images)

  If provided, local images referenced in Markdown source (such
  as `![](/img/example.png)`) will be copied to `downloadDestination`
  after applying this function to the path to obtain the local location
  of `example.png`, e.g.
  `localUrlToLocalPath('/img/example.png') === '/opt/assets/example.png'`.
  It will get renamed to a shortId just like any downloaded image.

  In case a two-element array is provided, the string `from` will get
  replaced by `to` using the following RegExp:

  ```js
  '/img/example.png'.replace(new RegExp(`^${from}`), to)
  ```

  If not provided, local images will not end up in `downloadDestination`.

## Example

```markdown
Two small images:
![](https://example.com/example.png)
![](https://example.com/example2.png)

And an image of 1Tb!
![](https://example.com/example_1Tb.png)
```

with the previous configuration `remark-images-download` will download the two first images in `img/UUID/otherUUID.png` and `img/UUID/yetAnotherUUID.png` where `UUID` is a random string and it does not download `example_1Tb.png` because the file is too large.

`vfile.data.imageDir` will be set to the path to the folder where images were downloaded.


## License

[MIT][license] © [Zeste de Savoir][zds]

<!-- Definitions -->

[build-badge]: https://img.shields.io/travis/zestedesavoir/zmarkdown.svg

[build-status]: https://travis-ci.org/zestedesavoir/zmarkdown

[coverage-badge]: https://img.shields.io/coveralls/zestedesavoir/zmarkdown.svg

[coverage-status]: https://coveralls.io/github/zestedesavoir/zmarkdown

[license]: https://github.com/zestedesavoir/zmarkdown/blob/master/packages/remark-images-download/LICENSE-MIT

[zds]: https://zestedesavoir.com

[npm]: https://www.npmjs.com/package/remark-images-download

---
_Source: https://npm.io/package/remark-images-download · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
