fix(TextRun): Add img element only if an URL is available

This commit is contained in:
Luan
2024-12-25 00:19:26 -03:00
parent b7c0421490
commit 913dcc74ea

View File

@@ -43,10 +43,17 @@ export default class TextRun implements Run {
if (this.attachment) {
if (this.attachment.element.type.imageType.image.sources.length) {
const { url } = this.attachment.element.type.imageType.image.sources[0];
if (this.endpoint) {
const { url } = this.attachment.element.type.imageType.image.sources[0];
let image_el = '';
if (url) {
image_el = `<img src="${url}" style="vertical-align: middle; height: ${this.attachment.element.properties.layoutProperties.height.value}px; width: ${this.attachment.element.properties.layoutProperties.width.value}px;" alt="">`;
}
const nav_url = this.endpoint.toURL();
if (nav_url) return `<a href="${nav_url}" class="yt-ch-link" display: block; width: fit-content; font-size: small;><img src="${url}" style="vertical-align: middle; height: ${this.attachment.element.properties.layoutProperties.height.value}px; width: ${this.attachment.element.properties.layoutProperties.width.value}px;">${wrapped_text}</a>`;
if (nav_url) return `<a href="${nav_url}" class="yt-ch-link">${image_el}${wrapped_text}</a>`;
}
}
}