Skip to content

<p><br /></p> results \ due to wrapText #66

@JounQin

Description

@JounQin

Initial checklist

Affected packages and versions

[email protected]

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions