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

new line character (\n) has been ignore and not rendered #4885

Closed
aszx87410 opened this issue Mar 20, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@aszx87410
Copy link
Contributor

commented Mar 20, 2019

Last week I asked a question about this behavior in spectrum chat: How to input new line when creating a new post?

Basically the problem is about new line, for now the only way to make a new line is to insert two line breaks, which doesn't make sense to me.

Example:

Input:

first line
second line

Expected:

first line
second line

Actual Result:

first line second line

Today I spent some time on the source code and try to solve this issue. At first I thought it's a bug when we transform the markdown to text, and this part is handle by spectrum/shared/draft-utils/process-thread-content.js

I used following example and print the json result to see if there is anything wrong:

Input:

oneline
newline  
thirdline

fourline

fiveline

JSON result after process-thread-content:

{
  "blocks": [
    {
      "key": "bq56i",
      "text": "oneline\nnewline\nthirdline",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    },
    {
      "key": "9h38b",
      "text": "fourline",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    },
    {
      "key": "fuprm",
      "text": "fiveline",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    }
  ],
  "entityMap": {}
}

It turns out that in the json response, the new line character is there(oneline\nnewline\nthirdline), nothing wrong here. So I shift my focus to the renderer part.

For renderer, the related file is spectrum/src/components/threadRenderer/index.js, we use a library called redraft.

In the Common issues sections, you can see following paragraph:

Can the multiple spaces between text be persisted?
Add white-space: pre-wrap to a parent div, this way it will preserve spaces and wrap to new lines (as editor js does)

So simply add while-space: pre-wrap to .markdown can solve this issue. I will submit a PR later, please let me know if there is any issue.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.