npm

@bradgarropy/rehype-cloudinary-image-size
TypeScript icon, indicating that this package has built-in type declarations

1.0.1Β β€’Β PublicΒ β€’Β Published

πŸ–Ό rehype cloudinary image size

version downloads size github actions coverage typescript contributing contributors discord

Rehype plugin to add width and height to Cloudinary images.

πŸ“¦ Installation

This package is hosted on npm.

npm install @bradgarropy/rehype-cloudinary-image-size

πŸ₯‘ Usage

This is a rehype plugin for use in a unified chain that modifies HTML syntax trees. It adds width and height attributes to all img tags that reference images hosted on Cloudinary.

import {rehypeCloudinaryImageSize} from "@bradgarropy/rehype-cloudinary-image-size"
import rehypeParse from "rehype-parse"
import rehypeStringify from "rehype-stringify"
import {unified} from "unified"

const processor = unified()
    .use(rehypeParse, {fragment: true})
    .use(rehypeCloudinaryImageSize)
    .use(rehypeStringify)

const html = await processor.process(
    '<img src="https://res.cloudinary.com/bradgarropy/image/upload/f_auto,q_auto/bradgarropy.com/pages/home/profile.jpg">',
)

console.log(html)

// output
// <img
//   src="https://res.cloudinary.com/bradgarropy/image/upload/f_auto,q_auto/bradgarropy.com/pages/home/profile.jpg"
//   width="460"
//   height="460"
// >

πŸ“– API Reference

use(rehypeCloudinaryImageSize)

This plugin only adds width and height attributes to images hosted on Cloudinary. All other sources are ignored. Any existing attributes are preserved.

<!-- input -->
<img
    src="https://res.cloudinary.com/bradgarropy/image/upload/f_auto,q_auto/bradgarropy.com/pages/home/profile.jpg"
    alt="description"
/>

<!-- output -->
<img
    src="https://res.cloudinary.com/bradgarropy/image/upload/f_auto,q_auto/bradgarropy.com/pages/home/profile.jpg"
    alt="description"
    width="460"
    height="460"
/>

❔ Questions

πŸ› report bugs by filing issues
πŸ“’ provide feedback with issues or on twitter
πŸ™‹πŸΌβ€β™‚οΈ use my ama or twitter to ask any other questions

✨ contributors


Brad Garropy

πŸ’» πŸ“– ⚠️ πŸš‡

Package Sidebar

Install

npm i @bradgarropy/rehype-cloudinary-image-size

Weekly Downloads

27

Version

1.0.1

License

MIT

Unpacked Size

15.3 kB

Total Files

12

Last publish

Collaborators

  • bradgarropy