syntax-tree / mdast-util-to-hast

utility to transform mdast to hast
https://unifiedjs.com
MIT License
102 stars 42 forks source link

Add class if list contains task list items #28

Closed detj closed 5 years ago

detj commented 5 years ago

A task-list-item class is added if the list item seems to be a task list, making it easier to style the task list item.

https://github.com/syntax-tree/mdast-util-to-hast/blob/51bc203c7f9f4107c97883abb964da7519dd2531/lib/handlers/list-item.js#L60

GitHub adds a contains-task-list class to its <ul>. This would make it easier to style a task list differently, which is what I am trying to do in my gatsby-mdx based blog.

Does it make sense to add a class to the <ul> if it contains one or more task list?

wooorm commented 5 years ago

^-- You’re right! I think this is new!

Could you create a PR for this? Should be a change somewhere here:

https://github.com/syntax-tree/mdast-util-to-hast/blob/8a0c14e2ae48d307aa404344b0226af310cabb75/lib/handlers/list.js#L15-L16

Something like this pseudocode:

  items = all(h, node)

  for item in items {
    if (item.properties.className && item.properties.className.indexOf('task-list-item') !== -1) {
      props.className = ['contains-task-list']
      break
    }
  }

  return h(node, name, props, wrap(items, true))
detj commented 5 years ago

@wooorm here you go https://github.com/syntax-tree/mdast-util-to-hast/pull/29