@mirrordown/remd-unwrap-images 0.1.3 → 0.1.4
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/CHANGELOG.md +9 -0
- package/README.md +9 -25
- package/dist/index.d.mts +2 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
## 0.1.4
|
|
8
|
+
<sub>2026-10-28</sub>
|
|
9
|
+
|
|
10
|
+
- *(patch)*
|
|
11
|
+
Sätteri ports of the hast plugins: `@mirrordown/sat-squeeze-paragraphs`, `sat-unwrap-images`, `sat-sectionize`, `sat-lightbox` and `sat-autolink-headings`, all included in `@mirrordown/preset-satteri` (whose stylesheet now also imports the lightbox and autolink-headings styles). Their output is identical to the markdown-it and rehype plugins'. `sat-autolink-headings` takes the same options as `remd-autolink-headings`, including the hast-node ones (`content`, `group`, `properties`, `headingProperties`, `test`).
|
|
12
|
+
|
|
13
|
+
The rules these engines must compute identically move into `@mirrordown/core` (`isEmptyParagraph`, `isImageParagraph`, `sectionize`, `headingRank`, and the lightbox's marker, ids and markup), which the rehype plugins now use too; their output is unchanged, and squeeze-paragraphs and unwrap-images drop `hast-util-whitespace`.
|
|
14
|
+
|
|
6
15
|
## 0.1.3
|
|
7
16
|
<sub>2026-06-28</sub>
|
|
8
17
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mirrordown/remd-unwrap-images
|
|
2
2
|
|
|
3
|
-
> Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified
|
|
3
|
+
> Part of [Mirrordown](https://github.com/mirrordown/mirrordown) — a suite of markdown syntax extensions for the unified, markdown-it and Sätteri ecosystems.
|
|
4
4
|
|
|
5
5
|
A remark/rehype (unified) plugin for the `unwrap-images` syntax extension.
|
|
6
6
|
|
|
@@ -9,31 +9,29 @@ A remark/rehype (unified) plugin for the `unwrap-images` syntax extension.
|
|
|
9
9
|
The `unwrap-images` plugin removes the `<p>` wrapper that Markdown adds around standalone images, allowing images to render as direct block-level elements. Images inside links are also unwrapped.
|
|
10
10
|
|
|
11
11
|
**Before:**
|
|
12
|
-
|
|
13
12
|
```html
|
|
14
|
-
<p><img src="photo.jpg" alt="A photo"
|
|
13
|
+
<p><img src="photo.jpg" alt="A photo"></p>
|
|
15
14
|
```
|
|
16
15
|
|
|
17
16
|
**After:**
|
|
18
|
-
|
|
19
17
|
```html
|
|
20
|
-
<img src="photo.jpg" alt="A photo"
|
|
18
|
+
<img src="photo.jpg" alt="A photo">
|
|
21
19
|
```
|
|
22
20
|
|
|
23
21
|
## Syntax
|
|
24
22
|
|
|
25
23
|
Any image that stands alone on a paragraph — with no other text or inline content — is unwrapped:
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
````markdown
|
|
28
26
|

|
|
29
27
|
|
|
30
28
|
Images mixed with text are **not** unwrapped:
|
|
31
29
|
|
|
32
30
|
Here is an inline image:  within a sentence.
|
|
33
|
-
|
|
31
|
+
````
|
|
34
32
|
|
|
35
|
-
[!NOTE]
|
|
36
|
-
This is a rehype plugin (`rehype-*`), not a remark plugin. Add it **after** `remarkRehype` in your pipeline.
|
|
33
|
+
> [!NOTE]
|
|
34
|
+
> This is a rehype plugin (`rehype-*`), not a remark plugin. Add it **after** `remarkRehype` in your pipeline.
|
|
37
35
|
|
|
38
36
|
## Install
|
|
39
37
|
|
|
@@ -66,22 +64,8 @@ import { rehypeUnwrapImages } from "@mirrordown/remd-unwrap-images";
|
|
|
66
64
|
|
|
67
65
|
export default defineConfig({
|
|
68
66
|
markdown: {
|
|
69
|
-
rehypePlugins: [rehypeUnwrapImages]
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
### VitePress
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
// .vitepress/config.ts
|
|
78
|
-
import { defineConfig } from "vitepress";
|
|
79
|
-
import { rehypeUnwrapImages } from "@mirrordown/remd-unwrap-images";
|
|
80
|
-
|
|
81
|
-
export default defineConfig({
|
|
82
|
-
markdown: {
|
|
83
|
-
rehypePlugins: [rehypeUnwrapImages]
|
|
84
|
-
}
|
|
67
|
+
rehypePlugins: [rehypeUnwrapImages],
|
|
68
|
+
},
|
|
85
69
|
});
|
|
86
70
|
```
|
|
87
71
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { Root } from "hast";
|
|
2
2
|
import { Plugin } from "unified";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** rehype plugin that unwraps block-level images out of their paragraph. */
|
|
6
|
-
declare const rehypeUnwrapImages: Plugin<[], Root>;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { rehypeUnwrapImages };
|
|
3
|
+
/** rehype plugin that unwraps block-level images out of their paragraph. The rule is shared with the Sätteri plugin through `@mirrordown/core`. */
|
|
4
|
+
export declare const rehypeUnwrapImages: Plugin<[], Root>;
|
|
9
5
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;qBAMa,oBAAoB,WAAW"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,15 @@
|
|
|
1
1
|
import { SKIP, visit } from "unist-util-visit";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const HAS_IMAGE = 2;
|
|
6
|
-
const HAS_OTHER = 3;
|
|
7
|
-
const applicable = (node, inLink) => {
|
|
8
|
-
let result = UNKNOWN;
|
|
9
|
-
for (const child of node.children) {
|
|
10
|
-
if (child.type === "text" && whitespace(child.value)) continue;
|
|
11
|
-
if (child.type !== "element") return HAS_OTHER;
|
|
12
|
-
if (child.tagName === "img") {
|
|
13
|
-
result = HAS_IMAGE;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
if (!inLink && (child.tagName === "a" || child.tagName === "button")) {
|
|
17
|
-
const inner = applicable(child, true);
|
|
18
|
-
if (inner === HAS_OTHER) return HAS_OTHER;
|
|
19
|
-
if (inner === HAS_IMAGE) result = HAS_IMAGE;
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
return HAS_OTHER;
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
/** rehype plugin that unwraps block-level images out of their paragraph. */
|
|
2
|
+
import { isImageParagraph } from "@mirrordown/core";
|
|
3
|
+
// src/index.ts
|
|
4
|
+
/** rehype plugin that unwraps block-level images out of their paragraph. The rule is shared with the Sätteri plugin through `@mirrordown/core`. */
|
|
27
5
|
const rehypeUnwrapImages = () => (tree) => {
|
|
28
6
|
visit(tree, "element", (node, index, parent) => {
|
|
29
|
-
if (
|
|
7
|
+
if (parent && typeof index === "number" && isImageParagraph(node)) {
|
|
30
8
|
parent.children.splice(index, 1, ...node.children);
|
|
31
9
|
return [SKIP, index];
|
|
32
10
|
}
|
|
33
11
|
});
|
|
34
12
|
};
|
|
35
|
-
//#endregion
|
|
36
13
|
export { rehypeUnwrapImages };
|
|
37
14
|
|
|
38
15
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { SKIP, visit } from \"unist-util-visit\";\nimport {
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { SKIP, visit } from \"unist-util-visit\";\nimport { isImageParagraph } from \"@mirrordown/core\";\nimport type { Root } from \"hast\";\nimport type { Plugin } from \"unified\";\n\n/** rehype plugin that unwraps block-level images out of their paragraph. The rule is shared with the Sätteri plugin through `@mirrordown/core`. */\nexport const rehypeUnwrapImages: Plugin<[], Root> = () => (tree) => {\n visit(tree, \"element\", (node, index, parent) => {\n if (parent && typeof index === \"number\" && isImageParagraph(node)) {\n parent.children.splice(index, 1, ...node.children);\n return [SKIP, index];\n }\n return;\n });\n};\n"],"mappings":";;;;AAMA,MAAa,4BAA8C,SAAS;CAClE,MAAM,MAAM,YAAY,MAAM,OAAO,WAAW;EAC9C,IAAI,UAAU,OAAO,UAAU,YAAY,iBAAiB,IAAI,GAAG;GACjE,OAAO,SAAS,OAAO,OAAO,GAAG,GAAG,KAAK,QAAQ;GACjD,OAAO,CAAC,MAAM,KAAK;EACrB;CAEF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirrordown/remd-unwrap-images",
|
|
3
3
|
"description": "A remark plugin for unwrapping block-level images out of their surrounding paragraph.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Drake Costa <drake@saeris.io> (https://saeris.gg)",
|
|
7
7
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"
|
|
23
|
+
"@mirrordown/core": "^0.1.0",
|
|
24
24
|
"unist-util-visit": "^5.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|