0.0.2 • Published 8 months ago

remark-replace-node v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

remark-replace-node

npm version

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

npm install remark-replace-node
# or
pnpm add remark-replace-node

Use

Say we have the following module example.js:

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(`[![abc.png](https://abc.png)](https://abc.link)`);

console.log(file.value);

Now running node example.js yields:

[abc.png](https://abc.link)

API

This package exports no identifiers. The default export is remarkReplaceNode.

Options

Record<string, (node: Node) => RootContent>;

License

MIT © hungtcs

0.0.2

8 months ago

0.0.1

8 months ago