Skip to content

Index Props for <li> #1391

Answered by wooorm
drxc00 asked this question in Q&A
Dec 9, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

You duplicate walking. That means that for lists in lists, as in list items in list items, you will have problems.

Lists have exactly only list items as children. List items have exactly only a list as a parent. This fact makes things simpler.
Also: I recommend using the common HTML data attribute name pattern.
Say for example:

visit(tree, function (node, index) {
  if (node.type === 'listItem' && typeof index === 'number') {
    node.data = node.data || {}
    node.data.hProperties = node.data.hProperties || {}
    node.data.hProperties.dataListIndex = index
  }
})

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@drxc00
Comment options

@wooorm
Comment options

Answer selected by drxc00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants