-
-
Notifications
You must be signed in to change notification settings - Fork 16
Closed
Labels
👶 semver/patchThis is a backwards-compatible fixThis is a backwards-compatible fix💪 phase/solvedPost is donePost is done🗄 area/interfaceThis affects the public interfaceThis affects the public interface🦋 type/enhancementThis is great to haveThis is great to have
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)
Affected packages and versions
Link to runnable example
No response
Steps to reproduce
import fs from 'fs'
import type { Element } from 'hast'
import { all } from 'hast-util-to-mdast'
import { code } from 'hast-util-to-mdast/lib/handlers/code.js'
import rehypeParse from 'rehype-parse'
import rehypeRemark from 'rehype-remark'
import remarkStringify from 'remark-stringify'
import { unified } from 'unified'
const processor = unified()
.use(rehypeParse)
.use(rehypeRemark, {
handlers: {
div(h, node: Element) {
if (
(node.properties?.className as string[] | undefined)?.includes(
'toc-macro',
)
) {
return
}
return all(h, node)
},
pre(h, node: Element) {
// `h.handlers.code` is actually `inlineCode`
return code(h, {
...node,
children: node.children.map(child =>
child.type === 'text'
? {
type: 'element',
tagName: 'code',
children: [child],
}
: child,
),
})
},
},
})
.use(remarkStringify, {
fences: true,
})
const main = async () => {
const text = await fs.promises.readFile('index.html', 'utf8')
const vfile = await processor.process(text)
await fs.promises.writeFile('index.md', vfile.value)
}
main().catch(console.error)
<!-- index.html -->
<p><br /></p>
Expected behavior
empty line
Actual behavior
\
Runtime
Node v12
Package manager
yarn v1
OS
macOS
Build and bundle tools
esbuild
ravi-ojha
Metadata
Metadata
Assignees
Labels
👶 semver/patchThis is a backwards-compatible fixThis is a backwards-compatible fix💪 phase/solvedPost is donePost is done🗄 area/interfaceThis affects the public interfaceThis affects the public interface🦋 type/enhancementThis is great to haveThis is great to have