Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-mdx-images

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-mdx-images

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

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
608
decreased by-47.95%
Maintainers
1
Weekly downloads
 
Created
Source

remark-mdx-images

github actions codecov npm version npm downloads

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

Table of Contents

Installation

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:

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

The following script:

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:

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 © Remco Haszing

Keywords

FAQs

Package last updated on 24 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc