From 802ec1169f02602948b8c50c688233ddcbbe31a4 Mon Sep 17 00:00:00 2001 From: Aviral Dasgupta Date: Wed, 7 Sep 2016 23:56:22 +0530 Subject: [PATCH] Fix Markdown conversion to not add extra \n Fixes vector-im/vector-web#2094 --- src/components/views/rooms/MessageComposerInput.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index 32f4497326..2e8ca5c78a 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -404,11 +404,13 @@ export default class MessageComposerInput extends React.Component { enableRichtext(enabled: boolean) { if (enabled) { - let html = mdownToHtml(this.state.editorState.getCurrentContent().getPlainText()); - this.setEditorState(this.createEditorState(enabled, RichText.HTMLtoContentState(html))); + const html = mdownToHtml(this.state.editorState.getCurrentContent().getPlainText()); + const contentState = RichText.HTMLtoContentState(html); + this.setEditorState(this.createEditorState(enabled, contentState)); } else { - let markdown = stateToMarkdown(this.state.editorState.getCurrentContent()), - contentState = ContentState.createFromText(markdown); + let markdown = stateToMarkdown(this.state.editorState.getCurrentContent()); + markdown = markdown.substring(0, markdown.length - 1); // stateToMarkdown tacks on an extra newline (?!?) + const contentState = ContentState.createFromText(markdown); this.setEditorState(this.createEditorState(enabled, contentState)); }