syntax-tree / mdast-util-to-hast

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

Expose internals #30

Closed danielepolencic closed 5 years ago

danielepolencic commented 5 years ago

The current handler for a paragraph is defined as such:

function paragraph(h, node) {
  return h(node, 'p', all(h, node))
}

I can override the paragraph element with my custom handler:

unified()
  .use(remark2rehype, {
    handlers: {
      paragraph: (h: any, node: Node) => {
        return h(node, 'my-p', {className: 'p'})
      }
    }
  })

However, I can't call all(node) or one(node) because the two utils are not exposed publicly. All the children for the paragraph are not rendered.

Is it possible to expose the all and one helper to allow subclassing of handlers? At the moment only the top level element can be customised.

ChristianMurphy commented 5 years ago

@danielepolencic those are internal APIs.

If you want to use them, do so at the risk of them not being covered by semantic versioning. If you still want to use them, they can be accessed with:

const all = require('mdast-util-to-hast/lib/all');
const one = require('mdast-util-to-hast/lib/one');
danielepolencic commented 5 years ago

Thanks. I tried to include all and one, but from the wrong package (remark-rehype instead of mdast-util-to-hast). Apologies. I understand that those are internal APIs and shouldn't be used. But is there any alternative?

wooorm commented 5 years ago

@danielepolencic Alternative would be to roll your own all / one, or you can pin the dep!

danielepolencic commented 5 years ago

Ok, thanks. I'll pin the dep.