rehype-image-caption 1.0.0 → 1.1.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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { Plugin } from "unified";
1
+ import "mdast-util-mdx-jsx";
2
2
  import type { Root } from "hast";
3
+ import type { Plugin } from "unified";
3
4
  /**
4
5
  * `rehype` plugin to set captions for images in addition to alt text.
5
6
  * @returns Transformer
package/dist/index.js CHANGED
@@ -1,5 +1,12 @@
1
+ import "mdast-util-mdx-jsx";
1
2
  import { isElement } from "hast-util-is-element";
2
3
  import { visit } from "unist-util-visit";
4
+ /**
5
+ * Check if a node is an image.
6
+ * @param node Node to check
7
+ * @returns `true` if the node is an image, `false` otherwise
8
+ */
9
+ const isImage = (node) => isElement(node, "img") || (node.type === "mdxJsxFlowElement" && ["astro-image", "img"].includes(node.name || ""));
3
10
  /**
4
11
  * `rehype` plugin to set captions for images in addition to alt text.
5
12
  * @returns Transformer
@@ -40,7 +47,7 @@ const rehypeImageCaption = () => {
40
47
  */
41
48
  const transformer = (tree) => {
42
49
  visit(tree, "element", (node) => {
43
- if (!(node.tagName === "p" && isElement(node.children[0], "img")))
50
+ if (!(node.tagName === "p" && isImage(node.children[0])))
44
51
  return;
45
52
  // eslint-disable-next-line no-magic-numbers
46
53
  if (node.children.length === 1) {
package/package.json CHANGED
@@ -1,52 +1,53 @@
1
- {
2
- "name": "rehype-image-caption",
3
- "version": "1.0.0",
4
- "description": "rehype plugin to set captions for images in addition to alt text.",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "files": [
8
- "./dist/"
9
- ],
10
- "type": "module",
11
- "scripts": {
12
- "test": "vitest",
13
- "build": "tsc",
14
- "prepublishOnly": "npm run build",
15
- "format": "prettier ./src/ --write",
16
- "format:check": "prettier ./src/ --check",
17
- "lint": "npx eslint ./src/**/*.ts"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "git+https://github.com/Robot-Inventor/rehype-image-caption.git"
22
- },
23
- "keywords": [
24
- "rehype",
25
- "rehype-plugin"
26
- ],
27
- "author": "Robot-Inventor",
28
- "license": "MIT",
29
- "bugs": {
30
- "url": "https://github.com/Robot-Inventor/rehype-image-caption/issues"
31
- },
32
- "homepage": "https://github.com/Robot-Inventor/rehype-image-caption#readme",
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",
39
- "prettier": "^3.2.5",
40
- "rehype-stringify": "^10.0.0",
41
- "remark-parse": "^11.0.0",
42
- "remark-rehype": "^11.1.0",
43
- "typescript": "^5.4.2",
44
- "vitest": "^1.4.0"
45
- },
46
- "dependencies": {
47
- "hast-util-is-element": "^3.0.0",
48
- "rehype": "^13.0.1",
49
- "unified": "^11.0.4",
50
- "unist-util-visit": "^5.0.0"
51
- }
52
- }
1
+ {
2
+ "name": "rehype-image-caption",
3
+ "version": "1.1.0",
4
+ "description": "rehype plugin to set captions for images in addition to alt text.",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "./dist/"
9
+ ],
10
+ "type": "module",
11
+ "scripts": {
12
+ "test": "vitest",
13
+ "build": "tsc",
14
+ "prepublishOnly": "npm run build",
15
+ "format": "prettier ./src/ --write",
16
+ "format:check": "prettier ./src/ --check",
17
+ "lint": "npx eslint ./src/**/*.ts"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/Robot-Inventor/rehype-image-caption.git"
22
+ },
23
+ "keywords": [
24
+ "rehype",
25
+ "rehype-plugin"
26
+ ],
27
+ "author": "Robot-Inventor",
28
+ "license": "MIT",
29
+ "bugs": {
30
+ "url": "https://github.com/Robot-Inventor/rehype-image-caption/issues"
31
+ },
32
+ "homepage": "https://github.com/Robot-Inventor/rehype-image-caption#readme",
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",
39
+ "prettier": "^3.2.5",
40
+ "rehype-stringify": "^10.0.0",
41
+ "remark-parse": "^11.0.0",
42
+ "remark-rehype": "^11.1.0",
43
+ "typescript": "^5.4.2",
44
+ "vitest": "^1.4.0"
45
+ },
46
+ "dependencies": {
47
+ "hast-util-is-element": "^3.0.0",
48
+ "mdast-util-mdx-jsx": "^3.1.2",
49
+ "rehype": "^13.0.1",
50
+ "unified": "^11.0.4",
51
+ "unist-util-visit": "^5.0.0"
52
+ }
53
+ }