npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rehype-absorb-siblings

v0.2.1

Published

Rehype plugin to manipulate the DOM

Readme

rehype-absorb-siblings

rehype plugin that supports tree manipulation to group a document's tags to enforce a certain formation, such as header / section / footer.

Contents

What is this?

This package is a unified(rehype) that looks at a node's children, and organizes such that child tags not specified will be included in the previous sibling on a specified list.

unified is a project that transforms content with abstract syntax trees (ASTs). rehype adds support for HTML to unified. hast is the HTML AST that rehype uses. This is a rehype plugin uses hast.

When should I use this?

This project is useful to enforce a header/section/footer structure on your document.

With the default options, a document with a tree such as:

- header
- h1: This is a header
- hr
- p: This is section content
- hr
- p: This is another section's content
- footer
- p: This is footer content

will be reformed into:

- header:
  - h1: This is a header
- section:
  - p: This is section content
- hr
- section:
  - p: This is another section's content
- footer:
  - p: This is footer content

This is designed to work with markdown editors which stick to the original markdwn rule of not parsing markdown syntax inside of html tags.

Future

This project is a work-in-progress, created around my own immediate use-case: forming a remark/rehype-processed markdown document into the desired shape. Rehype trees from remark-rehype are not full html documents, merely fragments. I plan to add support to specify which nodes to process, such as body.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install rehype-absorb-siblings

API

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

unified().use(rehypeAbsorbSiblings[, options])

Rewrite the document's nodes according to options or the default options,

Parameters
  • options (Options, optional)
    • configuration
Returns

Transform (Transformer)

Options

Configuration.

Fields
  • default: (string, default: section) -- the tag to use when there is not a current allowed tag
  • allowed: (Array<string>, default: ['header', 'section', 'hr', 'footer']) -- tags permitted at the root level of the node
  • extraAllowed: (Array<string>, optional) -- concatenated onto the allowed value, allows one to provide additional tags to the default ones.
  • greedy: (Record<string, any>, optional) -- keys are tag names which will absorb other non-greedy siblings. See example.
  • stingy: (Array<string>, default: ['hr']) -- tags that do not absorb their subsequent siblings
  • aliases: (Record<string, string>, optional) -- tag names that, when found, are converted another tag. See example.

Examples

Example: using hr tags as section breaks

providing these options:

	unified()
		.use(remarkParse)
		.use(remarkRehype)
		.use(rehypeAbsorbSiblings, {
			alases: { hr: 'section' }
		})
		.use(rehypeStringify)

will transform this markdown:

This is section one

---

This is section two

into this html:

<section><p>This is section one</p></section>
<section><p>This is section two</p></section>

Example: footers with sections

providing these options:

	unified()
		.use(remarkRehype)
		.use(rehypeAbsorbSiblings, {
			greedy: { footer: true }
		})
		.use(rehypeStringify)

Will transform this html:

<p>This is a top-level section</p>
<footer></footer>
<p>This is the first footer section</p>
<hr>
<p>This is the second footer section</p>

into this:

<section><p>This is a top-level section</p></section>
<footer>
<section><p>This is the first footer section</p></section>
<hr>
<section><p>This is the second footer section</p></section>
</footer>

The greedy option will continue to absorb subsequent siblings until another greedy sibling is found, in this case a second footer.

Compatibility

This project is compatible with NodeJS version 20 and forward.

This plugin works with unified version 11+. It may work with versions 6+ but I have not tested it with those.

Security

Use of rehype-absorb-siblings is safe by default.

License

ACSL © Matthew Lyon