Skip to content

Custom newline/hard-break rule with React parser #84

@Nevvulo

Description

@Nevvulo

Hi there! I'm having some issues creating a custom rule that will allow all newlines to be treated as a hard-break, here's an example of the behaviour I'm looking for:

Line 1\nLine 2\n\nLine 4\n\n\n\nLine 8\nLine 9\n\nLine 11
should return:

Content Raw
Line 1 Line 1<br />
Line 2 Line 2<br />
<br />
Line 4 Line 4<br />
<br />
<br />
<br />
Line 8 Line 8<br />
Line 9 Line 9<br />
<br />
Line 11 Line 11

EDIT: The table above says that all newlines should be replaced with <br /> but this doesn't have to be the case, I'm just looking for a way to translate all newlines created by the user into the content like this - my attempts keep wrapping each text node in a div and therefore none of the newlines are being rendered (see here)

I understand this isn't exactly how the specifications describe how newlines should work but that's the whole reason I've wanted to add a custom rule to allow for more than one break without doing weird stuff.

I've been trying to solve this for quite some time and I've had a look at similar issues such as #61 (and in other implementations) but even after adopting the code from that issue, I've had trouble getting it to work the way I want: multiple newlines in a row only count as one. Any help would be appreciated, thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions