forked from mystiq/hydrogen-web
Validate w/h and avoid use of properties object.
This commit is contained in:
parent
1e9cdbafd4
commit
012ef2b215
3 changed files with 12 additions and 10 deletions
|
@ -81,9 +81,12 @@ export class FormatPart {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ImagePart {
|
export class ImagePart {
|
||||||
constructor(src, properties) {
|
constructor(src, width, height, alt, title) {
|
||||||
this.src = src;
|
this.src = src;
|
||||||
this.properties = properties;
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.alt = alt;
|
||||||
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
get type() { return "image"; }
|
get type() { return "image"; }
|
||||||
|
|
|
@ -73,11 +73,11 @@ class Deserializer {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const width = result.getAttributeValue(node, "width");
|
const width = parseInt(result.getAttributeValue(node, "width")) || null;
|
||||||
const height = result.getAttributeValue(node, "height");
|
const height = parseInt(result.getAttributeValue(node, "height")) || null;
|
||||||
const alt = result.getAttributeValue(node, "alt");
|
const alt = result.getAttributeValue(node, "alt");
|
||||||
const title = result.getAttributeValue(node, "title");
|
const title = result.getAttributeValue(node, "title");
|
||||||
return new ImagePart(url, { width, height, alt, title });
|
return new ImagePart(url, width, height, alt, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseElement(node) {
|
parseElement(node) {
|
||||||
|
|
|
@ -43,13 +43,12 @@ function renderList(listBlock) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderImage(imagePart) {
|
function renderImage(imagePart) {
|
||||||
const props = imagePart.properties;
|
|
||||||
const attributes = Object.assign(
|
const attributes = Object.assign(
|
||||||
{ src: imagePart.src },
|
{ src: imagePart.src },
|
||||||
props.width && { width: props.width },
|
imagePart.width && { width: imagePart.width },
|
||||||
props.height && { height: props.height },
|
imagePart.height && { height: imagePart.height },
|
||||||
props.alt && { alt: props.alt },
|
imagePart.alt && { alt: imagePart.alt },
|
||||||
props.title && { title: props.title }
|
imagePart.title && { title: imagePart.title }
|
||||||
);
|
);
|
||||||
return tag.img(attributes, []);
|
return tag.img(attributes, []);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue