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

marked-responsive-images

v2.1.3

Published

A robust marked extension for handling responsive images with srcset generation.

Downloads

287

Readme

Marked Responsive Images

License: MIT Latest GitHub release npm

An extension for Marked (github, npm) designed to generate responsive images by parsing simple filename conventions into full <picture> elements with srcset and sizes attributes based on simple filename conventions.

Marked Responsive Images parses image filenames to detect available size and file extension variants without breaking standard markdown compatibility.

Installation

npm install marked-responsive-images

Usage

// Default factory export (recommended)
import { marked } from 'marked';
import { markedResponsiveImages } from 'marked-responsive-images';

/*
// or use UMD scripts
<script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked-responsive-images/dist/index.umd.js"></script>
*/

// Register with marked
marked.use(markedResponsiveImages());

// Render markdown
const html = marked.parse('![My Image](assets/hero__400-300_800-600.jpg)');

Naming Convention

[!TIP]
I have written a PowerShell automation script to automatically generate image size variants, WebP alternatives, and output a fully formed Markedown image link.

Naming the Main File

The extension looks for a specific pattern at the end of your filenames to generate the <source> tags and/or srcset attribute.

Pattern: filename__width-height_width-height-extension[…]_currentFileWidth-currentFileHeight.png

  1. Separator:
    Use two underscores (__) to separate the base name from the sizes.
  2. Variants:
    Use one underscore (_) to separate different size variants.
  3. Dimensions:
    Use a dash (-) to separate width and height.
  4. [optional] Extension:
    Use a second dash (-) to specify a file extension if it is different from the one used by the URL.

[!NOTE]
The "full name" image must exist on your server.
The image path you write in Markdown (e.g., hero__400-300_800-600.jpg) is used as the graceful fallback. This raw filename is assigned to the src attribute of the inner <img> tag and will be the only image loaded if the extension is disabled or if the Markdown is viewed in an environment that doesn't support responsive images.

[!IMPORTANT]
This extension does not resize images.
It is your responsibility to ensure that all physical image files—both the "Full Name" fallback and the individual variants (e.g., hero__400-300.jpg)—actually exist at the destination. This extension only generates the HTML markup to point to them.

Examples

Basic Resizing:

  • Markdown:
    ![Responsive image example](img/photo__400-300_800-600.jpg)
  • Resulting HTML:
    <picture>
    	<source
    		srcset="img/photo__400-300.jpg 400w, img/photo__800-600.jpg 800w"
    		type="image/jpeg"
    	/>
    	<img
    		src="img/photo__400-300_800-600.jpg"
    		width="800"
    		height="600"
    		alt="Responsive image example"
    	/>
    </picture>

Format Switching:

  • Markdown:
    ![Web optimized photo example](img/photo__800-600-webp_800-600.jpg)
  • Resulting HTML:
    <picture>
    	<source srcset="img/photo__800-600.webp 800w" type="image/webp" />
    	<source srcset="img/photo__800-600.jpg 800w" type="image/jpeg" />
    	<img
    		src="img/photo__800-600-webp_800-600.jpg"
    		width="800"
    		height="600"
    		alt="Web optimized photo example"
    	/>
    </picture>

Configuration

You can configure global options for Marked Responsive Images using:

marked.use(
	markedResponsiveImages({
		sizes: null, // {string}
		class: '', // {string}
		pictureClass: '', // {string}
		debug: false, // {boolean}
		lazy: true, // {boolean}
		decoding: 'auto', // {'async' | 'sync' | 'auto'}
		renderSimpleImgTags: false, // {boolean}
	}),
);

| Option | Type | Default | Description | | :-------------------- | :-------- | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | sizes | string | null | The sizes attribute that should be added to <source> or <img> tags. If empty, an automatic default is set based on the largest variant width. | | class | string | '' | The class attribute to apply to rendered <img> tags. | | pictureClass | string | '' | The class attribute to apply to the <picture> wrapper tag. | | lazy | boolean | true | Adds loading="lazy" to images for better page load optimization. | | decoding | string | 'auto' | The decoding attribute strategy to apply to the <img> tag. | | debug | boolean | false | Log warnings to the console when URLs cannot be parsed or formats are malformed. | | renderSimpleImgTags | boolean | false | Enable to generate a simple <img> tag with a srcset attribute instead of a full <picture> element.When enabled, format variations are automatically stripped out, as standard <img> tags do not support format negotiation. |