Questions & Answers

How to store blog posts's code examples in mongoDB and keep the indentation and line breaks?

I'm building a tech blog that has code examples in the articles using Angular, Node.js and MongoDB, I'm storing the post bodies in an html format. When I store a post the code snippets indentations and line breaks are being replaced by whitespaces. I can't find a way to store them and display them the way I want.


body {
  color: #ffffff;

What I get

body  {          color: #ffffff;      }

Btw I'm using Prism.js as a syntax highlighter.

2023-01-17 18:42:03
You have to find out where exactly this transformation happens. MongoDB certainly does not change any of the data you put into it. Review your code to see what might do this. If necessary sprinkle debug output around.
2023-01-17 18:42:03
Hello Sabrina. Welcome to the community! Can you provide the code you use to store and to return the code examples?
Answers(1) :

i wnt to know answer too please someone answer this question

2023-01-17 18:42:04
Hacamba Camba, please don't add Me too as answers. It doesn't actually provide an answer to the question. If you have a different but related question, then ask it (reference this one if it will help provide context). If you are interested in this specific question, you can upvote it, leave a comment, or start a bounty once you have enough reputation.
2023-01-17 18:42:04
@Yunnosch I'm so sorry please dont be mad i didnt know it was accident im so so sorry please i will never do it again im sorry
2023-01-17 18:42:04
OK, especially since as a an unregistered user you cannot even clean up. Please consider to take the tour. And, your decision, to register; to have at least a few more options.