Skip to content

A platform for community discussion. Free, open, simple.

FIX: Missing `title` attribute when quoting an image.

Guo Xiang Tan782da448a26b
diff --git a/app/assets/javascripts/discourse/lib/to-markdown.js.es6 b/app/assets/javascripts/discourse/lib/to-markdown.js.es6
index 8e4eaa48832..b4fc915023a 100644
--- a/app/assets/javascripts/discourse/lib/to-markdown.js.es6
+++ b/app/assets/javascripts/discourse/lib/to-markdown.js.es6
@@ -241,6 +241,7 @@ export class Tag {
let alt = attr.alt || pAttr.alt || "";
const width = attr.width || pAttr.width;
const height = attr.height || pAttr.height;
+ const title = attr.title;
if (width && height) {
const pipe = this.element.parentNames.includes("table")
@@ -249,7 +250,7 @@ export class Tag {
alt = `${alt}${pipe}${width}x${height}`;
}
- return "![" + alt + "](" + src + ")";
+ return `![${alt}](${src}${title ? ` "${title}"` : ""})`;
}
return "";
diff --git a/test/javascripts/lib/to-markdown-test.js.es6 b/test/javascripts/lib/to-markdown-test.js.es6
index f63a004c263..2cb28ba25f1 100644
--- a/test/javascripts/lib/to-markdown-test.js.es6
+++ b/test/javascripts/lib/to-markdown-test.js.es6
@@ -166,6 +166,9 @@ QUnit.test("converts img tag", assert => {
let html = `<img src="${url}" width="100" height="50">`;
assert.equal(toMarkdown(html), `![|100x50](${url})`);
+ html = `<img src="${url}" width="100" height="50" title="some title">`;
+ assert.equal(toMarkdown(html), `![|100x50](${url} "some title")`);
+
html = `<div><span><img src="${url}" alt="description" width="50" height="100" /></span></div>`;
assert.equal(toMarkdown(html), `![description|50x100](${url})`);