Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'break' not working in v3 #105

Closed
pcvandamcb opened this issue Nov 21, 2017 · 3 comments
Closed

'break' not working in v3 #105

pcvandamcb opened this issue Nov 21, 2017 · 3 comments

Comments

@pcvandamcb
Copy link

pcvandamcb commented Nov 21, 2017

When allowing all types or specifically 'break' in v3, it will not add BR breaks. This also does not work in the demo which allows all types.

I expected the same behaviour as 'SoftBreak' in v2 (although the naming is confusing...), where single enters end up as a BR and multiple end up as P. The 'SoftBreak' features seems to have been removed however.

@rexxars
Copy link
Collaborator

rexxars commented Nov 21, 2017

It follows the "spec" in this regard; a hard break needs two or more spaces as the end of a line, followed by a newline character. If you want it to insert a break for each newline character, you can do that through a plugin. I've just released v3.0.1 with experimental plugin support.

So in your case, you could install remark-breaks and do the following:

const React = require('react')
const ReactDOM = require('react-dom')
const Markdown  = require('react-markdown')
const breaks = require('remark-breaks')

const input = `break
me
at
every
line`

ReactDOM.render(
  <Markdown source={input} plugins={[breaks]} />,
  document.getElementById('root')
)

Which would output something along the lines of:

<p>break<br />me<br />at<br />every<br />line</p>

@RumenTech
Copy link

Just for your information, the newline character which appears in the very beginning of content, does not render <br />.

I had to append a space to make it work.

@Fleuv
Copy link

Fleuv commented Oct 25, 2019

Not sure if this one is fixable:

const Markdown  = require('react-markdown')
const breaks = require('remark-breaks')

<Markdown source="# Hello\nWorld\n!" plugins={[breaks]} />

Renders:

<h1>Hello</h1>
<p>World<br />!</p>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants