FIX: When quoting an attachment, keep the |attachment in markdown (#11347)

This commit is contained in:
Martin Brennan 2020-11-25 14:31:14 +10:00 committed by GitHub
parent 3e1b94c227
commit 2348a7972e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -273,7 +273,13 @@ export class Tag {
if (attr.href && text !== attr.href) { if (attr.href && text !== attr.href) {
text = text.replace(/\n{2,}/g, "\n"); 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; return text;

View File

@ -38,6 +38,12 @@ module("Unit | Utility | to-markdown", function () {
assert.equal(toMarkdown(html), markdown); assert.equal(toMarkdown(html), markdown);
}); });
test("converts a link which is an attachment", function (assert) {
let html = `<a class="attachment" href="https://discourse.org/pdfs/stuff.pdf">stuff.pdf</a>`;
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) { test("put raw URL instead of converting the link", function (assert) {
let url = "https://discourse.org"; let url = "https://discourse.org";
const html = () => `<a href="${url}">${url}</a>`; const html = () => `<a href="${url}">${url}</a>`;