rehype-image-caption 1.1.0 → 2.0.1

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.
Files changed (2) hide show
  1. package/dist/index.js +21 -0
  2. package/package.json +4 -6
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": "1.1.0",
3
+ "version": "2.0.1",
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",
@@ -31,13 +31,11 @@
31
31
  },
32
32
  "homepage": "https://github.com/Robot-Inventor/rehype-image-caption#readme",
33
33
  "devDependencies": {
34
- "@typescript-eslint/eslint-plugin": "^7.2.0",
35
- "@typescript-eslint/parser": "^7.2.0",
36
- "eslint": "^8.57.0",
37
- "eslint-config-prettier": "^9.1.0",
38
- "eslint-plugin-jsdoc": "^48.2.1",
34
+ "@robot-inventor/eslint-config": "^0.1.1",
35
+ "eslint": "^9.0.0",
39
36
  "prettier": "^3.2.5",
40
37
  "rehype-stringify": "^10.0.0",
38
+ "remark-breaks": "^4.0.0",
41
39
  "remark-parse": "^11.0.0",
42
40
  "remark-rehype": "^11.1.0",
43
41
  "typescript": "^5.4.2",