From 3483c7bc587c619134c557c68350e371dc44a837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 9 May 2018 12:42:12 +0200 Subject: [PATCH] FIX: supports user/group mentions and category hashtags when quoting posts --- .../javascripts/discourse/lib/to-markdown.js.es6 | 8 ++++++++ test/javascripts/lib/to-markdown-test.js.es6 | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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 => { Loremipsum dolor sit amet - + `; @@ -286,3 +286,16 @@ QUnit.test("converts list tag from word", assert => { const markdown = `Sample\n\n* **Item 1**\n * *Item 2*\n * Item 3\n* Item 4\n\nList`; assert.equal(toMarkdown(html), markdown); }); + +QUnit.test("keeps mention/hash class", assert => { + const html = ` +

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); +});