@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

๐Ÿ’ป ๐Ÿ“– โš ๏ธ ๐Ÿš‡

Dependentsโ€‚(0)

Package Sidebar

Install

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

Weekly Downloads

5

Version

1.0.1

License

MIT

Unpacked Size

15.3 kB

Total Files

12

Last publish

Collaborators

  • bradgarropy