rehypejs / rehype-raw

plugin to parse the tree again
https://unifiedjs.com
MIT License
142 stars 9 forks source link

Markdown after self-closing html tag is not parsed #16

Closed Bundas closed 4 years ago

Bundas commented 4 years ago

Markdown after self-closing html tag is not parsed

When there is a self closing tag (eg. <br/>) before markdown content, the markdown is not parsed and is shown as is.

Steps to reproduce

Example input:

<img src="https://a.storyblok.com/f/68034/756x1000/db92d9ed67/hc_3000_r.png" width="110" />
El <b>VF 1000 / 65R32 CFO 200A8 HC3000R TL</b> tiene un **nuevo** diseño de banda de rodadura

Expected behaviour

Img + El VF 1000 / 65R32 CFO 200A8 HC3000R TL tiene un nuevo diseño de banda de rodadura

Actual behaviour

Img + El VF 1000 / 65R32 CFO 200A8 HC3000R TL tiene un **nuevo** diseño de banda de rodadura

wooorm commented 4 years ago

This should work, could you provide an example of how you are doing all this?

Bundas commented 4 years ago

@wooorm I was also checking if the input isn't somehow escaped but it is not so the problem is somewhere in the unified tree

import markdown from 'remark-parse'
import raw from 'rehype-raw'
import remark2rehype from 'remark-rehype'
import rehype2react from 'rehype-react'

const processor = unified()
  .use(markdown)
  .use(remark2rehype, { allowDangerousHTML: true })
  .use(raw)
  .use(rehype2react, {
    createElement: React.createElement,
  })

{processor.processSync(original).contents}
wooorm commented 4 years ago

Ah, the problem is that you’re missing an empty line between HTML and Markdown. See https://github.com/rehypejs/rehype-raw/issues/8 for more info.

If you want to enter markdown after block-level HTML again, you need that blank line. Without it, markdown parsers see it as one block of HTML.