From 5c3ef7875f50100ddaa20cd6702e77c1a7c3d29d Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Fri, 15 Dec 2017 12:00:17 +0530 Subject: [PATCH] FIX: Inline head tag html pasting --- .../discourse/components/d-editor.js.es6 | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6 index 2b255286f30..e36329ff499 100644 --- a/app/assets/javascripts/discourse/components/d-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/d-editor.js.es6 @@ -639,6 +639,17 @@ export default Ember.Component.extend({ return null; }, + _pasteMarkdown(text) { + const lineVal = this._getSelected(null, {lineVal: true}).lineVal; + + if(lineVal) { // inline pasting + text = text.replace(/^#+/, "").trim(); + text = (lineVal.search(/\s$/) === lineVal.length - 1) ? text : ` ${text}`; + } + + this.appEvents.trigger('composer:insert-text', text); + }, + paste(e) { if (!$(".d-editor-input").is(":focus")) { return; @@ -664,7 +675,7 @@ export default Ember.Component.extend({ const markdown = toMarkdown(html); if (!plainText || plainText.length < markdown.length) { - this.appEvents.trigger('composer:insert-text', markdown); + this._pasteMarkdown(markdown); handled = true; } }