-
-
Notifications
You must be signed in to change notification settings - Fork 874
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
Add examples regarding new lines / line breaks #749
Comments
Your cases seem to have more to do with how JSX works. The JSX transform you use collapsed arbitrary whitespace. E.g., Babel repl. |
What do you propose? I don‘t think this project needs to explain what markdown is and how it works. It already defers to other sources for that. |
Regarding JSX: Regarding proposal: But I'd add another example under examples: Handling line breaks
Tip: We recommend learning how Markdown treats new lines and how plugins (such as |
Having another example is fine, but I’m not sure about this heading, this code. I don’t think humans know that one of these 3 problems you describe (plus the line endings + JSX one) are solved by “Handling line breaks”. And there’s no explanation what the code does. Perhaps a new appendix is better. Say for example: ### Appendix A: line endings in markdown (and in JSX)
You might try to write markdown directly in your JSX and find that it **does
not** work:
```jsx
<ReactMarkdown>
# Hi
This is **not** a paragraph.
</ReactMarkdown>
```
The is because in JSX the whitespace (including line endings) is collapsed to
a single space.
So the above example is equivalent to:
```jsx
<ReactMarkdown> # Hi This is **not** a paragraph. </ReactMarkdown>
```
Instead, to pass markdown to `ReactMarkdown`, you can use the `children` prop
with a template literal:
```jsx
<ReactMarkdown
children={`
# Hi
This is a paragraph.
`}
/>
```
Template literals have another potential problem, because they keep whitespace
(including indentation) inside them.
That means that the following **does not** turn into a heading:
```jsx
<ReactMarkdown
children={`
# This is **not** a heading, it’s an indented code block
`}
/>
``` Now, the hard breaks in markdown / hard breaks with remark-breaks thing is another point that perhaps can be discussed here. |
Sorry for the slow reply – life stuff happening. I think the bare minimum would be a working example like the one I proposed. A more extensive section like yours is even better. So from my end 👍 |
@wooorm thanks for the explanation about JSX , i was dealing with the same line break missing white space, probleme . |
Initial checklist
Problem
I am struggling to work with new lines / line breaks and many others did in the past.
From what I've seen there are three problems:
\n
)Solution
Regarding 1) and 2)
Could be solved/enhanced by mentioning it next to an appropriate example. Something like "Tip: Read up on how Markdown treats new lines and have a look at plugins such as
remark-breaks
that can change this behaviour."Regarding 3)
I compiled a few ways to use markdown that I tried from which some failed, which I think also cause some of the confusion.
❌ Case 1
Doesn't work as expected (treats everything as the headline)
HTML:
✅ Case 2
Works as expected, but has a pitfall:
If a line in the markdown is indented with spaces it (rightfully) gets interpreted as a
pre
-tag.HTML:
✅ Case 3
Works as expected
HTML:
❌ Case 4:
Does not work as expected (treats everything as the headline)
HTML:
Solution
Would be cool to add another example regarding line breaks to the docs. Maybe case 3 with a note regarding the problem with case 4.
Alternatives
It's about a documentation enhancement so I don't think alternatives apply here.
The text was updated successfully, but these errors were encountered: