|
1 |
| -# rehype-figure |
| 1 | +# rehype-figure |
| 2 | + |
| 3 | +[](https://travis-ci.com/josestg/rehype-figure) |
| 4 | + |
| 5 | +[rehype](https://github.com/rehypejs/rehype) plugins to support figure and caption! |
| 6 | + |
| 7 | +## Install |
| 8 | + |
| 9 | +```shell |
| 10 | +npm install rehype-figure |
| 11 | + |
| 12 | +or |
| 13 | + |
| 14 | +yarn add rehype-figure |
| 15 | +``` |
| 16 | + |
| 17 | +## Use |
| 18 | + |
| 19 | +**Markdown:** |
| 20 | + |
| 21 | +```md |
| 22 | +# Images |
| 23 | + |
| 24 | +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua |
| 30 | + |
| 31 | + |
| 32 | +``` |
| 33 | + |
| 34 | +**rehype-figure:** |
| 35 | + |
| 36 | +```js |
| 37 | +const unified = require("unified") |
| 38 | +const remark = require("remark-parse") |
| 39 | +const remark2rehype = require("remark-rehype") |
| 40 | +const stringify = require("rehype-stringify") |
| 41 | +const assert = require("assert") |
| 42 | +const vfile = require("to-vfile") |
| 43 | + |
| 44 | +const rehypeFigure = require("rehype-figure") |
| 45 | + |
| 46 | +function compile(filename) { |
| 47 | + return unified() |
| 48 | + .use(remark) |
| 49 | + .use(remark2rehype) |
| 50 | + .use(rehypeFigure, { className: "my-figure" }) |
| 51 | + .use(stringify) |
| 52 | + .processSync(vfile.readSync("./__example__/" + filename)) |
| 53 | + .toString() |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +**Yields:** |
| 58 | + |
| 59 | +```html |
| 60 | +<h1>Images</h1> |
| 61 | +<p> |
| 62 | + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod |
| 63 | + tempor incididunt ut labore et dolore magna aliqua |
| 64 | +</p> |
| 65 | +<div class="my-figure-container"> |
| 66 | + <figure class="my-figure"> |
| 67 | + <img |
| 68 | + src="https://img.id/dog.png" |
| 69 | + alt="This is a caption and image alt property" |
| 70 | + /> |
| 71 | + <figcaption>This is a caption and image alt property</figcaption> |
| 72 | + </figure> |
| 73 | + <figure class="my-figure"> |
| 74 | + <img |
| 75 | + src="https://img.id/cat.png" |
| 76 | + alt="These two images will be children 'rehype-container'" |
| 77 | + /> |
| 78 | + <figcaption> |
| 79 | + These two images will be children 'rehype-container' |
| 80 | + </figcaption> |
| 81 | + </figure> |
| 82 | +</div> |
| 83 | +<p> |
| 84 | + Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod |
| 85 | + tempor incididunt ut labore et dolore magna aliqua |
| 86 | +</p> |
| 87 | +<figure class="my-figure"> |
| 88 | + <img |
| 89 | + src="https://img.id/cat.png" |
| 90 | + alt="These two images will be children 'rehype-container'" |
| 91 | + /> |
| 92 | + <figcaption>These two images will be children 'rehype-container'</figcaption> |
| 93 | +</figure> |
| 94 | +``` |
0 commit comments