rehype-image-caption 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +21 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -45,7 +45,9 @@ const rehypeImageCaption = () => {
|
|
|
45
45
|
* Transformer
|
|
46
46
|
* @param tree Root node
|
|
47
47
|
*/
|
|
48
|
+
// eslint-disable-next-line max-lines-per-function
|
|
48
49
|
const transformer = (tree) => {
|
|
50
|
+
// eslint-disable-next-line max-lines-per-function
|
|
49
51
|
visit(tree, "element", (node) => {
|
|
50
52
|
if (!(node.tagName === "p" && isImage(node.children[0])))
|
|
51
53
|
return;
|
|
@@ -87,6 +89,25 @@ const rehypeImageCaption = () => {
|
|
|
87
89
|
}
|
|
88
90
|
];
|
|
89
91
|
}
|
|
92
|
+
else if (
|
|
93
|
+
// eslint-disable-next-line no-magic-numbers
|
|
94
|
+
node.children.length === 4 &&
|
|
95
|
+
isElement(node.children[1], "br") &&
|
|
96
|
+
node.children[2].type === "text" &&
|
|
97
|
+
node.children[2].value.trim() === "" &&
|
|
98
|
+
isElement(node.children[3], "em")) {
|
|
99
|
+
// Image with caption with line break (with remark-breaks plugin)
|
|
100
|
+
node.tagName = "figure";
|
|
101
|
+
node.children = [
|
|
102
|
+
node.children[0],
|
|
103
|
+
{
|
|
104
|
+
type: "element",
|
|
105
|
+
tagName: "figcaption",
|
|
106
|
+
properties: {},
|
|
107
|
+
children: node.children[3].children
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
}
|
|
90
111
|
});
|
|
91
112
|
};
|
|
92
113
|
return transformer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rehype-image-caption",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "rehype plugin to set captions for images in addition to alt text.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"eslint-plugin-jsdoc": "^48.2.1",
|
|
39
39
|
"prettier": "^3.2.5",
|
|
40
40
|
"rehype-stringify": "^10.0.0",
|
|
41
|
+
"remark-breaks": "^4.0.0",
|
|
41
42
|
"remark-parse": "^11.0.0",
|
|
42
43
|
"remark-rehype": "^11.1.0",
|
|
43
44
|
"typescript": "^5.4.2",
|