marp-team / marp-react

[INACTIVE] Marp renderer component for React
https://marp-react.netlify.com/
MIT License
20 stars 3 forks source link

Fix ignored whitespaces and line breaks in fenced code #5

Closed yhatt closed 5 years ago

yhatt commented 5 years ago

It resolves #4.

As like as HTML, JSX converts line breaks to single whitespace. It would bring collapsed whitespaces / line breaks at around highlighted element of code block.

Luckily, we can deal it with using JS expression. This update will convert line breaks in the rendered HTML into JS expression before applying to htm.

In short, it means converting HTM:

htm`
  <pre>
    test({
      foo: 0;
      bar: 0;
    })
  </pre>
`

to

htm`
  <pre>${'\n'}
    test({${'\n'}
      foo: 0;${'\n'}
      bar: 0;${'\n'}
    })${'\n'}
  </pre>
`