# remark-mdx-images

> A remark plugin for changing image sources to JavaScript imports using MDX

Latest version **3.0.0** (published 2023-11-24) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-11-24 |
| First published | 2021-03-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 3 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 25 |
| Author | Remco Haszing |
| Maintainers | remcohaszing |
| Keywords | markdown, mdast, mdx, remark, remark-plugin, unified |

## Links

- npm: https://www.npmjs.com/package/remark-mdx-images
- Repository: https://github.com/remcohaszing/remark-mdx-images
- Homepage: https://github.com/remcohaszing/remark-mdx-images#readme
- Issues: https://github.com/remcohaszing/remark-mdx-images/issues
- Funding: https://github.com/sponsors/remcohaszing
- npm.io page: https://npm.io/package/remark-mdx-images

## Dependencies (3)

- [unified](https://npm.io/package/unified.md) ^11.0.0
- [@types/mdast](https://npm.io/package/@types/mdast.md) ^4.0.0
- [unist-util-visit](https://npm.io/package/unist-util-visit.md) ^5.0.0

## 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.0 (latest) — 2023-11-24
- 2.0.0 — 2022-07-23
- 1.0.3 — 2021-07-11
- 1.0.2 — 2021-03-15
- 1.0.1 — 2021-03-07
- 1.0.0 — 2021-03-07

## README

# remark-mdx-images

[![github actions](https://github.com/remcohaszing/remark-mdx-images/actions/workflows/ci.yaml/badge.svg)](https://github.com/remcohaszing/remark-mdx-images/actions/workflows/ci.yaml)
[![codecov](https://codecov.io/gh/remcohaszing/remark-mdx-images/branch/main/graph/badge.svg)](https://codecov.io/gh/remcohaszing/remark-mdx-images)
[![npm version](https://img.shields.io/npm/v/remark-mdx-images)](https://www.npmjs.com/package/remark-mdx-images)
[![npm downloads](https://img.shields.io/npm/dm/remark-mdx-images)](https://www.npmjs.com/package/remark-mdx-images)

A [remark](https://remark.js.org) plugin for changing image sources to JavaScript imports using MDX

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
  - [Options](#options)
    - [`resolve`](#resolve)
- [Compatibility](#compatibility)
- [License](#license)

## Installation

```sh
npm install remark-mdx-images
```

## Usage

This remark plugin takes markdown images, and converts them into mdx elements `<img />` that use
JavaScript imports to resolve the image source.

For example, given a file named `example.mdx` with the following contents:

```mdx
![Very cute kittens](./kittens.png 'Meow!')
```

The following script:

```js
import { readFile } from 'node:fs/promises'

import { compile } from '@mdx-js/mdx'
import remarkMdxImages from 'remark-mdx-images'

const { contents } = await compile(await readFile('example.mdx'), {
  jsx: true,
  remarkPlugins: [remarkMdxImages]
})
console.log(contents)
```

Roughly yields:

```jsx
import kittens from './kittens.png'

export default function MDXContent() {
  return (
    <p>
      <img alt="Very cute kittens" src={kittens} title="Meow!" />
    </p>
  )
}
```

## API

### Options

#### `resolve`

By default imports are resolved relative to the markdown file. This matches default markdown
behaviour. If this is set to false, this behaviour is removed and URLs are no longer processed. This
allows to import images from `node_modules`. If this is disabled, local images can still be imported
by prepending the path with `./`.

## Compatibility

This project is compatible with Node.js 18 or greater.

## License

[MIT](LICENSE.md) © [Remco Haszing](https://github.com/remcohaszing)

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