diff --git a/app/assets/javascripts/discourse/lib/Markdown.Editor.js b/app/assets/javascripts/discourse/lib/Markdown.Editor.js index 2eb1e9d6d26..e1a38895efb 100644 --- a/app/assets/javascripts/discourse/lib/Markdown.Editor.js +++ b/app/assets/javascripts/discourse/lib/Markdown.Editor.js @@ -2241,8 +2241,18 @@ // make a level 2 hash header around some default text. if (!chunk.selection) { chunk.startTag = "## "; + + if(chunk.before === "" || !chunk.before.match(/\n$/)){ + chunk.startTag = "\n## "; + } + chunk.selection = this.getString("headingexample"); chunk.endTag = " ##"; + + if(chunk.after === "" || !chunk.after.match(/^\n/)){ + chunk.endTag = "## \n"; + } + return; }