-
-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Labels
💪 phase/solvedPost is donePost is done
Description
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Problem
Maybe a bit similar to syntax-tree/mdast-util-to-markdown#34
I'm trying to implement a tiny util cf2md which Transform from confluence flavored HTML to Markdown with enhanced features.
In confluence's HTML, pre can be used without code inside, so I have to wrap its direct text nodes into a code node to reuse original h.handlers.pre, but there is no defaultHandlers provided, so I have to use import { code } from 'hast-util-to-mdast/lib/handlers/code.js' which is the original h.handlers.pre actually.
import { code } from 'hast-util-to-mdast/lib/handlers/code.js'
unified()
// ...
.use(rehypeRemark, {
handlers: {
pre(h, node, parent) {
// I'd like to have `h.defaultHandlers.pre` here
return code(h, {
...node,
children: node.children.map(child =>
child.type === 'text'
? {
type: 'element',
tagName: 'code',
children: [child],
}
: child,
),
})
},
},
})See also https://github.com/rx-ts/cf2md/blob/main/src/index.ts#L82
Solution
Expose defaultHandlers in h
Alternatives
N/A
Metadata
Metadata
Assignees
Labels
💪 phase/solvedPost is donePost is done