Skip to content
New issue

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

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

Already on GitHub? # to your account

Double line breaks (\n\n) are not converted properly #580

Open
sdeep27 opened this issue May 14, 2024 · 3 comments
Open

Double line breaks (\n\n) are not converted properly #580

sdeep27 opened this issue May 14, 2024 · 3 comments

Comments

@sdeep27
Copy link

sdeep27 commented May 14, 2024

If i write a text string "Hello\n\nHow are you?"
I expect:
Hello

How are you?

Instead markdown-to-jsx converts it to:
Hello
How are you?

I am specifically using this with a streaming response from an AI LLM which outputs line breaks as \n and usually \n\n between paragraphs but it is markdown-to-jsx is not conserving it. If I try to replace instances of \n with < br / > tag it will create the line break properly but it will break markdown elsewhere in the output.

@vincentDen
Copy link

vincentDen commented May 30, 2024

I fixed it with the option forceInline along with the css property white-space: pre-wrap :

import MarkdownToJsx from 'markdown-to-jsx'

<span style={{ whiteSpace: 'pre-wrap' }}>
    <MarkdownToJsx
        options={{
            forceInline: true,
        }}>
        {"Hello\n\nHow are you?"}
    </MarkdownToJsx>
</span>

I don't really know why does this work tho

@zaadevofc
Copy link

I fixed it with the option forceInline along with the css property white-space: pre-wrap :

import MarkdownToJsx from 'markdown-to-jsx'

<span style={{ whiteSpace: 'pre-wrap' }}>
    <MarkdownToJsx
        options={{
            forceInline: true,
        }}>
        {"Hello\n\nHow are you?"}
    </MarkdownToJsx>
</span>

I don't really know why does this work tho

thank for save my work, thats work 🤩

@cloudkite
Copy link

cloudkite commented Oct 30, 2024

Unfortunately if you do forceInline: true this disables all block rendering like tables and lists. Would be good if there was a better workaround/fix

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants