Skip to content

Commit

Permalink
fix(TextRun): Add img element only if an URL is available
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Dec 25, 2024
1 parent b7c0421 commit 913dcc7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/parser/classes/misc/TextRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>`;
}
}
}
Expand Down

0 comments on commit 913dcc7

Please sign in to comment.