Validate w/h and avoid use of properties object.

This commit is contained in:
Danila Fedorin 2021-07-12 13:42:39 -07:00
parent 1e9cdbafd4
commit 012ef2b215
3 changed files with 12 additions and 10 deletions

View file

@ -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"; }

View file

@ -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) {

View file

@ -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, []);
}