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

Parsing wordpress category content #864

Open
ElSeniorMikael opened this issue Mar 10, 2023 · 5 comments
Open

Parsing wordpress category content #864

ElSeniorMikael opened this issue Mar 10, 2023 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@ElSeniorMikael
Copy link

Expected Behavior

Parsing the \r\n

Actual Behavior

it remove \r and keep \n

Steps to Reproduce

const text = "toto \r\n toto"

parse(text)

output "toto toto"

description

Wordpress now output some \r\n inside their description field of their category and im using wordpress as an headless cms and i fetch the data on my nextjs project but when i parse the data, im losing the flow of my content and whenever i try to use the "replace" option with the parse, it already have cleaned the "\r" from the text and i only can see those "\n" is there anyway i could include those during the parsin or i would have to replace \n by something like =>

@ElSeniorMikael ElSeniorMikael added the bug Something isn't working label Mar 10, 2023
@remarkablemark
Copy link
Owner

@ElSeniorMikael can you help provide a reproducible example?

@ElSeniorMikael
Copy link
Author

I'm expecting for it to make it a breaking line

@remarkablemark
Copy link
Owner

I can confirm that I can reproduce the issue in https://codesandbox.io/p/sandbox/html-react-parser-864-0v3xvs

This bug is coming from html-dom-parser

@remarkablemark
Copy link
Owner

@ElSeniorMikael can you do this as a workaround?

const text = "toto \r\n toto"

parse(text.replace(/\r/g, "\n"))

Or:

const text = "toto \r\n toto"

parse(text.replace(/\r|\n/g, "<br>"))

See CodeSandbox

It seems that innerHTML strips out carriage returns on the client parser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants