React-markdown: 'break' not working in v3

Created on 21 Nov 2017  路  3Comments  路  Source: remarkjs/react-markdown

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.

Most helpful comment

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>

All 3 comments

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>

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.

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>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

amalajeyan picture amalajeyan  路  4Comments

garrilla picture garrilla  路  4Comments

kennetpostigo picture kennetpostigo  路  4Comments

ghost picture ghost  路  4Comments

neilyoung picture neilyoung  路  3Comments