npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

gatsby-remark-extract-image-attributes

v1.0.7

Published

Gatsby Transformer Remark plugin that extracts data attributes from images in Markdown (.md) files and adds them to the AST stream for later processing.

Readme

gatsby-remark-extract-image-attributes

Coverage Circle CI License

Extract data attributes from the images in your Markdown (.md) files and add them to the remark AST for later processing.

Align And Size Markdown Images

This plugin can be used by itself, or in conjunction with the gatsby-remark-images-insert-wrapper-attributes plugin to extract image attributes and then apply them to the wrapper generated by gatsby-remark-images after image processing.

Using the two plugins together makes it simple to align and size images in your Markdown files while still taking advantage of Gatsby's excellent image optimization plugin, gatsby-remark-images.

Use With Gatsby Remark Copy Linked Files Plugin

The "stripMdAttributes" option can be used to remove url params prior to being processed by the gatsby-remark-copy-linked-files plugin. This setup can be very useful when using a git-backed CMS such as Forestry.io or NetlifyCMS where images must be stored in and referenced from the "static" directory.

To use this plugin with gatsby-remark-copy-linked-files (and Gatsby Remark Images), place it thusly in the gatsby-config.js plugins array:

{
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          {
            resolve: `gatsby-remark-extract-image-attributes`,
            options: {
              stripMdAttributes: true,
            }
          },
          `gatsby-remark-copy-linked-files`,
          `gatsby-remark-images`,
        ]
      }
}

Getting Started

Compatibility

This plugin has been tested, and is compatible, with the following (related) dependencies:

  • gatsby: ^3.3.1
  • gatsby-transformer-remark: ^3.0.0
  • gatsby-transformer-sharp: ^3.0.0
  • gatsby-remark-images: ^4.0.0

Prerequisites

Installation

npm install gatsby-remark-extract-image-attributes

Solo Usage

This plugin can be used by itself to extract image attributes. In your gatsby-config.js file, simply add it to the plugins array of the 'gatsby-transformer-remark' plugin.

// gatsby-config.js
plugins: [
    {
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          `gatsby-remark-extract-image-attributes`,
        ]
      }
    }
]

With gatsby-remark-images-insert-wrapper-attributes

In this configuration, the gatsby-remark-images plugin should be sandwiched in the middle, like so:

{
      resolve: `gatsby-transformer-remark`,
      options: {
        plugins: [
          `gatsby-remark-extract-image-attributes`,
          `gatsby-remark-images`,
          `gatsby-remark-images-insert-wrapper-attributes`
        ]
      }
}

Options

properties

By default, the plugin extracts the "align", "width", and "height" attributes. Any number of additional custom data attributes can be captured by specifying the attribute name(s) in the "properties" array:

{
  resolve: `gatsby-transformer-remark`,
  options: {
    plugins: [
      {
        resolve: `gatsby-remark-extract-image-attributes`,
        options: {
          properties: ["caption", "filesize", "format"]
        }
      },
    ]
  }
}

stripMdAttributes (boolean)

When using Markdown syntax, setting this value to "true" will remove url params from the image source. For example, image.jpg?align=left&width=300 will become image.jpg.

{
  resolve: `gatsby-transformer-remark`,
  options: {
    plugins: [
      {
        resolve: `gatsby-remark-extract-image-attributes`,
        options: {
          stripMdAttributes: true,
        }
      },
    ]
  }
}

Image Attribute Examples

The plugin accepts both Markdown and HTML syntax.

Markdown

Attributes using Markdown syntax are accomplished by appending the desired data to the image source as URL params. This example shows align, height, width, and caption params. Make sure to URL-encode any data parameters that include spaces or characters outside the ASCII set :

![Alt text here](my-image.jpg?align=left&height=300&width=250&caption=My%20awesome%20picture%20caption "Title text here")

HTML

With HTML syntax, the plugin first looks for data-* attributes:

<img src="my-image.jpg" alt="Alt text here" title="Title text here" data-align="left" data-height="1280" data-width="720" data-caption="My awesome picture caption">

If no data-* attribute is found, it will look for the attribute name alone:

<img src="my-image.jpg" alt="Alt text here" title="Title text here" align="left" height="1280" width="720" data-caption="My awesome picture">

Testing

To run Jest tests:

npm test