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

@libsrcdev/gatsby-remark-images-anywhere

v0.1.10

Published

Handle images with relative, absolute, remote path for gatsby-transformer-remark.

Downloads

63

Readme

gatsby-remark-images-anywhere

This plugin processes images from markdown files that are parsed with gatsby-transformer-remark. It supports images from multiple sources including relative paths, remote URLs, protocol-relative URLs, and CMS-generated paths.

Fork Notice

This is a fork of gatsby-remark-images-anywhere with the following improvements:

  • Updated dependencies to latest versions
  • Added support for custom HTTP headers in image requests (useful for authenticated image sources)
  • Enhanced URL validation and security features

Why use this?

gatsby-remark-images is great, but if you use a CMS that pastes remote URLs or paths that aren't relative to the markdown file itself, it won't work. This plugin provides a more flexible solution that:

  • Takes any image path (relative, absolute, remote, protocol-relative) and feeds them to Sharp
  • Allows customized Sharp methods (fluid, fixed, resize)
  • Supports custom image templates
  • Works with NetlifyCMS and other headless CMS platforms
  • Extracts images based on custom logic for thumbnails or galleries

Supported image paths

# Regular relative path
![relative path](./image.png)

# NetlifyCMS path (absolute from root)
![relative from root path](/assets/image.png)

# Remote path
![cloud image](https://images.unsplash.com/photo-1563377176922-062e6ae09ceb)

# Protocol relative path
![cloud image](//images.ctfassets.net/1311eqff/image.png)

# Also works with <img /> tags
<img src="./image.png" alt="hey" title="hello" />

Protocol relative paths

See the whitelisted domains here

How to install

npm i --save @libsrcdev/gatsby-remark-structured-content

Requirements

Your project needs to have:

  • gatsby
  • gatsby-source-filesystem
  • gatsby-transformer-remark
  • gatsby-transformer-sharp
  • gatsby-plugin-sharp

Capabilities

  • List embedded images of markdown content based on custom logic
  • Remove embedded images of markdown content based on custom logic
  • Process images from any source (local, remote, CMS)
  • Generate optimized Sharp images with custom configurations

Use cases

  • Extract the first embedded image to use it as a thumbnail
  • Create a gallery of all images used in a post
  • Process remote images from a headless CMS
  • Handle NetlifyCMS absolute paths

Usage

Basic example:

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        {
          resolve: `gatsby-remark-structured-content`,
          options: {
            // Optional: provide a function to extract images based on custom logic
            shouldExtractImage: async (code) => { ... },
          },
        },
      ],
    },
  },
];

Configuration

Full configuration options:

{
  resolve: `gatsby-remark-structured-content`,
  options: {
    /**
     * @param {string} staticDir
     * Root folder for images. For example,
     * if your image path is `/assets/image.png`,
     * your image is located in `static/assets/image.png`,
     * then the staticDir is `static`.
     */
    staticDir: 'static',

    /**
     * @param {Function} createMarkup
     * A function that returns string template for image
     * All sharp result will be passed in as arguments
     */
    createMarkup: ({ src, srcSet }) => `<img src="${src}" srcSet="${srcSet}" class="custom-class" />`,

    /**
     * @param {'lazy' | 'eager' | 'auto'} loading 
     * Set the output markup's 'loading' attribute. Default: 'lazy'
     */
    loading: 'lazy',

    /**
     * @param {string} backgroundColor
     * Background color. Default: '#fff'
     */
    backgroundColor: '#fff',

    /**
     * @param {boolean} linkImagesToOriginal 
     * If enabled, wraps the default markup with an <a> tag pointing to the original image.
     * Default: false
     */
    linkImagesToOriginal: true,

    /**
     * @param {string | Function} wrapperStyle 
     * Inject styles to the image wrapper.
     * Also accepts a function that receives all image data as arguments:
     * ({ aspectRatio, width, height }) => `padding-bottom: ${height/2}px;`
     */
    wrapperStyle: 'padding-bottom: 0.5rem;',

    /**
     * @param {'fluid' | 'fixed' | 'resize'} sharpMethod
     * Default: 'fluid'.
     */
    sharpMethod: 'fluid',

    /**
     * Sharp image options
     * Any sharp image arguments (quality, maxWidth, etc.)
     */
    maxWidth: 650,
    quality: 50,
  }
}

Writing your own markup

You can customize the image markup using the createMarkup function:

type CreateMarkup = (args: CreateMarkupArgs, options?: MarkupOptions) => string;

interface CreateMarkupArgs {
  sharpMethod: SharpMethod;
  originSrc: string;
  title?: string;
  alt?: string;

  aspectRatio: number;
  src: string;
  srcSet?: string;
  srcWebp?: string;
  srcSetWebp?: string;
  base64?: string;
  tracedSVG?: string;
  
  // fixed, resize
  width?: number;
  height?: number;

  // fluid
  presentationHeight?: number;
  presentationWidth?: number;
  sizes?: string;
  originalImg?: string;
}

interface MarkupOptions {
  loading: 'lazy' | 'eager' | 'auto';
  linkImagesToOriginal: boolean;
  showCaptions: boolean;
  wrapperStyle: string | Function;
  backgroundColor: string;
  tracedSVG: boolean | Object;
  blurUp: boolean;
}

Example

Codesandbox demo showing this plugin combined with gatsby-transformer-remark custom components to achieve gatsby-image-like benefits (blur up, lazy loading, aspect-ratio).

Should I use this?