Added whitespace and newline support

This commit is contained in:
Simon Backx 2022-07-05 16:37:26 +02:00
parent 81db05a3ac
commit 3522ee6ee1
2 changed files with 11 additions and 2 deletions

View File

@ -4,6 +4,8 @@ import {formatRelativeTime} from '../utils/helpers';
function Comment(props) {
const comment = props.comment;
const html = {__html: comment.html};
return (
<div className="flex mb-4">
<div className="mr-4">
@ -18,7 +20,7 @@ function Comment(props) {
</div>
</div>
<div className="mb-4 font-sans leading-normal dark:text-neutral-300">
<p>{comment.html}</p>
<p dangerouslySetInnerHTML={html} className="whitespace-pre-wrap"></p>
</div>
</div>
</div>

View File

@ -14,6 +14,13 @@ class Form extends React.Component {
this.handleChange = this.handleChange.bind(this);
}
getHTML() {
const text = this.state.message;
// Convert newlines to <br> for now (until we add a real editor)
return text.replace('\n', '<br>');
}
async submitForm(event) {
event.preventDefault();
const message = this.state.message;
@ -28,7 +35,7 @@ class Form extends React.Component {
await this.context.onAction('addComment', {
post_id: this.context.postId,
status: 'published',
html: message
html: this.getHTML()
});
// Clear message on success