diff --git a/app/assets/javascripts/discourse/lib/to-markdown.js.es6 b/app/assets/javascripts/discourse/lib/to-markdown.js.es6 index 692d4350ed2..6fb56e4db8f 100644 --- a/app/assets/javascripts/discourse/lib/to-markdown.js.es6 +++ b/app/assets/javascripts/discourse/lib/to-markdown.js.es6 @@ -126,6 +126,14 @@ class Tag { decorate(text) { const attr = this.element.attributes; + if (/^mention/.test(attr.class) && "@" === text[0]) { + return text; + } + + if ("hashtag" === attr.class && "#" === text[0]) { + return text; + } + if (attr.href && text !== attr.href) { text = text.replace(/\n{2,}/g, "\n"); return "[" + text + "](" + attr.href + ")"; diff --git a/test/javascripts/lib/to-markdown-test.js.es6 b/test/javascripts/lib/to-markdown-test.js.es6 index 4a99ab8138e..d310d97f20a 100644 --- a/test/javascripts/lib/to-markdown-test.js.es6 +++ b/test/javascripts/lib/to-markdown-test.js.es6 @@ -104,7 +104,7 @@ QUnit.test("converts table tags", assert => {
User mention: @discourse
+Group mention: @discourse-group
+Category link: #foo
+Sub-category link: #foo:bar
+ `; + + const markdown = `User mention: @discourse\n\nGroup mention: @discourse-group\n\nCategory link: #foo\n\nSub-category link: #foo:bar`; + + assert.equal(toMarkdown(html), markdown); +});