UNPKG

remark-figure-caption

Version:

A remark plugin to wrap images with next line blockquote in figure elements with captions.

41 lines (40 loc) 1.19 kB
import { visit as p } from "unist-util-visit"; function s() { return function(a) { p(a, (e, i, r) => { if (!((e.type === "paragraph" && e.children.length === 1 && e.children[0].type === "image" || e.type === "paragraph" && e.children.length === 1 && e.children[0].type === "link" && e.children[0].children.length === 1 && e.children[0].children[0].type === "image" || e.type === "code") && r.children[i + 1] && r.children[i + 1].type === "blockquote")) return; let c; switch (e.type) { case "code": c = e; break; case "paragraph": switch (e.children[0].type) { case "image": c = e.children[0]; break; case "link": c = e.children[0]; break; } } const h = r.children[i + 1], t = { type: "figure", children: [c], data: { hName: "figure" } }, l = { type: "figureCaption", children: [...h.children], data: { hName: "figcaption" } }; t.children.push(l), r.children.splice(i, 2, t); }); }; } export { s as default };