From 2348a7972eb471b98b80469c68a587a9af83cbf7 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Wed, 25 Nov 2020 14:31:14 +1000 Subject: [PATCH] FIX: When quoting an attachment, keep the |attachment in markdown (#11347) --- app/assets/javascripts/discourse/app/lib/to-markdown.js | 8 +++++++- .../discourse/tests/unit/lib/to-markdown-test.js | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/app/lib/to-markdown.js b/app/assets/javascripts/discourse/app/lib/to-markdown.js index cabb1439371..88459e3d244 100644 --- a/app/assets/javascripts/discourse/app/lib/to-markdown.js +++ b/app/assets/javascripts/discourse/app/lib/to-markdown.js @@ -273,7 +273,13 @@ export class Tag { if (attr.href && text !== attr.href) { text = text.replace(/\n{2,}/g, "\n"); - return "[" + text + "](" + attr.href + ")"; + + let linkModifier = ""; + if (attr.class && attr.class.includes("attachment")) { + linkModifier = "|attachment"; + } + + return "[" + text + linkModifier + "](" + attr.href + ")"; } return text; diff --git a/app/assets/javascripts/discourse/tests/unit/lib/to-markdown-test.js b/app/assets/javascripts/discourse/tests/unit/lib/to-markdown-test.js index 673b050eaf8..1ee3b245a6a 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/to-markdown-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/to-markdown-test.js @@ -38,6 +38,12 @@ module("Unit | Utility | to-markdown", function () { assert.equal(toMarkdown(html), markdown); }); + test("converts a link which is an attachment", function (assert) { + let html = `stuff.pdf`; + let markdown = `[stuff.pdf|attachment](https://discourse.org/pdfs/stuff.pdf)`; + assert.equal(toMarkdown(html), markdown); + }); + test("put raw URL instead of converting the link", function (assert) { let url = "https://discourse.org"; const html = () => `${url}`;