Skip to content

Remark plugin that unwraps first and last child nodes from parent nodes

License

Notifications You must be signed in to change notification settings

vwkd/remark-unwrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Remark plugin that unwraps first and last child nodes from parent nodes

Features

  • unwraps a child node from its parent node if it's the first or last child
  • child and parent are defined using a Test

Example

To unwrap child nodes from hyperlinks without URL

import { unified, remarkParse, remarkStringify } from "./deps.ts";
import remarkUnwrap from "./src/main.ts";

const result = (await unified()
  .use(remarkParse)
  .use(remarkUnwrap, {
    childTest: (node, _, parent) =>
      parent?.type == "link" && !parent.url && !parent.title,
    parentTest: undefined,
  })
  .use(remarkStringify)
  .process(`[foobar]()`))
  .toString();
console.log(result);

Before

[foobar]()

After

foobar[]()

About

Remark plugin that unwraps first and last child nodes from parent nodes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published