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 {
|
||||
constructor(src, properties) {
|
||||
constructor(src, width, height, alt, title) {
|
||||
this.src = src;
|
||||
this.properties = properties;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.alt = alt;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
get type() { return "image"; }
|
||||
|
|
|
@ -73,11 +73,11 @@ class Deserializer {
|
|||
if (!url) {
|
||||
return null;
|
||||
}
|
||||
const width = result.getAttributeValue(node, "width");
|
||||
const height = result.getAttributeValue(node, "height");
|
||||
const width = parseInt(result.getAttributeValue(node, "width")) || null;
|
||||
const height = parseInt(result.getAttributeValue(node, "height")) || null;
|
||||
const alt = result.getAttributeValue(node, "alt");
|
||||
const title = result.getAttributeValue(node, "title");
|
||||
return new ImagePart(url, { width, height, alt, title });
|
||||
return new ImagePart(url, width, height, alt, title);
|
||||
}
|
||||
|
||||
parseElement(node) {
|
||||
|
|
|
@ -43,13 +43,12 @@ function renderList(listBlock) {
|
|||
}
|
||||
|
||||
function renderImage(imagePart) {
|
||||
const props = imagePart.properties;
|
||||
const attributes = Object.assign(
|
||||
{ src: imagePart.src },
|
||||
props.width && { width: props.width },
|
||||
props.height && { height: props.height },
|
||||
props.alt && { alt: props.alt },
|
||||
props.title && { title: props.title }
|
||||
imagePart.width && { width: imagePart.width },
|
||||
imagePart.height && { height: imagePart.height },
|
||||
imagePart.alt && { alt: imagePart.alt },
|
||||
imagePart.title && { title: imagePart.title }
|
||||
);
|
||||
return tag.img(attributes, []);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue