I am creating a blog website. I am taking the input using a textarea
and storing it in MongoDB. For displaying the data I use: white-space: pre-wrap;
.
With pre-wrap if I give the input as:
hello
world
The output is:
hello
world
I want the output as:
hello
world
Code: Taking the input:
<form action="/post/compose" method="post">
<div class="form-group">
<label for="postTitle">Title</label>
<input type="text" class="form-control" name="postTitle" >
<label for="postBody">Body</label>
<textarea class="form-control" name="postBody" rows="10" col="10"></textarea>
</div>
<button class="btn btn-success" type="submit">Publish</button>
</form>
Storing the input in database:
const post=new Post({
Title:req.body.postTitle,
Content:req.body.postBody,
});
post.save();
Displaying the input
<div id="fullpost">
<h2 class="text-dark"><%= post.Title %></h2>
<p class="text-dark" id="Postcontent"><%- post.Content %></p>
</div>
css:
#Postcontent{
white-space: pre-wrap;
}
Now as I added white-space property if there is \n in the input ,in the output single whitespace is included.But I want two white spaces. Is it possible to do this without regex in Javascript? Please help. Thanks in advance.