mirror of
https://github.com/discourse/discourse.git
synced 2025-05-11 07:14:54 +08:00
Grab dimention of the clipboard images
This commit is contained in:
parent
9cd48207f2
commit
dc159d7fa6
@ -125,12 +125,19 @@ class Tag {
|
|||||||
|
|
||||||
toMarkdown() {
|
toMarkdown() {
|
||||||
const e = this.element;
|
const e = this.element;
|
||||||
const attr = e.attributes;
|
const attr = e.attributes || {};
|
||||||
const pAttr = e.parent && e.parent.attributes;
|
const pAttr = (e.parent && e.parent.attributes) || {};
|
||||||
const src = (attr && attr.src) || (pAttr && pAttr.src);
|
const src = attr.src || pAttr.src;
|
||||||
|
|
||||||
if (src) {
|
if (src) {
|
||||||
const alt = (attr && attr.alt) || (pAttr && pAttr.alt) || "";
|
let alt = attr.alt || pAttr.alt || "";
|
||||||
|
const width = attr.width || pAttr.width;
|
||||||
|
const height = attr.height || pAttr.height;
|
||||||
|
|
||||||
|
if (width && height) {
|
||||||
|
alt = `${alt}|${width}x${height}`;
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,11 +106,11 @@ QUnit.test("converts table as readable", assert => {
|
|||||||
|
|
||||||
QUnit.test("converts img tag", assert => {
|
QUnit.test("converts img tag", assert => {
|
||||||
const url = "https://example.com/image.png";
|
const url = "https://example.com/image.png";
|
||||||
let html = `<img src="${url}">`;
|
let html = `<img src="${url}" width="100" height="50">`;
|
||||||
assert.equal(toMarkdown(html), ``);
|
assert.equal(toMarkdown(html), ``);
|
||||||
|
|
||||||
html = `<div><span><img src="${url}" alt="description" /></span></div>`;
|
html = `<div><span><img src="${url}" alt="description" width="50" height="100" /></span></div>`;
|
||||||
assert.equal(toMarkdown(html), ``);
|
assert.equal(toMarkdown(html), ``);
|
||||||
|
|
||||||
html = `<a href="http://example.com"><img src="${url}" alt="description" /></a>`;
|
html = `<a href="http://example.com"><img src="${url}" alt="description" /></a>`;
|
||||||
assert.equal(toMarkdown(html), `[](http://example.com)`);
|
assert.equal(toMarkdown(html), `[](http://example.com)`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user