4.1.0 • Published 5 years ago

@phtml/image-alt v4.1.0

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
5 years ago

pHTML Image Alt

NPM Version Build Status Support Chat

pHTML Image Alt lets you add alt attributes to images in HTML.

<img src="/path/to/image-1.jpg" alt="Mother Nature's Son">
<img src="/path/to/image-2.jpg">
<img src="/path/to/image-3.jpg" alt="">
<img src="/path/to/image-4.jpg">

<!-- becomes -->

<img src="/path/to/image-1.jpg" alt="Mother Nature's Son">
<img src="/path/to/image-2.jpg" alt>
<img src="/path/to/image-3.jpg" alt="">
<img src="/path/to/image-4.jpg" alt>

Usage

Add pHTML Image Alt to your project:

npm install @phtml/image-alt --save-dev

Use pHTML Image Alt to process your HTML:

const phtmlImageAlt = require('@phtml/image-alt');

phtmlImageAlt.process(YOUR_HTML /*, processOptions, pluginOptions */);

Or use it as a pHTML plugin:

const phtml = require('phtml');
const phtmlImageAlt = require('@phtml/image-alt');

phtml([
  phtmlImageAlt(/* pluginOptions */)
]).process(YOUR_HTML /*, processOptions */);

pHTML Image Alt runs in all Node environments, with special instructions for:

NodeCLIEleventyGulpGrunt

Options

alts

The alts option defines alt attributes by a matching src attribute value.

phtmlImageAlt({ alts: {
  '/path/to/image-2.jpg': 'Martha My Dear'
} });
<img src="/path/to/image-1.jpg" alt="Mother Nature's Son">
<img src="/path/to/image-2.jpg">
<img src="/path/to/image-3.jpg" alt="">
<img src="/path/to/image-4.jpg">

<!-- becomes -->

<img src="/path/to/image-1.jpg" alt="Mother Nature's Son">
<img src="/path/to/image-2.jpg" alt="Martha My Dear">
<img src="/path/to/image-3.jpg" alt="">
<img src="/path/to/image-4.jpg" alt>