FEATURE: use Markdown for image pasted in as opposed to IMG tags

This commit is contained in:
Sam 2017-07-25 15:11:28 -04:00
parent 0d66a41753
commit 17d56a4cb7
2 changed files with 5 additions and 3 deletions

View File

@ -296,7 +296,9 @@ export function uploadLocation(url) {
export function getUploadMarkdown(upload) {
if (isAnImage(upload.original_filename)) {
return '<img src="' + upload.url + '" width="' + upload.width + '" height="' + upload.height + '">';
const split = upload.original_filename.split('.');
const name = split[split.length-2];
return `![${name}|${upload.width}x${upload.height}](${upload.url})`;
} else if (!Discourse.SiteSettings.prevent_anons_from_downloading_files && (/\.(mov|mp4|webm|ogv|mp3|ogg|wav|m4a)$/i).test(upload.original_filename)) {
return uploadLocation(upload.url);
} else {

View File

@ -119,7 +119,7 @@ var testUploadMarkdown = function(filename) {
};
QUnit.test("getUploadMarkdown", assert => {
assert.ok(testUploadMarkdown("lolcat.gif") === '<img src="/uploads/123/abcdef.ext" width="100" height="200">');
assert.equal(testUploadMarkdown("lolcat.gif"),'![lolcat|100x200](/uploads/123/abcdef.ext)');
assert.ok(testUploadMarkdown("important.txt") === '<a class="attachment" href="/uploads/123/abcdef.ext">important.txt</a> (42 Bytes)\n');
});
@ -227,4 +227,4 @@ QUnit.test("caretRowCol", assert => {
assertResult(14, 3, 2);
document.body.removeChild(textarea);
});
});