remarkjs / react-markdown

Markdown component for React
https://remarkjs.github.io/react-markdown/
MIT License
13.27k stars 876 forks source link

\n Doesn't work properly #818

Closed sash20m closed 9 months ago

sash20m commented 9 months ago

Initial checklist

Affected packages and versions

^9.0.1

Link to runnable example

https://stackblitz.com/edit/github-mmihct?file=src%2Fapp.tsx

Steps to reproduce

Install react-markdown and add as mardown the string "abc\nabc" or any other with the \n. It only makes a blank space between the words. If I added two \n then there will be a new line, but if I added 3 or 4 \n, also it remains only at one new lines. I tried it in a fresh react app, and implemented it exactly as said in docs.

function App() {
  return (
    <div className="App">
      <MarkdownText markdown={"dasd\ndsad"} />
    </div>
  );
}

const MarkdownText = ({ markdown }) => {
  return <Markdown>{markdown}</Markdown>;
};
image
JounQin commented 9 months ago

Please provide minimal but runnable online reproduction.

sash20m commented 9 months ago

Please provide minimal but runnable online reproduction.

https://stackblitz.com/edit/github-mmihct?file=src%2Fapp.tsx

JounQin commented 9 months ago

This is how markdown works?

image
github-actions[bot] commented 9 months ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

github-actions[bot] commented 9 months ago

Hi team! I don’t know what’s up as there’s no phase label. Please add one so I know where it’s at.

Thanks, — bb

ChristianMurphy commented 9 months ago

Welcome @sash20m! 👋 Sorry you ran into some confusion.

As @JounQin mentioned that is how markdown works. If you want an alternative behavior for newline you can use plugins like https://github.com/remarkjs/remark-breaks

remcohaszing commented 9 months ago

As @JounQin stated, this is how markdown works.

I don’t recommend it, but if you insist on turning single newlines into line breaks, you can use remark-breaks.

sash20m commented 9 months ago

As @JounQin stated, this is how markdown works.

I don’t recommend it, but if you insist on turning single newlines into line breaks, you can use remark-breaks.

I was under the impression its relation to \n is the same as any string. I have a long text with \n's and react-markdown fails to add new lines properly to the component.

I'll look at the plugin mentioned above, thank you.