1.0.6 • Published 9 months ago

remark-figure-caption v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

remark-figure-caption

A remark plugin to transform images or code blocks followed by blockquotes into figures with captions.

Installation

npm install remark-figure-caption

Usage

This plugin can be used with the unified ecosystem, specifically with remark for Markdown processing.

import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkFigureCaption from 'remark-figure-caption'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'

const processor = unified()
  .use(remarkParse)
  .use(remarkFigureCaption)
  .use(remarkRehype)
  .use(rehypeStringify)

const markdown = `
![Image alt text](image.jpg)

> This is the caption for the image.

\`\`\`js
console.log('Hello World');
\`\`\`

> This is a code caption.
`

processor.process(markdown).then((file) => {
  console.log(String(file))
})

How it works

This plugin transforms:

  1. An image immediately followed by a blockquote
  2. A code block immediately followed by a blockquote

Into a <figure> element containing the image or code block, with the blockquote content as a <figcaption>.

Example Input

![Image alt text](image.jpg)

> This is the caption for the image.

\`\`\`js
console.log('Hello World');
\`\`\`

> This is a code caption.

Example Output (HTML)

<figure>
  <img src="image.jpg" alt="Image alt text">
  <figcaption>This is the caption for the image.</figcaption>
</figure>

<figure>
  <pre><code class="language-js">console.log('Hello World');</code></pre>
  <figcaption>This is a code caption.</figcaption>
</figure>

License

MIT

Contributing

Contributions, issues, and feature requests are welcome!

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago