
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@microflash/rehype-figure
Advanced tools
rehype plugin to transform an image with alt text to a figure with caption
rehype plugin to transform an image with alt text to a figure with caption
This package is a unified (rehype) plugin that takes an image node with alt text (e.g., 
) and converts it to a figure element with caption.
<figure>
<img src="path-to-image.jpg" alt="Alt text">
<figcaption>Alt Text</figcaption>
</figure>
This package is ESM only.
In Node.js (16.0+), install with npm:
npm install @microflash/rehype-figure
For Node.js versions below 16.0, stick to 1.x.x versions of this plugin.
In Deno, with esm.sh:
import rehypeFigure from "https://esm.sh/@microflash/rehype-figure";
In browsers, with esm.sh:
<script type="module">
import rehypeFigure from "https://esm.sh/@microflash/rehype-figure?bundle";
</script>
Say we have the following module example.js
:
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkGfm from "remark-gfm";
import remarkRehype from "remark-rehype";
import rehypeFigure from "@microflash/rehype-figure";
import rehypeStringify from "rehype-stringify";
main()
async function main() {
const file = await unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeFigure)
.use(rehypeStringify)
.process("");
console.log(String(file));
}
Running that with node example.js
yields:
<figure>
<img src="path-to-image.jpg" alt="Alt Text">
<figcaption>Alt Text</figcaption>
</figure>
The default export is rehypeFigure
.
The following options are available. All of them are optional.
className
: class for the wrapped figure
elementBy default, no classes are added to the figure
element.
FAQs
rehype plugin to transform an image with alt text to a figure with caption
The npm package @microflash/rehype-figure receives a total of 21,729 weekly downloads. As such, @microflash/rehype-figure popularity was classified as popular.
We found that @microflash/rehype-figure demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.