https://github.com/hungtcs/remark-replace-node
replace the markdown node of the specified type with another type
https://github.com/hungtcs/remark-replace-node
Last synced: 3 months ago
JSON representation
replace the markdown node of the specified type with another type
- Host: GitHub
- URL: https://github.com/hungtcs/remark-replace-node
- Owner: hungtcs
- License: mit
- Created: 2023-09-25T07:24:26.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-25T07:39:45.000Z (almost 3 years ago)
- Last Synced: 2025-03-21T08:12:41.238Z (over 1 year ago)
- Language: TypeScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# remark-replace-node
[](https://badge.fury.io/js/remark-replace-node)
Remark plugin to replace the markdown node of the specified type with another type.
## When should I use this?
When you don't want to render a certain type of node, you can use this plugin to convert it into a regular text node.
## Install
```shell
npm install remark-replace-node
# or
pnpm add remark-replace-node
```
## Use
Say we have the following module example.js:
```ts
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkStringify from "remark-stringify";
import remarkReplaceNode from "remark-replace-node";
const replacements = {
image: (node) => ({
type: "text",
value: node.alt || node.url,
}),
};
const file = await unified()
.use(remarkParse)
.use(remarkReplaceNode, replacements)
.use(remarkStringify)
.process(`[](https://abc.link)`);
console.log(file.value);
```
Now running node example.js yields:
```markdown
[abc.png](https://abc.link)
```
## API
This package exports no identifiers. The default export is remarkReplaceNode.
### Options
```ts
Record RootContent>;
```
## License
[MIT](./LICENSE) © [hungtcs](https://github.com/hungtcs)