Project: syntax-tree/hast-util-menu-state

Package: hast-util-menu-state@2.0.0

  1. Dependencies: 2·Dependents: 0
  2. hast utility to get the state of a menu element
  1. util 136
  2. utility 132
  3. unist 119
  4. html 111
  5. hast 61
  6. hast-util 40
  7. element 5


Build Coverage Downloads Size Sponsors Backers Chat

hast utility to get the state of a <menu> element.


This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.


npm install hast-util-menu-state


import {menuState} from 'hast-util-menu-state'

// If there’s no last element or that node is not a `menu`:
menuState([{type: 'element', tagName: 'a'}]) // => null

// If the last node is a `menu` without `type`:
menuState([{type: 'element', tagName: 'menu'}]) // => 'toolbar'

// If the last node is a `menu` with a `type`, or that node has
// a parent `menu` with a type:
  {type: 'element', tagName: 'menu', properties: {type: 'context'}},
  {type: 'element', tagName: 'li'},
  {type: 'element', tagName: 'menu'}
]) // => 'context'


This package exports the following identifiers: menuState. There is no default export.

Get the state of a <menu> element. The state is calculated from the lowest <menu> with a valid type property. If no <menu> has a type, it defaults to 'toolbar'.

The algorithm stops looking for higher <menu>s if a template element, or non-element, is found.


string? — either 'context' or 'toolbar' (the state the menu is in), or null, if the last node is not a menu element.


hast-util-menu-state does not change the syntax tree so there are no openings for cross-site scripting (XSS) attacks.


See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.


MIT © Titus Wormer