Markdown: Split up render function into toHTML/toPlaintext

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
This commit is contained in:
Johannes Löthberg 2017-01-18 19:29:11 +01:00
parent 6d2e521421
commit 30bd01cdf2
3 changed files with 61 additions and 47 deletions

View file

@ -401,7 +401,7 @@ export default class MessageComposerInput extends React.Component {
let contentState = null;
if (enabled) {
const md = new Markdown(this.state.editorState.getCurrentContent().getPlainText());
contentState = RichText.HTMLtoContentState(md.render(true));
contentState = RichText.HTMLtoContentState(md.toHTML());
} else {
let markdown = stateToMarkdown(this.state.editorState.getCurrentContent());
if (markdown[markdown.length - 1] === '\n') {
@ -524,9 +524,9 @@ export default class MessageComposerInput extends React.Component {
} else {
const md = new Markdown(contentText);
if (md.isPlainText()) {
contentText = md.render(false);
contentText = md.toPlaintext();
} else {
contentHTML = md.render(true);
contentHTML = md.toHTML(true);
}
}

View file

@ -325,13 +325,13 @@ module.exports = React.createClass({
}
if (send_markdown) {
const htmlText = mdown.render(true);
const htmlText = mdown.toHTML();
sendMessagePromise = isEmote ?
MatrixClientPeg.get().sendHtmlEmote(this.props.room.roomId, contentText, htmlText) :
MatrixClientPeg.get().sendHtmlMessage(this.props.room.roomId, contentText, htmlText);
}
else {
const contentText = mdown.render(false);
const contentText = mdown.toPlaintext(false);
sendMessagePromise = isEmote ?
MatrixClientPeg.get().sendEmoteMessage(this.props.room.roomId, contentText) :
MatrixClientPeg.get().sendTextMessage(this.props.room.roomId, contentText);