mdast-move-images-to-root
v1.0.0
Published
Transforms a markdown AST so that image nodes are strict children of the root
Downloads
139
Maintainers
Readme
mdast-move-images-to-root
Transforms a markdown AST (MDAST) so that image nodes are strict children of the root.
Note: positions are not recalculated after this transformation.
Installation
npm install mdast-move-images-to-root
Usage
// ...
var moveImagesToRoot = require('mdast-move-images-to-root');
unified()
.use(parse)
.use(moveImagesToRoot())
// ...
Markdown document:
# Title
> ## *Foo ![my image](./foo.png) ooF*
## ![other image](./bar.jpg)
Input AST:
root[3] (1:1-7:1, 0-78)
├─ heading[1] (2:1-2:8, 1-8) [depth=1]
│ └─ text: "Title" (2:3-2:8, 3-8)
├─ blockquote[1] (4:1-4:38, 10-47)
│ └─ heading[1] (4:3-4:38, 12-47) [depth=2]
│ └─ emphasis[3] (4:6-4:38, 15-47)
│ ├─ text: "Foo " (4:7-4:11, 16-20)
│ ├─ image (4:11-4:33, 20-42) [url="./foo.png"][alt="my image"]
│ └─ text: " ooF" (4:33-4:37, 42-46)
└─ heading[1] (6:1-6:29, 49-77) [depth=2]
└─ image (6:4-6:29, 52-77) [url="./bar.jpg"][alt="other image"]
Output AST:
root[5] (1:1-7:1, 0-78)
├─ heading[1] (2:1-2:8, 1-8) [depth=1]
│ └─ text: "Title" (2:3-2:8, 3-8)
├─ blockquote[1] (4:1-4:38, 10-47)
│ └─ heading[1] (4:3-4:38, 12-47) [depth=2]
│ └─ emphasis[1] (4:6-4:38, 15-47)
│ └─ text: "Foo " (4:7-4:11, 16-20)
├─ image (4:11-4:33, 20-42) [url="./foo.png"][alt="my image"]
├─ blockquote[1] (4:1-4:38, 10-47)
│ └─ heading[1] (4:3-4:38, 12-47) [depth=2]
│ └─ emphasis[1] (4:6-4:38, 15-47)
│ └─ text: " ooF" (4:33-4:37, 42-46)
└─ image (6:4-6:29, 52-77) [url="./bar.jpg"][alt="other image"]