figure()
Wrap images that have alt text in <figure> and <figcaption> elements.
import { figure } from "@unifast/node";Signature
function figure(): UnifastPluginParameters
None.
Usage
import { compile, figure } from "@unifast/node";
const md = ``;
const result = compile(md, {
plugins: [figure()],
});
// The image is wrapped in <figure> with <figcaption>Examples
Basic figure wrapping
When an image has alt text, figure() wraps it in a <figure> element and adds a <figcaption> containing the alt text:
import { compile, figure } from "@unifast/node";
const md = ``;
const result = compile(md, { plugins: [figure()] });
console.log(result.output);
// <figure><img src="landscape.jpg" alt="A beautiful landscape"><figcaption>A beautiful landscape</figcaption></figure>Image without alt text
Images without alt text are not wrapped, since there is no meaningful caption to display:
import { compile, figure } from "@unifast/node";
const md = ``;
const result = compile(md, { plugins: [figure()] });
console.log(result.output);
// <p><img src="decorative.png" alt=""></p>