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 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-remark-image-attributes

v1.1.0

Published

Creates HTML image markup with style and data-* attributes from [`mdAST Image`](https://github.com/syntax-tree/mdast#image) nodes with attributes in their title.

Downloads

2,056

Readme

gatsby-remark-image-attributes

Creates HTML image markup with style and data-* attributes from mdAST Image nodes with attributes in their title.

Gatsby 2/3/4 compatible npm dependencies minified minified+gzip

                                                 ┌─────────── styleAttributes ───────────┐          reserved for image title
                                                 │ ▼           ▼           ▼             │                ▼
![satisfied](https://foomoji.com/satisfied.png '#width=32px;height=32px;position=absolute;lightbox=true;title=Image Title')
                                                ▲                                             ▲
                                            Leading #                                   dataAttribute

yields

<img
  src="https://foomoji.com/satisfied.png"
  alt="satisfied"
  title="Image Title"
  style="width: 32px; height:32px; position: absolute;"
  data-lightbox="true"
  class="gatsby-img-attributes"
/>

Note that title is a reserved attribute key, i.e. declaring data-title is not possible. title image attributes will always become the HTML attribute title of the <img>.

The plugin handles mdAST HTML nodes created by gatsby-remark-images; possibly other image-processing plugins. Order of plugins in your gatsby-config matters.


Some examples

Netlify Status demo source

Installation

npm install --save gatsby-remark-image-attributes

How to use

.gatsby-img-attributes

Generated markup has a CSS class gatsby-img-attributes. The plugin itself does not come with any properties for that class; you can use it to apply default styling to all images with attributes.

Options

|Name|Type|Default|Description| |:-:|:-:|:-:|-| | dataAttributes |Boolean| false | Set to true if you want attributes not recognized as styleAttribute to be added as data- attribute to the image. | styleAttributes ||| Deprecated ^1.0.0

styleAttributes

As of v1.0.0, this option is deprecated and the behavior described below will always apply.

The plugin uses a list of all CSS properties, as defined by the W3C, to decide whether an attribute is to be added to the image's style or not.

dataAttributes

When options.dataAttributes is true, the plugin will add all attributes whose key isn't a CSS property as data-* attribute to the image.

gatsby-config.js:

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

md:

![happy](https://foomoji.com/happy.png '#tool-tip=Fancy image with tooltip;position=absolute;height=100px')

Where position and height are recognized as styleAttributes, tool-tip is not and due to options.dataAttributes: true applied as data- attribute:

<img
  src="https://foomoji.com/happy.png"
  alt="happy"
  style="position: absolute; height: 100px;"
  data-tool-tip="Fancy image with tooltip"
  class="gatsby-img-attributes"
/>