Skip to content

Releases: chrisnewtn/hast-util-find-parent

v1.0.2

02 Dec 13:08
Compare
Choose a tag to compare

No code changes. Another attempt at a fix for the publishing workflow.

v1.0.1

02 Dec 13:00
Compare
Choose a tag to compare

No code changes. Fixes the GitHub publishing workflow and updates the package readme with information about the package's exported API.

v1.0.0

02 Dec 12:46
Compare
Choose a tag to compare

The initial release of the library.

API

This package exports a single function findParent.

findParent(element, tree)

Finds the immediate parent of the passed element in the passed tree.

Parameters
  • element (Element)
    — A hast Element.
  • tree (Parent)
    — A hast Parent.
Returns

The immediate Parent of the passed element. This could be tree itself.

Example
import { h } from 'hastscript';
import { findParent } from 'hast-util-find-parent';

const element = h('h1', 'Hello, world!');

const tree = h('root',
  h('article', [element])
);

console.log(
  findParent(element, tree)
);

Yields:

{
  type: 'element',
  tagName: 'article',
  properties: {},
  children: [
    {
      type: 'element',
      tagName: 'h1',
      properties: {},
      children: [Array]
    }
  ]
}